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

Commit

Permalink
minor test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnMilo committed Aug 20, 2015
1 parent 50f5f39 commit 4ddf6a4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions rest/tests/test_vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,18 @@ def test_vocabulary_pagination(self):
# should still be the only thing there.
self.assertEqual(vocabs.count(), 1)
expected = [
Vocabulary.objects.create(
VocabularySerializer(Vocabulary.objects.create(
repository=self.repo,
name="name{i}".format(i=i),
description="description",
required=True,
vocabulary_type=Vocabulary.FREE_TAGGING,
weight=1000,
) for i in range(40)]
)).data for i in range(40)]

# The curator status vocabulary will be first by ID.
expected.append(vocabs[0])
expected.append(VocabularySerializer(vocabs[0]).data)
expected.sort(key=lambda x: x["id"])

resp = self.client.get(
'{repo_base}{repo_slug}/vocabularies/'.format(
Expand All @@ -442,15 +443,14 @@ def test_vocabulary_pagination(self):
vocabularies = as_json(resp)
self.assertEqual(41, vocabularies['count'])

# Sort both lists in preparation for comparison.
expected_dicts = [VocabularySerializer(x).data for x in expected]
expected_dicts.sort(key=lambda x: x["id"])
# Sort both lists in preparation for comparisons.
expected.sort(key=lambda x: x["id"])
from_api = sorted(vocabularies['results'], key=lambda x: x["id"])

expected_count = 20
self.assertEqual(expected_count, len(from_api))
self.assertEqual(
expected_dicts[:expected_count],
expected[:expected_count],
from_api,
)

Expand All @@ -466,7 +466,7 @@ def test_vocabulary_pagination(self):
self.assertEqual(41, vocabularies['count'])
self.assertEqual(
from_api,
expected_dicts[expected_count:expected_count*2],
expected[expected_count:expected_count*2],
)

def test_term_pagination(self):
Expand Down

0 comments on commit 4ddf6a4

Please sign in to comment.