Пример #1
0
    def test_diff(self):
        Place.request = MagicMock(return_value=[
            {
                "id_place": "1",
                "id_universal": "1",
                "modification_type": "updated",
            },
            {
                "id_place": "2",
                "id_universal": "2",
                "modification_type": "deleted",
            },
        ])

        # Case 1: without retrieving
        date = datetime.now() - timedelta(hours=1)
        observations = Place.diff(
            date,
            modification_type=ModificationType.ALL,
            only_protocol="CBBM",
        )
        self.assertEqual(len(observations), 2)
        Place.request.assert_called_with(
            method="get",
            url="places/diff",
            params={
                "date": date.replace(microsecond=0).isoformat(),
                "modification_type": ModificationType.ALL.value,
                "only_protocol": "CBBM",
            },
        )

        # Case 2: with retrieving

        mock_protocol = MagicMock(spec=ornitho.Protocol)
        type(mock_protocol).name = mock.PropertyMock(return_value="CBBM-Mock")
        Place.get = MagicMock(return_value=self.place)
        date = datetime.now().astimezone(
            pytz.timezone("Asia/Tokyo")) - timedelta(hours=1)
        places = Place.diff(date,
                            only_protocol=mock_protocol,
                            retrieve_places=True)
        self.assertEqual(len(places), 2)
        self.assertEqual(places[0], self.place)
        Place.request.assert_called_with(
            method="get",
            url="places/diff",
            params={
                "date":
                date.replace(microsecond=0).astimezone(
                    datetime.now().astimezone().tzinfo).replace(
                        tzinfo=None).isoformat(),
                "only_protocol":
                "CBBM-Mock",
            },
        )
Пример #2
0
 def setUp(self):
     self.place_json = {
         "id": "767",
         "id_commune": "8192",
         "name": "Aasbüttel (SH, IZ) - Gemeindemittelpunkt",
         "coord_lon": "9.43977095617034",
         "coord_lat": "54.0686078708784",
         "altitude": "52",
         "id_region": "5",
         "visible": "0",
         "is_private": "0",
         "place_type": "municipality",
         "loc_precision": "750",
         "municipality": "municipality",
         "created_by": "30",
         "created_date": {
             "@timestamp": "1285902090",
             "@notime": "0",
             "@offset": "7200",
             "@ISO8601": "2010-10-01T05:01:30+02:00",
             "#text": "Freitag, 1. Oktober 2010, 05:01:30",
         },
         "last_updated_by": "30",
         "last_updated_date": {
             "@timestamp": "1530066871",
             "@notime": "0",
             "@offset": "7200",
             "@ISO8601": "2018-06-27T04:34:31+02:00",
             "#text": "Mittwoch, 27. Juni 2018, 04:34:31",
         },
     }
     self.place = Place.create_from_ornitho_json(self.place_json)
     self.place._refreshed = True
Пример #3
0
 def polygon_places(self) -> Optional[List[Place]]:
     if self._polygon_places is None:
         if "polygons" in self._raw_data:
             self._polygon_places = [
                 Place.create_from_site(raw_transect)
                 for raw_transect in self._raw_data["polygons"]
             ]
     return self._polygon_places
Пример #4
0
 def test_create_from_site(self):
     place = Place.create_from_site({
         "id": "1",
         "id_universal": "1_1",
         "name": "ETST (1)",
         "altitude": "1",
         "order": "1",
         "wkt": "POINT(1.1 2.2)",
     })
     self.assertEqual(1, place.id_)
Пример #5
0
 def id_place(self) -> int:
     if "place" not in self._raw_data:
         id_place = Place.find_closest_place(
             self.coord_lat, self.coord_lon, get_hidden=True
         ).id_
         if id_place is not None:
             self.id_place = int(id_place)
             return int(id_place)
     if "@id" in self._raw_data["place"]:
         return int(self._raw_data["place"]["@id"])
     else:
         return int(self._raw_data["place"]["id"])
Пример #6
0
 def place(self) -> Place:
     if self._place is None:
         self._place = Place(id_=self.id_reference_locality)
     return self._place
Пример #7
0
    def test_find_closest_place(self, mock_list_all):
        mock_list_all.return_value = ["Place"]

        place = Place.find_closest_place(1.1, 2.2)
        self.assertEqual(place, "Place")
Пример #8
0
 def place(self) -> Place:
     """ Place of the observation """
     if self._place is None:
         self._place = Place.create_from_ornitho_json(self._raw_data["place"])
     return self._place