Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3626 : corrige les espaces dans l'ajout de tags sur les contenus #3627

Merged
merged 1 commit into from
May 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zds/tutorialv2/models/models_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def add_tags(self, tag_collection):
"""
for tag in tag_collection:
try:
current_tag, created = Tag.objects.get_or_create(title=tag.lower())
current_tag, created = Tag.objects.get_or_create(title=tag.lower().strip())
self.tags.add(current_tag)
except ValueError as e:
logging.getLogger("zds.tutorialv2").warn(e)
Expand Down
12 changes: 12 additions & 0 deletions zds/tutorialv2/tests/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,18 @@ def test_add_tags(self):
'all tags are "{}"'.format('","'.join([str(t) for t in Tag.objects.all()])))
self.assertEqual(tuto_tags_len, len(tuto.tags.all()))

# test space in tags (first and last space deleted)
tags = ['foo bar', ' azerty', 'qwerty ', ' another tag ']
tuto.add_tags(tags)
tuto_tags_list = [tag['title'] for tag in tuto.tags.values('title')]
self.assertIn('foo bar', tuto_tags_list)
self.assertNotIn(' azerty', tuto_tags_list)
self.assertIn('azerty', tuto_tags_list)
self.assertNotIn('qwerty ', tuto_tags_list)
self.assertIn('qwerty', tuto_tags_list)
self.assertNotIn(' another tag', tuto_tags_list)
self.assertIn('another tag', tuto_tags_list)

def tearDown(self):
if os.path.isdir(settings.ZDS_APP['content']['repo_private_path']):
shutil.rmtree(settings.ZDS_APP['content']['repo_private_path'])
Expand Down