Exemplo n.º 1
0
    def test_update_offices_geolocations(self):
        """
        Test `update_offices_geolocations`.
        """
        # Add an entry in the OfficeAdminExtraGeoLocation table with extra geolocations.
        extra_geolocation = OfficeAdminExtraGeoLocation(
            siret=self.office1.siret,
            codes="75110\n13055",  # Paris 10 + Marseille
        )
        extra_geolocation.save(commit=True)

        script.update_offices_geolocations()

        # The office should now have 3 geolocations in ES (the original one + Paris 10 + Marseille).
        res = self.es.get(index=settings.ES_INDEX,
                          doc_type=es.OFFICE_TYPE,
                          id=self.office1.siret)
        expected_locations = [
            {
                'lat': 43.25996690043557,
                'lon': 5.370740865779022
            },
            {
                'lat': 48.8815994262695,
                'lon': 2.36229991912841
            },
            {
                'lat': 49.1044,
                'lon': 6.17952
            },
        ]
        self.assertEqual(
            sorted(res['_source']['locations'],
                   key=lambda x: (x['lat'], x['lon'])), expected_locations)

        office = Office.get(self.office1.siret)
        self.assertTrue(office.has_multi_geolocations)

        # Make `extra_geolocation` instance out-of-date.
        extra_geolocation.date_end = datetime.datetime.now(
        ) - datetime.timedelta(days=1)
        extra_geolocation.update()
        self.assertTrue(extra_geolocation.is_outdated())

        script.update_offices_geolocations()

        # The office extra geolocations should now be reset.
        res = self.es.get(index=settings.ES_INDEX,
                          doc_type=es.OFFICE_TYPE,
                          id=self.office1.siret)
        expected_locations = [
            {
                'lat': 49.1044,
                'lon': 6.17952
            },
        ]
        self.assertEqual(res['_source']['locations'], expected_locations)

        office = Office.get(self.office1.siret)
        self.assertFalse(office.has_multi_geolocations)
Exemplo n.º 2
0
 def test_is_outdated(self):
     """
     Test `OfficeAdminExtraGeoLocation.is_outdated()`.
     """
     extra_geolocation = OfficeAdminExtraGeoLocation(
         siret="38524664000176",
         codes="75108",
     )
     extra_geolocation.save()
     self.assertFalse(extra_geolocation.is_outdated())
     # Make `extra_geolocation` instance out-of-date.
     extra_geolocation.date_end = datetime.datetime.now(
     ) - datetime.timedelta(days=1)
     extra_geolocation.update()
     self.assertTrue(extra_geolocation.is_outdated())