-
Notifications
You must be signed in to change notification settings - Fork 2
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
#302 Slugify tags with theirs groups #304
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||
"""Defines tests for models in Catalog app.""" | ||||||
import string | ||||||
import unittest | ||||||
|
||||||
from django.db import DataError | ||||||
from django.test import TestCase | ||||||
|
@@ -249,14 +250,15 @@ class Tag(TestCase): | |||||
|
||||||
def test_tag_doubled_save_slug_postfix(self): | ||||||
"""Tag should preserve it's slug value after several saves.""" | ||||||
slug = '12-v' | ||||||
group = catalog_models.MockTagGroup.objects.create(name='Напряжение вход') | ||||||
tag = catalog_models.MockTag.objects.create( | ||||||
name='12 В', | ||||||
group=group | ||||||
) | ||||||
self.assertEqual(tag.slug, '12-v') | ||||||
self.assertEqual(tag.slug[-len(slug):], slug) | ||||||
tag.save() | ||||||
self.assertEqual(tag.slug, '12-v') | ||||||
self.assertEqual(tag.slug[-len(slug):], slug) | ||||||
|
||||||
def test_long_name(self): | ||||||
""" | ||||||
|
@@ -266,21 +268,45 @@ def test_long_name(self): | |||||
It may create problems for tag with long name. | ||||||
""" | ||||||
name = 'Имя ' * 50 | ||||||
group = catalog_models.MockTagGroup.objects.first() | ||||||
group = catalog_models.MockTagGroup.objects.create(name='Some group') | ||||||
try: | ||||||
tag = catalog_models.MockTag.objects.create(group=group, name=name) | ||||||
self.assertLessEqual(len(tag.slug), catalog.models.Tag.SLUG_MAX_LENGTH) | ||||||
except DataError as e: | ||||||
self.assertTrue(False, f'Tag has too long name. {e}') | ||||||
|
||||||
def test_slugify_conflicts(self): | ||||||
group = catalog_models.MockTagGroup.objects.create(name='Some group') | ||||||
slugs = [ | ||||||
catalog_models.MockTag.objects.create(name=name).slug | ||||||
catalog_models.MockTag.objects.create(group=group, name=name).slug | ||||||
for name in ['11 A', '1/1 A', '1 1 A'] | ||||||
] | ||||||
|
||||||
self.assertEqual(len(slugs), len(set(slugs)), msg=slugs) | ||||||
|
||||||
# @todo #302:30m Process more special symbols for slugs. | ||||||
@unittest.expectedFailure | ||||||
def test_slug_special_symbols(self): | ||||||
slugs = [ | ||||||
catalog_models.MockTag.objects.create(name=name).slug | ||||||
for name in ['11 A', '1/1 A', '1 1 A', '1.1 A', '1-1 A', '1_1 A'] | ||||||
] | ||||||
|
||||||
self.assertEqual(len(slugs), len(set(slugs)), msg=slugs) | ||||||
|
||||||
def test_slugs_for_cloned_tag_values(self): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Up to you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'll leave it because of few points:
|
||||||
groups = [ | ||||||
catalog_models.MockTagGroup.objects.create(name=name) | ||||||
for name in ['Length', 'Width', 'Height'] | ||||||
] | ||||||
values = ['11 A']*3 | ||||||
slugs = [ | ||||||
catalog_models.MockTag.objects.create(group=group, name=value).slug | ||||||
for group, value in zip(groups, values) | ||||||
] | ||||||
|
||||||
self.assertEqual(len(slugs), len(set(slugs)), msg=slugs) | ||||||
|
||||||
def test_group_tags(self): | ||||||
groups = [ | ||||||
catalog_models.MockTagGroup.objects.create(name=name) | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create a separate skipped test (e.g.
test_slugify_punctuation_conflicts
) for the set, that led to the conflict to preserve testing of the set that has no such conflicts11 A, 1/1 A, 1 1 A
This will help to avoid regressions if we break the slugify for non-conflict set. In common i'd prefer stick to such rule: new tests for new bugs. Up to you