def test_set_encompassing_city_exists(self): city = Location(name="Wixom").save() city.encompassed_by.connect(self.state) self.state.encompasses.connect(city) res = self.address.set_encompassing() self.assertTrue(res.encompassed_by.is_connected(city)) city.delete()
def test_address_has_no_lat_long(self): mi = Location(name=us.states.lookup("MI").name, sector="federal").save() address = Address(state="MI").save() res = connect_to_state_districts.apply_async( kwargs={'object_uuid': address.object_uuid}) self.assertFalse(res.result) mi.delete() address.delete()
def test_address_has_lat_long_outside_usa(self): mi = Location(name=us.states.lookup("MI").name, sector="federal").save() # lat/long of Greenwich UK address = Address(state="MI", latitude=51.4800, longitude=0.0000).save() res = connect_to_state_districts.apply_async( kwargs={'object_uuid': address.object_uuid}) self.assertTrue(res.result) mi.delete() address.delete()
def test_multiple_cities_same_name(self): address = Address(city="Redford", state="Michigan").save() city = Location(name="Redford").save() city2 = Location(name="Redford").save() try: new_state = Location.nodes.get(name="Washington") except (Location.DoesNotExist, DoesNotExist): new_state = Location(name="Washington").save() self.state.encompasses.connect(city) city.encompassed_by.connect(self.state) city2.encompassed_by.connect(new_state) new_state.encompasses.connect(city2) res = address.set_encompassing() self.assertTrue(res.encompassed_by.is_connected(city)) city.delete() city2.delete() address.delete()
def test_create_state_districts(self): mi = Location(name=us.states.lookup("MI").name, sector="federal").save() address = Address(state="MI", latitude=42.532020, longitude=-83.496500).save() lower = Location(name='38', sector='state_lower').save() upper = Location(name='15', sector='state_upper').save() mi.encompasses.connect(lower) lower.encompassed_by.connect(mi) mi.encompasses.connect(upper) upper.encompassed_by.connect(mi) res = connect_to_state_districts.apply_async( kwargs={'object_uuid': address.object_uuid}) self.assertTrue(res.result) self.assertTrue(lower in address.encompassed_by) self.assertTrue(upper in address.encompassed_by) mi.delete() address.delete() upper.delete() lower.delete()
def test_create_state_districts_already_exist(self): mi = Location(name=us.states.lookup("MI").name, sector="federal").save() address = Address(state="MI", latitude=42.532020, longitude=-83.496500).save() upper = Location(name="15", sector="state_upper").save() lower = Location(name="38", sector="state_lower").save() address.encompassed_by.connect(lower) address.encompassed_by.connect(upper) mi.encompasses.connect(upper) upper.encompassed_by.connect(mi) mi.encompasses.connect(lower) lower.encompassed_by.connect(mi) res = connect_to_state_districts.apply_async( kwargs={'object_uuid': address.object_uuid}) self.assertTrue(res.result) query = 'MATCH (l:Location {name:"38", sector:"state_lower"}), ' \ '(l2:Location {name:"15", sector:"state_upper"}) RETURN l, l2' res, _ = db.cypher_query(query) lower = Location.inflate(res[0].l) upper = Location.inflate(res[0].l2) self.assertTrue(lower in address.encompassed_by) self.assertTrue(upper in address.encompassed_by) res = connect_to_state_districts.apply_async( kwargs={'object_uuid': address.object_uuid}) self.assertTrue(res.result) query = 'MATCH (l:Location {name:"38", sector:"state_lower"}), ' \ '(l2:Location {name:"15", sector:"state_upper"}) RETURN l, l2' res, _ = db.cypher_query(query) self.assertEqual(len(res[0]), 2) # assert only two nodes returned self.assertEqual(lower, Location.inflate(res[0].l)) # assert only one lower node self.assertEqual(upper, Location.inflate(res[0].l2)) # assert only one upper node mi.delete() address.delete() upper.delete() lower.delete()
class TestCreateStateDistricts(TestCase): def setUp(self): settings.CELERY_ALWAYS_EAGER = True self.email = "*****@*****.**" self.pleb = create_user_util_test(self.email) self.user = User.objects.get(email=self.email) self.headers = {"content-type": 'application/json; charset=utf8'} with open("sb_public_official/tests/michigan_reps.json") as json_file: self.json_data = json.load(json_file) self.mi = Location(name=us.states.lookup("MI").name, sector="federal").save() self.lower = Location(name='38', sector='state_lower').save() self.upper = Location(name='15', sector='state_upper').save() self.mi.encompasses.connect(self.lower) self.lower.encompassed_by.connect(self.mi) self.mi.encompasses.connect(self.upper) self.upper.encompassed_by.connect(self.mi) self.lower_pos = Position().save() self.lower_pos.location.connect(self.lower) self.upper_pos = Position().save() self.upper_pos.location.connect(self.upper) def tearDown(self): settings.CELERY_ALWAYS_EAGER = False self.mi.delete() self.lower.delete() self.upper.delete() self.upper_pos.delete() self.lower_pos.delete() def test_success(self): res = create_and_attach_state_level_reps.apply_async( kwargs={'rep_data': self.json_data}) while not res.ready(): time.sleep(1) self.assertTrue(res.result) def test_rep_already_exists(self): try: official = PublicOfficial.nodes.get(bioguideid="MIL000290") except (PublicOfficial.DoesNotExist, DoesNotExist): official = PublicOfficial(bioguideid="MIL000290", first_name="Kathy", last_name="Crawford", state_district="38", state_chamber="lower", state="mi").save() res = create_and_attach_state_level_reps.apply_async( kwargs={'rep_data': self.json_data}) while not res.ready(): time.sleep(1) self.assertTrue(res.result) camp = official.get_quest() self.assertTrue(camp in official.quest) official.delete() camp.delete() def test_rep_already_has_campaign(self): try: official = PublicOfficial.nodes.get(bioguideid="MIL000290") official.delete() except (PublicOfficial.DoesNotExist, DoesNotExist): pass official = PublicOfficial(bioguideid="MIL000290", first_name="Kathy", last_name="Crawford", state_district="38", state_chamber="lower", state="mi").save() campaign = Quest(first_name=official.first_name, last_name=official.last_name).save() official.quest.connect(campaign) res = create_and_attach_state_level_reps.apply_async( kwargs={'rep_data': self.json_data}) while not res.ready(): time.sleep(1) self.assertTrue(res.result) official.delete() campaign.delete()