Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snopoke committed Sep 18, 2017
1 parent 05b66ae commit ff4307e
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions tests/test_commcare_hq_client.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals, print_function, absolute_import, division, generators, nested_scopes

import json
import unittest

import simplejson
Expand Down Expand Up @@ -33,18 +34,34 @@ def _get_results(self, params):
}


class FakeDateSession(FakeSession):
def __init__(self, resource):
self.since_query_param = resource_since_params[resource][0]
class FakeDateCaseSession(FakeSession):
def _get_results(self, params):
if not params:
return {
'meta': {'next': '?offset=1', 'offset': 0, 'limit': 1, 'total_count': 2},
'objects': [{'id': 1, 'foo': 1, 'since_field': '2017-01-01T15:36:22Z'}]
}
else:
since_query_param =resource_since_params['case'].start_param
assert params[since_query_param] == '2017-01-01T15:36:22'
# include ID=1 again to make sure it gets filtered out
return {
'meta': { 'next': None, 'offset': 1, 'limit': 1, 'total_count': 2 },
'objects': [ {'id': 1, 'foo': 1}, {'id': 2, 'foo': 2} ]
}

class FakeDateFormSession(FakeSession):
def _get_results(self, params):
if not params:
return {
'meta': {'next': '?offset=1', 'offset': 0, 'limit': 1, 'total_count': 2},
'objects': [{'id': 1, 'foo': 1, 'since_field': '2017-01-01T15:36:22Z'}]
}
else:
assert params[self.since_query_param] == '2017-01-01T15:36:22'
search = json.loads(params['_search'])
_or = search['filter']['or']
assert _or[0]['and'][1]['range']['server_modified_on']['gte'] == '2017-01-01T15:36:22'
assert _or[1]['and'][1]['range']['received_on']['gte'] == '2017-01-01T15:36:22'
# include ID=1 again to make sure it gets filtered out
return {
'meta': { 'next': None, 'offset': 1, 'limit': 1, 'total_count': 2 },
Expand All @@ -68,8 +85,8 @@ def test_iterate_simple(self):
self._test_iterate(FakeSession(), SimplePaginator('fake'))

def test_iterate_date(self):
self._test_iterate(FakeDateSession('form'), DatePaginator('form', 'since_field'))
self._test_iterate(FakeDateSession('case'), DatePaginator('case', 'since_field'))
self._test_iterate(FakeDateFormSession(), DatePaginator('form', 'since_field'))
self._test_iterate(FakeDateCaseSession(), DatePaginator('case', 'since_field'))


class TestDatePaginator(unittest.TestCase):
Expand Down

0 comments on commit ff4307e

Please sign in to comment.