def test_google_places_city_without_state(self, m): query = 'MATCH (a:Location) OPTIONAL MATCH (a)-[r]-() DELETE a, r' db.cypher_query(query) url = "https://maps.googleapis.com/maps/api/" \ "place/details/json?placeid=%s&key=%s" % ( wixom_without_state_data['place_id'], settings.GOOGLE_MAPS_API_SERVER) m.get(url, json=wixom_server_response, status_code=status.HTTP_200_OK) location = parse_google_places( wixom_without_state_data['address_components'], wixom_without_state_data['place_id']) self.assertEqual(location.name, "Wixom") res, _ = db.cypher_query('MATCH (a:Location ' '{name: "Michigan"}) RETURN a') state = Location.inflate(res.one) res, _ = db.cypher_query( 'MATCH (a:Location ' '{name: "United States of America"}) RETURN a') country = Location.inflate(res.one) self.assertTrue(state in location.encompassed_by) self.assertTrue(location in state.encompasses) self.assertTrue(country in state.encompassed_by) self.assertTrue(state in country.encompasses)
def test_google_places_country(self): query = 'MATCH (a:Location) OPTIONAL MATCH (a)-[r]-() DELETE a, r' db.cypher_query(query) location = parse_google_places(us_data['address_components'], us_data['place_id']) self.assertEqual(location.name, "United States of America") self.assertIsInstance(location, Location)
def test_google_places_country_already_exists(self): query = 'MATCH (a:Location) OPTIONAL MATCH (a)-[r]-() DELETE a, r' db.cypher_query(query) old_location = Location(name="United States of America").save() location = parse_google_places(us_data['address_components'], us_data['place_id']) self.assertEqual(location.name, "United States of America") self.assertIsInstance(location, Location) self.assertEqual(old_location.object_uuid, location.object_uuid)
def test_connect_no_related_element(self): cache.clear() query = 'MATCH (a:Question) OPTIONAL MATCH (a)-[r]-() DELETE a, r' db.cypher_query(query) question = Question(title="Hello this is my question", content="This is content", owner_username=self.pleb.username).save() location = parse_google_places(wixom_data['address_components'], wixom_data['place_id']) connected = connect_related_element(location, wixom_data['place_id']) self.assertIsNone(connected) question.delete()
def test_google_places_state(self): query = 'MATCH (a:Location) OPTIONAL MATCH (a)-[r]-() DELETE a, r' db.cypher_query(query) location = parse_google_places(quebec_data['address_components'], quebec_data['place_id']) self.assertEqual(location.name, "Quebec") res, _ = db.cypher_query('MATCH (a:Location ' '{name: "Canada"}) RETURN a') country = Location.inflate(res.one) self.assertTrue(country in location.encompassed_by) self.assertTrue(location in country.encompasses)
def test_google_places_city(self): query = 'MATCH (a:Location) OPTIONAL MATCH (a)-[r]-() DELETE a, r' db.cypher_query(query) location = parse_google_places(wixom_data['address_components'], wixom_data['place_id']) self.assertEqual(location.name, "Wixom") res, _ = db.cypher_query('MATCH (a:Location ' '{name: "Michigan"}) RETURN a') state = Location.inflate(res.one) res, _ = db.cypher_query( 'MATCH (a:Location ' '{name: "United States of America"}) RETURN a') country = Location.inflate(res.one) self.assertTrue(state in location.encompassed_by) self.assertTrue(location in state.encompasses) self.assertTrue(country in state.encompassed_by) self.assertTrue(state in country.encompasses)
def test_google_places_city_already_exists(self): query = 'MATCH (a:Location) OPTIONAL MATCH (a)-[r]-() DELETE a, r' db.cypher_query(query) old_country = Location(name="United States of America").save() old_state = Location(name="Michigan").save() old_city = Location(name="Wixom").save() old_country.encompasses.connect(old_state) old_state.encompassed_by.connect(old_country) old_state.encompasses.connect(old_city) old_city.encompassed_by.connect(old_state) location = parse_google_places(wixom_data['address_components'], wixom_data['place_id']) self.assertEqual(location.name, "Wixom") self.assertIsInstance(location, Location) self.assertEqual(old_city.object_uuid, location.object_uuid) self.assertTrue(old_state in location.encompassed_by) self.assertTrue(location in old_state.encompasses)