Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnMilo committed Aug 18, 2015
1 parent da52f58 commit 88d932a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions rest/tests/test_vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def test_term_pagination(self):
"""Test pagination for collections"""

vocab_slug = self.create_vocabulary(self.repo.slug)['slug']
not_set = self.get_terms(self.repo.slug, vocab_slug)["results"][0]

expected = [
self.create_term(
Expand All @@ -446,7 +447,7 @@ def test_term_pagination(self):
"weight": 1000,
}
) for i in range(40)]

expected.insert(0, not_set)
terms = self.get_terms(self.repo.slug, vocab_slug)
self.assertEqual(41, terms['count'])
self.assertEqual([TermSerializer(x).data for x in expected[:20]],
Expand Down Expand Up @@ -751,13 +752,14 @@ def test_vocabulary_get(self):
def test_term_create(self):
"""Test create term"""
vocab_slug = self.create_vocabulary(self.repo.slug)['slug']
original_count = self.get_terms(self.repo.slug, vocab_slug)['count']

# curator has manage_taxonomy permission
self.logout()
self.login(self.curator_user.username)

self.create_term(self.repo.slug, vocab_slug)
self.assertEqual(1, self.get_terms(
self.assertEqual(original_count + 1, self.get_terms(
self.repo.slug, vocab_slug)['count'])

# login as author which doesn't have manage_taxonomy permissions
Expand Down Expand Up @@ -864,11 +866,12 @@ def test_term_get(self):
"""Test retrieve term"""
vocab_slug = self.create_vocabulary(self.repo.slug)['slug']
term_slug = self.create_term(self.repo.slug, vocab_slug)['slug']
expected_count = self.get_terms(self.repo.slug, vocab_slug)['count']

# author_user has view_repo permissions
self.logout()
self.login(self.author_user.username)
self.assertEqual(1, self.get_terms(
self.assertEqual(expected_count, self.get_terms(
self.repo.slug, vocab_slug)['count'])
self.get_term(self.repo.slug, vocab_slug, term_slug)

Expand Down
3 changes: 2 additions & 1 deletion taxonomy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def save(self, *args, **kwargs):
Vocabulary, id=self.id).name:
slug = slugify(self.name)
count = 1
create_notset = True
if self.id is None:
create_notset = True
while Vocabulary.objects.filter(slug=slug).exists():
slug = "{0}{1}".format(slugify(self.name), count)
count += 1
Expand Down

0 comments on commit 88d932a

Please sign in to comment.