def test_storage_with_feature_turned_off(self): orig = settings.CASCADE_UPDATE_TO_FRED settings.CASCADE_UPDATE_TO_FRED = False facility = HealthFacility(name="Dummy 1") facility.save() self.failUnless(facility.id) settings.CASCADE_UPDATE_TO_FRED = orig
def test_create_facility_without_cascading_with_empty_uuid(self, mock_create_facility): mock_create_facility.return_value = "randomuuid" facility = HealthFacility(name="Dummy 1", uuid="") facility.save() assert mock_create_facility.called == True self.failUnless(facility.id) assert facility.uuid == "randomuuid"
def test_create_facility_without_cascading(self): facility = HealthFacility(name="Dummy 1") facility.save(cascade_update=False) self.failUnless(facility.id) self.failIf(facility.uuid) facility = HealthFacility(name="Dummy 2") facility.save() self.failUnless(facility.id) self.failIf(facility.uuid)
def test_store_json_update(self): facility_json = json.loads('{ "uuid": "18a021ed-205c-4e80-ab9c-fbeb2d9c1bcf", "name": "Some HOSPITAL", "active": true, "href": "http://dhis/api-fred/v1/facilities/123", "createdAt": "2013-01-15T11:14:02.863+0000", "updatedAt": "2013-01-15T11:14:02.863+0000", "coordinates": [34.19622, 0.70331], "identifiers": [{ "agency": "DHIS2", "context": "DHIS2_UID", "id": "123" }], "properties": { "dataSets": ["123456"], "level": 5, "ownership": "Private Not For Profit", "parent": "56789", "type": "General Hospital" }}') facility_json['name'] = facility_json['name'].encode('utf-8') facility = HealthFacility(name="Dummy", uuid=facility_json['uuid'], active = False) facility.save(cascade_update=False) self.failUnless(facility.id) assert facility.name == 'Dummy' assert facility.uuid == facility_json['uuid'] assert facility.active == False HealthFacility.store_json(facility_json, comment = "Updates from FRED provider") facility = HealthFacility.objects.get(id=facility.id) assert facility.name == facility_json['name'] assert facility.active == facility_json['active'] assert facility.uuid == facility_json['uuid'] assert facility.type.name == facility_json["properties"]["type"] assert facility.type.slug == "generalhospital" assert facility.owner == facility_json['properties']['ownership']
def create_facility(uuid): facility = HealthFacility(uuid=uuid) facility.save(cascade_update=False)
def test_create_facility_without_double_cascading(self, mock_create_facility): facility = HealthFacility(name="Dummy 1", uuid="randomuuid") facility.save() assert mock_create_facility.called == False self.failUnless(facility.id) assert facility.uuid == "randomuuid"