Skip to content

Commit ebf4683

Browse files
committed
add api changes
1 parent 628211c commit ebf4683

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

api/src/feeds/impl/models/gbfs_feed_impl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from feeds.impl.models.bounding_box_impl import BoundingBoxImpl
12
from feeds.impl.models.feed_impl import FeedImpl
23
from feeds.impl.models.gbfs_version_impl import GbfsVersionImpl
34
from shared.database_gen.sqlacodegen_models import Gbfsfeed as GbfsFeedOrm
@@ -29,4 +30,6 @@ def from_orm(cls, feed: GbfsFeedOrm | None) -> GbfsFeed | None:
2930
if feed.gbfsversions
3031
else []
3132
)
33+
gbfs_feed.bounding_box = BoundingBoxImpl.from_orm(feed.bounding_box)
34+
gbfs_feed.bounding_box_generated_at = feed.bounding_box_generated_at
3235
return gbfs_feed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import unittest
2+
from datetime import datetime
3+
4+
from geoalchemy2 import WKTElement
5+
6+
from feeds_gen.models.source_info import SourceInfo
7+
from shared.database_gen.sqlacodegen_models import Gbfsfeed, Location, Gbfsversion
8+
from feeds.impl.models.gbfs_feed_impl import GbfsFeedImpl
9+
from feeds.impl.models.location_impl import LocationImpl
10+
from feeds.impl.models.gbfs_version_impl import GbfsVersionImpl
11+
from feeds.impl.models.bounding_box_impl import BoundingBoxImpl
12+
13+
POLYGON = "POLYGON ((3.0 1.0, 4.0 1.0, 4.0 2.0, 3.0 2.0, 3.0 1.0))"
14+
15+
16+
class TestGbfsFeedImpl(unittest.TestCase):
17+
def setUp(self):
18+
self.location_orm = Location(
19+
id="loc1",
20+
country_code="US",
21+
country="United States",
22+
subdivision_name="California",
23+
municipality="San Francisco",
24+
)
25+
self.version_orm = Gbfsversion(
26+
id="ver1",
27+
version="2.2",
28+
url="https://example.com/gbfs.json",
29+
)
30+
self.bounding_box_orm = WKTElement(POLYGON, srid=4326)
31+
self.feed_orm = Gbfsfeed(
32+
id="feed1",
33+
stable_id="feed_stable_1",
34+
created_at=datetime(2024, 1, 1, 10, 0, 0),
35+
data_type="gbfs",
36+
system_id="sys1",
37+
operator_url="https://provider.com",
38+
locations=[self.location_orm],
39+
gbfsversions=[self.version_orm],
40+
bounding_box=self.bounding_box_orm,
41+
bounding_box_generated_at=datetime(2024, 1, 1, 12, 0, 0),
42+
authentication_type=0,
43+
authentication_info_url="https://auth.info",
44+
api_key_parameter_name="api_key",
45+
license_url="https://license.info",
46+
)
47+
48+
def test_from_orm_all_fields(self):
49+
expected = GbfsFeedImpl(
50+
id="feed_stable_1",
51+
system_id="sys1",
52+
data_type="gbfs",
53+
created_at=datetime(2024, 1, 1, 10, 0, 0),
54+
external_ids=[],
55+
redirects=[],
56+
provider_url="https://provider.com",
57+
locations=[LocationImpl.from_orm(self.location_orm)],
58+
versions=[GbfsVersionImpl.from_orm(self.version_orm)],
59+
bounding_box=BoundingBoxImpl.from_orm(self.bounding_box_orm),
60+
bounding_box_generated_at=datetime(2024, 1, 1, 12, 0, 0),
61+
source_info=SourceInfo(
62+
producer_url=None,
63+
authentication_type=0,
64+
authentication_info_url="https://auth.info",
65+
api_key_parameter_name="api_key",
66+
license_url="https://license.info",
67+
),
68+
)
69+
result = GbfsFeedImpl.from_orm(self.feed_orm)
70+
self.assertEqual(result, expected)
71+
72+
def test_from_orm_empty_fields(self):
73+
feed_orm = Gbfsfeed(
74+
id="feed2",
75+
stable_id="feed_stable_2",
76+
system_id=None,
77+
operator_url=None,
78+
locations=[],
79+
gbfsversions=[],
80+
bounding_box=None,
81+
bounding_box_generated_at=None,
82+
)
83+
expected = GbfsFeedImpl(
84+
id="feed_stable_2",
85+
system_id=None,
86+
provider_url=None,
87+
external_ids=[],
88+
redirects=[],
89+
locations=[],
90+
versions=[],
91+
bounding_box=None,
92+
bounding_box_generated_at=None,
93+
source_info=SourceInfo(
94+
producer_url=None,
95+
authentication_type=None,
96+
authentication_info_url=None,
97+
api_key_parameter_name=None,
98+
license_url=None,
99+
),
100+
)
101+
result = GbfsFeedImpl.from_orm(feed_orm)
102+
self.assertEqual(result, expected)
103+
104+
def test_from_orm_none(self):
105+
result = GbfsFeedImpl.from_orm(None)
106+
self.assertIsNone(result)

docs/DatabaseCatalogAPI.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,13 @@ components:
512512
type: array
513513
items:
514514
$ref: "#/components/schemas/GbfsVersion"
515+
bounding_box:
516+
$ref: "#/components/schemas/BoundingBox"
517+
bounding_box_generated_at:
518+
description: The date and time the bounding box was generated, in ISO 8601 date-time format.
519+
type: string
520+
example: 2023-07-10T22:06:00Z
521+
format: date-time
515522

516523
GbfsVersion:
517524
type: object

0 commit comments

Comments
 (0)