Skip to content

Commit

Permalink
Merge branch 'feature/covering' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Jun 12, 2015
2 parents 10def02 + 7ebf7ce commit b791ab1
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
source = tagging
omit = tagging/tests/*

[report]
show_missing = True
exclude_lines =
pragma: no cover
57 changes: 57 additions & 0 deletions tagging/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def test_tags_with_double_quotes_can_contain_commas(self):
['a-one', 'a-two, and a-three'])
self.assertEqual(parse_tag_input('"two", one, one, two, "one"'),
['one', 'two'])
self.assertEqual(parse_tag_input('two", one'),
['one', 'two'])

def test_with_naughty_input(self):
""" Test with naughty input. """
Expand Down Expand Up @@ -684,6 +686,49 @@ def test_related_for_model_with_tag_strings_as_input(self):
self.assertEqual(len(relevant_attribute_list), 0)


class TestTagCloudForModel(TestCase):
def setUp(self):
parrot_details = (
('pining for the fjords', 9, True, 'foo bar'),
('passed on', 6, False, 'bar baz ter'),
('no more', 4, True, 'foo ter'),
('late', 2, False, 'bar ter'),
)

for state, perch_size, perch_smelly, tags in parrot_details:
perch = Perch.objects.create(size=perch_size, smelly=perch_smelly)
parrot = Parrot.objects.create(state=state, perch=perch)
Tag.objects.update_tags(parrot, tags)

def test_tag_cloud_for_model(self):
tag_cloud = Tag.objects.cloud_for_model(Parrot)
relevant_attribute_list = [(tag.name, tag.count, tag.font_size)
for tag in tag_cloud]
self.assertEqual(len(relevant_attribute_list), 4)
self.assertTrue(('bar', 3, 4) in relevant_attribute_list)
self.assertTrue(('baz', 1, 1) in relevant_attribute_list)
self.assertTrue(('foo', 2, 2) in relevant_attribute_list)
self.assertTrue(('ter', 3, 4) in relevant_attribute_list)

def test_tag_cloud_for_model_filters(self):
tag_cloud = Tag.objects.cloud_for_model(Parrot,
filters={'state': 'no more'})
relevant_attribute_list = [(tag.name, tag.count, tag.font_size)
for tag in tag_cloud]
self.assertEqual(len(relevant_attribute_list), 2)
self.assertTrue(('foo', 1, 1) in relevant_attribute_list)
self.assertTrue(('ter', 1, 1) in relevant_attribute_list)

def test_tag_cloud_for_model_min_count(self):
tag_cloud = Tag.objects.cloud_for_model(Parrot, min_count=2)
relevant_attribute_list = [(tag.name, tag.count, tag.font_size)
for tag in tag_cloud]
self.assertEqual(len(relevant_attribute_list), 3)
self.assertTrue(('bar', 3, 4) in relevant_attribute_list)
self.assertTrue(('foo', 2, 1) in relevant_attribute_list)
self.assertTrue(('ter', 3, 4) in relevant_attribute_list)


class TestGetTaggedObjectsByModel(TestCase):
def setUp(self):
parrot_details = (
Expand Down Expand Up @@ -802,6 +847,12 @@ def test_get_union_by_model(self):
# Issue 114 - Union with non-existant tags
parrots = TaggedItem.objects.get_union_by_model(Parrot, [])
self.assertEqual(len(parrots), 0)
parrots = TaggedItem.objects.get_union_by_model(Parrot, ['albert'])
self.assertEqual(len(parrots), 0)

Tag.objects.create(name='titi')
parrots = TaggedItem.objects.get_union_by_model(Parrot, ['titi'])
self.assertEqual(len(parrots), 0)


class TestGetRelatedTaggedItems(TestCase):
Expand Down Expand Up @@ -1036,6 +1087,12 @@ def test_tag_d_validation(self):
forms.ValidationError, t.clean,
'foo qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbn bar')

def test_tag_get_from_model(self):
FormTest.objects.create(tags='test3 test2 test1')
FormTest.objects.create(tags='toto titi')
self.assertEquals(FormTest.tags, 'test1 test2 test3 titi toto')


#########
# Forms #
#########
Expand Down
3 changes: 0 additions & 3 deletions tagging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ def split_strip(input, delimiter=','):
Splits ``input`` on ``delimiter``, stripping each resulting string
and returning a list of non-empty strings.
"""
if not input:
return []

words = [w.strip() for w in input.split(delimiter)]
return [w for w in words if w]

Expand Down

0 comments on commit b791ab1

Please sign in to comment.