Skip to content

Commit

Permalink
Supprime une duplication de code (fix #3067)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Oct 11, 2015
1 parent 2580564 commit 8c7f3c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 2 additions & 12 deletions zds/tutorialv2/models/models_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,7 @@ def get_absolute_url_online(self):
:return: the URL of the published content
:rtype: str
"""
reversed_ = ''

if self.is_article():
reversed_ = 'article'
elif self.is_tutorial():
reversed_ = 'tutorial'
reversed_ = self.content_type.lower()

return reverse(reversed_ + ':view', kwargs={'pk': self.content_pk, 'slug': self.content_public_slug})

Expand Down Expand Up @@ -672,12 +667,7 @@ def get_absolute_url_to_extra_content(self, type_):
allowed_types = ['pdf', 'md', 'html', 'epub', 'zip']

if type_ in allowed_types:
reversed_ = ''

if self.is_article():
reversed_ = 'article'
elif self.is_tutorial():
reversed_ = 'tutorial'
reversed_ = self.content_type.lower()

return reverse(
reversed_ + ':download-' + type_, kwargs={'pk': self.content_pk, 'slug': self.content_public_slug})
Expand Down
5 changes: 4 additions & 1 deletion zds/tutorialv2/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3268,15 +3268,18 @@ def test_publication_make_extra_contents(self):
self.assertTrue(published.have_type(extra))
result = self.client.get(published.get_absolute_url_to_extra_content(extra))
self.assertEqual(result.status_code, 200)

# test that deletion give a 404
markdown_url = published.get_absolute_url_md()
md_path = os.path.join(published.get_extra_contents_directory(), published.content_public_slug + '.md')
os.remove(md_path)
self.assertEqual(404, self.client.get(markdown_url).status_code)
self.assertEqual('', published.get_absolute_url_to_extra_content('kboom'))
self.client.logout()

with open(md_path, "w") as f:
with open(md_path, "w") as f: # remake a .md file, whatever the content
f.write("I rebuilt it to finish the test. Perhaps a funny quote would be a good thing?")

# same test with author:
self.assertEqual(
self.client.login(
Expand Down

0 comments on commit 8c7f3c3

Please sign in to comment.