File: __init__.py

package info (click to toggle)
python-aio-geojson-client 0.20-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 268 kB
  • sloc: python: 1,368; makefile: 4
file content (69 lines) | stat: -rw-r--r-- 1,937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Tests for aio-geojson-client library."""
from __future__ import annotations

from datetime import datetime
from typing import Optional

from aio_geojson_client.feed import GeoJsonFeed
from aio_geojson_client.feed_entry import FeedEntry

ATTR_GUID = "guid"
ATTR_ID = "id"
ATTR_TITLE = "title"


class MockGeoJsonFeed(GeoJsonFeed):
    """Mock geojson feed."""

    def _extract_from_feed(self, feed) -> Optional:
        return None

    def _extract_last_timestamp(self, feed_entries) -> datetime | None:
        return None

    def _new_entry(self, home_coordinates, feature, global_data):
        """Generate a new entry."""
        return MockFeedEntry(home_coordinates, feature)


class MockSimpleFeedEntry(FeedEntry):
    """Mock feed entry."""

    @property
    def title(self) -> str | None:
        """Return title."""
        return "mock title"

    @property
    def external_id(self) -> str | None:
        """Return external id."""
        return "mock id"


class MockFeedEntry(FeedEntry):
    """Generic feed entry."""

    def __init__(self, home_coordinates, feature):
        """Initialise this service."""
        super().__init__(home_coordinates, feature)

    @property
    def title(self) -> str:
        """Return the title of this entry."""
        return self._search_in_properties(ATTR_TITLE)

    @property
    def external_id(self) -> str:
        """Return the external id of this entry."""
        """Find a suitable ID for the provided entry."""
        external_id = self._search_in_feature(ATTR_ID)
        if not external_id:
            external_id = self._search_in_properties(ATTR_ID)
        if not external_id:
            external_id = self._search_in_properties(ATTR_GUID)
        if not external_id:
            external_id = self.title
        if not external_id:
            # Use geometry as ID as a fallback.
            external_id = hash(self.coordinates)
        return external_id