def testOwnerIDSetOnTransform(self): """ Test that the owner_id gets set to the case when the pillow calls change transform """ case_owner_id = CASE_WITH_OWNER_ID case_no_owner_id = CASE_NO_OWNER_ID pillow = CasePillow(create_index=False, online=False) changed_with_owner_id = pillow.change_transform(case_owner_id) changed_with_no_owner_id = pillow.change_transform(case_no_owner_id) self.assertEqual(changed_with_owner_id.get("owner_id"), "testuser") self.assertEqual(changed_with_no_owner_id.get("owner_id"), "testuser")
def testOwnerIDSetOnTransform(self): """ Test that the owner_id gets set to the case when the pillow calls change transform """ case_owner_id = CASE_WITH_OWNER_ID case_no_owner_id = CASE_NO_OWNER_ID pillow = CasePillow(create_index=False, online=False) changed_with_owner_id = pillow.change_transform(case_owner_id) changed_with_no_owner_id = pillow.change_transform(case_no_owner_id) self.assertEqual(changed_with_owner_id.get("owner_id"), "testuser") self.assertEqual(changed_with_no_owner_id.get("owner_id"), "testuser")
def test_get_list(self): """ Any case in the appropriate domain should be in the list from the API. """ # The actual infrastructure involves saving to CouchDB, having PillowTop # read the changes and write it to ElasticSearch. #the pillow is set to offline mode - elasticsearch not needed to validate pillow = CasePillow(online=False) fake_case_es = FakeXFormES() v0_4.MOCK_CASE_ES = fake_case_es modify_date = datetime.utcnow() backend_case = CommCareCase(server_modified_on=modify_date, domain=self.domain.name) backend_case.save() translated_doc = pillow.change_transform(backend_case.to_json()) fake_case_es.add_doc(translated_doc['_id'], translated_doc) self.client.login(username=self.username, password=self.password) response = self.client.get(self.list_endpoint) self.assertEqual(response.status_code, 200) api_cases = simplejson.loads(response.content)['objects'] self.assertEqual(len(api_cases), 1) api_case = api_cases[0] self.assertEqual(dateutil.parser.parse(api_case['server_date_modified']), backend_case.server_modified_on) backend_case.delete()
def test_get_list(self): """ Any case in the appropriate domain should be in the list from the API. """ # The actual infrastructure involves saving to CouchDB, having PillowTop # read the changes and write it to ElasticSearch. #the pillow is set to offline mode - elasticsearch not needed to validate pillow = CasePillow(online=False) fake_case_es = FakeXFormES() v0_4.MOCK_CASE_ES = fake_case_es modify_date = datetime.utcnow() backend_case = CommCareCase(server_modified_on=modify_date, domain=self.domain.name) backend_case.type = CC_BIHAR_PREGNANCY backend_case.save() translated_doc = pillow.change_transform(backend_case.to_json()) fake_case_es.add_doc(translated_doc['_id'], translated_doc) self.client.login(username=self.username, password=self.password) response = self.client.get(self.list_endpoint) self.assertEqual(response.status_code, 200) api_cases = simplejson.loads(response.content)['objects'] self.assertEqual(len(api_cases), 2) api_case = api_cases['mother_lists'][0] self.assertEqual(dateutil.parser.parse(api_case['server_date_modified']), backend_case.server_modified_on) backend_case.delete()