-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_basic_feed_impl.py
More file actions
160 lines (149 loc) · 5.17 KB
/
test_basic_feed_impl.py
File metadata and controls
160 lines (149 loc) · 5.17 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import copy
import unittest
from datetime import datetime
from zoneinfo import ZoneInfo
from shared.database_gen.sqlacodegen_models import (
Feed,
Externalid,
Location,
Gtfsdataset,
Validationreport,
Redirectingid,
Feature,
)
from feeds.impl.models.basic_feed_impl import BasicFeedImpl
from feeds.impl.models.external_id_impl import ExternalIdImpl
from feeds.impl.models.redirect_impl import RedirectImpl
from feeds_gen.models.source_info import SourceInfo
targetFeed = Feed(
id="id1",
stable_id="target_id",
locations=[],
externalids=[],
gtfsdatasets=[],
redirectingids=[],
)
feed_orm = Feed(
id="id",
data_type="gtfs",
feed_name="feed_name",
note="note",
producer_url="producer_url",
authentication_type="1",
authentication_info_url="authentication_info_url",
api_key_parameter_name="api_key_parameter_name",
license_url="license_url",
stable_id="stable_id",
status="active",
feed_contact_email="feed_contact_email",
provider="provider",
locations=[
Location(
id="id",
country_code="CA",
country=None,
subdivision_name="subdivision_name",
municipality="municipality",
)
],
externalids=[
Externalid(
feed_id="feed_id",
associated_id="associated_id",
source="source",
)
],
gtfsdatasets=[
Gtfsdataset(
id="id",
stable_id="stable_id",
feed_id="feed_id",
hosted_url="hosted_url",
note="note",
downloaded_at="downloaded_at",
hash="hash",
bounding_box="bounding_box",
service_date_range_start=datetime(2024, 1, 1, 0, 0, 0, tzinfo=ZoneInfo("Canada/Atlantic")),
service_date_range_end=datetime(2025, 1, 1, 0, 0, 0, tzinfo=ZoneInfo("Canada/Atlantic")),
agency_timezone="Canada/Atlantic",
validation_reports=[
Validationreport(
id="id",
validator_version="validator_version",
validated_at=datetime(year=2022, month=12, day=31, hour=13, minute=45, second=56),
html_report="html_report",
json_report="json_report",
features=[Feature(name="feature")],
notices=[],
)
],
)
],
redirectingids=[
Redirectingid(source_id="source_id", target_id="id1", redirect_comment="redirect_comment", target=targetFeed)
],
)
expected_base_feed_result = BasicFeedImpl(
id="stable_id",
data_type="gtfs",
status="active",
external_ids=[ExternalIdImpl(external_id="associated_id", source="source")],
provider="provider",
feed_name="feed_name",
note="note",
feed_contact_email="feed_contact_email",
source_info=SourceInfo(
producer_url="producer_url",
authentication_type=1,
authentication_info_url="authentication_info_url",
api_key_parameter_name="api_key_parameter_name",
license_url="license_url",
),
redirects=[
RedirectImpl(
target_id="target_id",
comment="redirect_comment",
)
],
)
class TestBasicFeedImpl(unittest.TestCase):
"""Test the `BasicFeedImpl` model."""
def test_from_orm_all_fields(self):
"""Test the `from_orm` method with all fields."""
result = BasicFeedImpl.from_orm(feed_orm)
assert result == expected_base_feed_result
def test_from_orm_empty_fields(self):
"""Test the `from_orm` method with not provided fields."""
# Test with empty fields and None values
# No error should be raised
# Target is set to None as deep copy is failing for unknown reasons
# At the end of the test, the target is set back to the original value
feed_orm.redirectingids[0].target = None
target_feed_orm = copy.deepcopy(feed_orm)
target_feed_orm.feed_name = ""
target_feed_orm.provider = None
target_feed_orm.externalids = []
target_feed_orm.redirectingids = []
target_expected_base_feed_result = copy.deepcopy(expected_base_feed_result)
target_expected_base_feed_result.feed_name = ""
target_expected_base_feed_result.provider = None
target_expected_base_feed_result.external_ids = []
target_expected_base_feed_result.redirects = []
result = BasicFeedImpl.from_orm(target_feed_orm)
assert result == target_expected_base_feed_result
# Test all None values
# No error should be raised
# Resulting list must be empty and not None
empty_feed_orm = Feed()
expected_empty_feed = BasicFeedImpl(
external_ids=[],
redirects=[],
source_info=SourceInfo(),
)
empty_result = BasicFeedImpl.from_orm(empty_feed_orm)
assert empty_result == expected_empty_feed
# Setting the target at the end of the test
feed_orm.redirectingids[0].target = targetFeed
def test_from_orm_none(self):
"""Test the `from_orm` method with None."""
assert BasicFeedImpl.from_orm(None) is None