def test_should_sync_locations_change_location_type(self): """ When location_type gets changed, we should resync locations """ yesterday = datetime.today() - timedelta(1) day_before_yesterday = yesterday - timedelta(1) LocationType.objects.all().update(last_modified=day_before_yesterday) # Force update because of auto_now self.location_type = LocationType.objects.last() location = SQLLocation( location_id="unique-id", domain="test-domain", name="Meereen", location_type=self.location_type, metadata={'queen': "Daenerys Targaryen", 'rebels': "Sons of the Harpy"}, ) location.save() SQLLocation.objects.filter(pk=1).update(last_modified=day_before_yesterday) location = SQLLocation.objects.last() location_db = _location_footprint([location]) self.assertFalse(should_sync_locations(SyncLog(date=yesterday), location_db, self.user)) self.location_type.shares_cases = True self.location_type.save() location = SQLLocation.objects.last() location_db = _location_footprint([location]) self.assertTrue(should_sync_locations(SyncLog(date=yesterday), location_db, self.user))
def _make_loc(name, site_code, location_type, parent_code, location_id, do_delete, external_id, latitude, longitude, custom_data, index, location_data_model, parent=None): _type = lt_by_code.get(location_type) loc = SQLLocation( site_code=site_code, name=name, domain=self.domain.name, location_type=_type, parent=parent, ) loc.save() return loc
def _make_loc(name, site_code, location_type, parent_code, location_id, do_delete, external_id, latitude, longitude, custom_data, uncategorized_data, index, parent=None): _type = lt_by_code.get(location_type) loc = SQLLocation( site_code=site_code, name=name, domain=self.domain.name, location_type=_type, parent=parent, ) loc.save() return loc
def test_should_sync_locations_change_location_type(self): """ When location_type gets changed, we should resync locations """ yesterday = datetime.today() - timedelta(1) day_before_yesterday = yesterday - timedelta(1) LocationType.objects.all().update(last_modified=day_before_yesterday ) # Force update because of auto_now self.location_type = LocationType.objects.last() location = SQLLocation( location_id="unique-id", domain="test-domain", name="Meereen", location_type=self.location_type, metadata={ 'queen': "Daenerys Targaryen", 'rebels': "Sons of the Harpy" }, ) location.save() SQLLocation.objects.filter(pk=1).update( last_modified=day_before_yesterday) location = SQLLocation.objects.last() location_db = _location_footprint([location]) self.assertFalse( should_sync_locations(SyncLog(date=yesterday), location_db, self.user)) self.location_type.shares_cases = True self.location_type.save() location = SQLLocation.objects.last() location_db = _location_footprint([location]) self.assertTrue( should_sync_locations(SyncLog(date=yesterday), location_db, self.user))
def setUpClass(cls): super(LocationHierarchyTest, cls).setUpClass() domain = "a-song-of-ice-and-fire" domain_obj = create_domain(domain) continent_location_type = LocationType( domain=domain, name="continent", code="continent", ) continent_location_type.save() kingdom_location_type = LocationType( domain=domain, name="kingdom", code="kingdom", parent_type=continent_location_type, ) kingdom_location_type.save() city_location_type = LocationType( domain=domain, name="city", code="city", parent_type=kingdom_location_type, ) city_location_type.save() continent = SQLLocation( domain=domain, name="Westeros", location_type=continent_location_type, site_code="westeros", ) continent.save() kingdom = SQLLocation( domain=domain, name="The North", location_type=kingdom_location_type, parent=continent, site_code="the_north", ) kingdom.save() city = SQLLocation( domain=domain, name="Winterfell", location_type=city_location_type, parent=kingdom, site_code="winterfell", ) city.save() cls.domain_obj = domain_obj cls.domain = domain cls.continent = continent cls.kingdom = kingdom cls.city = city
def setUpClass(cls): super(LocationHierarchyTest, cls).setUpClass() domain = "a-song-of-ice-and-fire" domain_obj = create_domain(domain) continent_location_type = LocationType( domain=domain, name="continent", code="continent", ) continent_location_type.save() kingdom_location_type = LocationType( domain=domain, name="kingdom", code="kingdom", parent_type=continent_location_type, ) kingdom_location_type.save() city_location_type = LocationType( domain=domain, name="city", code="city", parent_type=kingdom_location_type, ) city_location_type.save() continent = SQLLocation( domain=domain, name="Westeros", location_type=continent_location_type, site_code="westeros", ) continent.save() kingdom = SQLLocation( domain=domain, name="The North", location_type=kingdom_location_type, parent=continent, site_code="the_north", ) kingdom.save() city = SQLLocation( domain=domain, name="Winterfell", location_type=city_location_type, parent=kingdom, site_code="winterfell", ) city.save() cls.domain_obj = domain_obj cls.domain = domain cls.continent = continent cls.kingdom = kingdom cls.city = city