Ejemplo n.º 1
0
 def test_correct_data_under_places(self):
     """
     under the `cities_cities_places_template_key<city_name>` is a hash.
     The key is a place_id as per the Google Places Search API.
     The value is an object, as returned by the same API.
     """
     load_to_datastore(self.places_sofia, self.metadata_sofia)
     CommonAssertions.check_correct_data_under_places(
         tester=self,
         places=self.places_sofia,
         metadata=self.metadata_sofia)
Ejemplo n.º 2
0
 def test_correct_data_under_coordinates(self):
     """
     https://redis.io/commands/geoadd
     The `cities_coordinates_template_key<area_name>` holds a sorted set.
     Here we test that the correct items were added to this set.
     An item consists of [lat lng place_id], where place_id is also a key under the
     `cities_places_template_key<area_name>`
     """
     load_to_datastore(self.places_sofia, self.metadata_sofia)
     CommonAssertions.check_correct_data_under_coordinates(
         tester=self,
         metadata=self.metadata_sofia,
         places=self.places_sofia)
Ejemplo n.º 3
0
    def test_load_two_areas(self):
        data = [[self.metadata_sofia, self.places_sofia],
                [self.metadata_leuven, self.places_leuven]]

        for metadata, places in data:
            print("loading data for %s" % metadata.area_name)
            load_to_datastore(places=places, metadata=metadata)

        for metadata, places in data:
            print("run all tests for %s" % metadata.area_name)
            CommonAssertions.run_all_tests_single_area_loaded(
                tester=self, places=places, metadata=metadata)
            CommonAssertions.check_exclusive_correct_top_level_keys_loaded_in_redis(
                tester=self,
                expected_areas=[
                    self.metadata_leuven.area_name,
                    self.metadata_sofia.area_name,
                ])
Ejemplo n.º 4
0
    def test_update(self):
        """
        We'd first load half of the dummy data for the given city.
        We'd then load the whole data set.
        We expect that the old data is fully replaced with the new one
        """
        metadata = self.metadata_sofia  # the metadata'd stay the same
        places_initial_batch = dict(
            list(self.places_sofia.items())[:len(self.places_sofia) //
                                            2])  # get the first half of a dict
        load_to_datastore(places=places_initial_batch, metadata=metadata)

        # sanity checking
        CommonAssertions.run_all_tests_single_area_loaded(
            tester=self, places=places_initial_batch, metadata=metadata)

        # now load a second batch (which is just all of the available data)
        load_to_datastore(places=self.places_sofia, metadata=metadata)
        # and test again
        CommonAssertions.run_all_tests_single_area_loaded(
            tester=self, places=self.places_sofia, metadata=metadata)
Ejemplo n.º 5
0
    def test_correct_data_under_boundaries(self):
        """
        The `cities_boundaries_key` holds a hash.
        The value is the name of a geographical area. the value is a json object with shape like
        {
            "northwest":{"lat":1, "lng":2},
            "southeast":{"lat":1, "lng":2},
        }
        """
        load_to_datastore(self.places_sofia, self.metadata_sofia)

        area_name = self.metadata_sofia.area_name

        # ensure only the boundary for the correct single area is loaded
        redis_boundaries_keys = r.keys(
            "*%s*" % cities_boundaries_template_key)  # returns a list
        self.assertEqual(set([cities_boundaries_template_key + area_name]),
                         set(redis_boundaries_keys))

        CommonAssertions.check_correct_boundaries_for_area(
            tester=self, metadata=self.metadata_sofia)
Ejemplo n.º 6
0
 def test_correct_top_level_keys(self):
     # dummy_data was loaded from a file with the same format as original data.
     load_to_datastore(self.places_sofia, self.metadata_sofia)
     CommonAssertions.check_exclusive_correct_top_level_keys_loaded_in_redis(
         tester=self, expected_areas=[self.metadata_sofia.area_name])
Ejemplo n.º 7
0
def main():
    places, metadata = read_input()
    log.info("Loaded input file with %i places." % len(places))
    log.info("area-name = %s" % metadata.area_name)

    load_to_datastore(places, metadata=metadata)