Skip to content

Commit

Permalink
Add test for sort_nulls_last
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeaufort committed Nov 5, 2018
1 parent 23e2596 commit a9772fe
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/test_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def test_cand_filters(self):
response = self._response(page)
self.assertGreater(original_count, response['pagination']['count'])


def test_candidate_sort(self):
candidates = [
factories.CandidateFactory(candidate_status='P'),
Expand All @@ -180,6 +179,22 @@ def test_candidate_sort(self):
results = self._results(api.url_for(CandidateSearch, sort='-candidate_status'))
self.assertEqual([each['candidate_id'] for each in results], candidate_ids)

def test_candidate_sort_nulls_last(self):
"""
Nulls will sort last by default when sorting ascending -
sort_nulls_last allows forces nulls to the bottom for descending sort
"""
candidates = [
factories.CandidateFactory(candidate_id='1'),
factories.CandidateFactory(candidate_id='2', candidate_status='P'),
factories.CandidateFactory(candidate_id='3', candidate_status='C'),
]
candidate_ids = [each.candidate_id for each in candidates]
results = self._results(api.url_for(CandidateList, sort='candidate_status', sort_nulls_last=True))
self.assertEqual([each['candidate_id'] for each in results], candidate_ids[::-1])
results = self._results(api.url_for(CandidateList, sort='-candidate_status', sort_nulls_last=True))
self.assertEqual([each['candidate_id'] for each in results], ['2', '3', '1'])

class TestCandidateHistory(ApiBaseTest):

def setUp(self):
Expand Down

0 comments on commit a9772fe

Please sign in to comment.