Skip to content

Commit

Permalink
chore(tests): move test data into dedicated json (#49)
Browse files Browse the repository at this point in the history
Fix #30
  • Loading branch information
jonperron authored May 24, 2024
1 parent 5af90eb commit 585b130
Show file tree
Hide file tree
Showing 33 changed files with 1,168 additions and 1,416 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pytest

from unittest.mock import MagicMock, patch
Expand All @@ -21,18 +22,9 @@ def test_list_entity_collection_from_region(
) -> None:
# Given
mock_response = MagicMock()
mock_response.json.return_value = {
"commercial_modes": [
{"id": "commercial_mode:buz", "name": "Buz"},
{"id": "commercial_mode:foo", "name": "foo"},
],
"pagination": {
"items_on_page": 25,
"items_per_page": 25,
"start_page": 0,
"total_result": 99,
},
}
with open("tests/test_data/commercial_mode.json", encoding="utf-8") as file:
mock_response.json.return_value = json.load(file)

mock_get_navitia_api.return_value = mock_response

# When
Expand All @@ -51,20 +43,14 @@ def test_get_entity_by_id(
) -> None:
# Given
mock_response = MagicMock()
mock_response.json.return_value = {
"commercial_modes": [{"id": "commercial_mode:foo", "name": "foo"}],
"pagination": {
"items_on_page": 25,
"items_per_page": 25,
"start_page": 0,
"total_result": 99,
},
}
with open("tests/test_data/commercial_mode.json", encoding="utf-8") as file:
mock_response.json.return_value = json.load(file)

mock_get_navitia_api.return_value = mock_response

# When
commercial_modes, _ = commercial_modes_apis.get_entity_by_id("tuz", "1")

# Then
assert len(commercial_modes) == 1
assert len(commercial_modes) == 2
assert isinstance(commercial_modes[0], CommercialMode)
19 changes: 4 additions & 15 deletions tests/client/apis/public_transportation_apis/test_company_apis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pytest

from unittest.mock import MagicMock, patch
Expand All @@ -19,21 +20,9 @@ def test_list_entity_collection_from_region(
) -> None:
# Given
mock_response = MagicMock()
mock_response.json.return_value = {
"companies": [
{
"codes": [{"type": "source", "value": "12"}],
"id": "company:foo:0012",
"name": "Foo gmbh",
}
],
"pagination": {
"items_on_page": 25,
"items_per_page": 25,
"start_page": 0,
"total_result": 99,
},
}
with open("tests/test_data/company.json", encoding="utf-8") as file:
mock_response.json.return_value = json.load(file)

mock_get_navitia_api.return_value = mock_response

# When
Expand Down
388 changes: 8 additions & 380 deletions tests/client/apis/public_transportation_apis/test_disruption_apis.py

Large diffs are not rendered by default.

173 changes: 8 additions & 165 deletions tests/client/apis/public_transportation_apis/test_line_apis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pytest

from unittest.mock import MagicMock, patch
Expand All @@ -19,112 +20,9 @@ def test_list_entity_collection_from_region(
) -> None:
# Given
mock_response = MagicMock()
mock_response.json.return_value = {
"lines": [
{
"closing_time": "220430",
"code": "",
"codes": [],
"color": "",
"commercial_mode": {"id": "commercial_mode:barS", "name": "bar foo"},
"geojson": {"coordinates": [], "type": "MultiLineString"},
"id": "line:foo:FR:Line::0000000:",
"links": [],
"name": "Lauterbourg - Woerth Rhein",
"network": {"id": "network:foo:barS", "links": [], "name": "bar foo"},
"opening_time": "043900",
"physical_modes": [
{
"id": "physical_mode:LongDistanceTrain",
"name": "Train grande vitesse",
}
],
"routes": [
{
"direction": {
"embedded_type": "stop_area",
"id": "stop_area:foo:0000000",
"name": "Lauterbourg (Lauterbourg)",
"quality": 0,
"stop_area": {
"codes": [
{"type": "source", "value": "0000000"},
{"type": "uic", "value": "0000000"},
],
"coord": {"lat": "48.967697", "lon": "8.182682"},
"id": "stop_area:foo:0000000",
"label": "Lauterbourg " "(Lauterbourg)",
"links": [],
"name": "Lauterbourg",
"timezone": "Europe/Paris",
},
},
"direction_type": "forward",
"geojson": {"coordinates": [], "type": "MultiLineString"},
"id": "route:foo:FR:Line::0000000:",
"is_frequence": "False",
"links": [],
"name": "Lauterbourg - Woerth Rhein",
}
],
"text_color": "",
},
{
"closing_time": "214900",
"code": "",
"codes": [],
"color": "",
"commercial_mode": {"id": "commercial_mode:barS", "name": "bar foo"},
"geojson": {"coordinates": [], "type": "MultiLineString"},
"id": "line:foo:CSR:0000000",
"links": [],
"name": "Marseille Saint-Charles - Frankfurt am Main Hbf",
"network": {"id": "network:foo:barS", "links": [], "name": "bar foo"},
"opening_time": "081200",
"physical_modes": [
{
"id": "physical_mode:LongDistanceTrain",
"name": "Train grande vitesse",
}
],
"routes": [
{
"direction": {
"embedded_type": "stop_area",
"id": "stop_area:foo:0000000",
"name": "Marseille Saint-Charles " "(Marseille)",
"quality": 0,
"stop_area": {
"codes": [
{"type": "source", "value": "0000000"},
{"type": "uic", "value": "0000000"},
],
"coord": {"lat": "43.302666", "lon": "5.380407"},
"id": "stop_area:foo:0000000",
"label": "Marseille " "Saint-Charles " "(Marseille)",
"links": [],
"name": "Marseille " "Saint-Charles",
"timezone": "Europe/Paris",
},
},
"direction_type": "forward",
"geojson": {"coordinates": [], "type": "MultiLineString"},
"id": "route:foo:CSR:0000000",
"is_frequence": "False",
"links": [],
"name": "Marseille Saint-Charles - Frankfurt am Main " "Hbf",
}
],
"text_color": "",
},
],
"pagination": {
"items_on_page": 25,
"items_per_page": 25,
"start_page": 0,
"total_result": 99,
},
}
with open("tests/test_data/line.json", encoding="utf-8") as file:
mock_response.json.return_value = json.load(file)

mock_get_navitia_api.return_value = mock_response

# When
Expand All @@ -141,69 +39,14 @@ def test_get_entity_by_id(
) -> None:
# Given
mock_response = MagicMock()
mock_response.json.return_value = {
"lines": [
{
"closing_time": "220430",
"code": "",
"codes": [],
"color": "",
"commercial_mode": {"id": "commercial_mode:barS", "name": "bar foo"},
"geojson": {"coordinates": [], "type": "MultiLineString"},
"id": "line:foo:FR:Line::0000000:",
"links": [],
"name": "Lauterbourg - Woerth Rhein",
"network": {"id": "network:foo:barS", "links": [], "name": "bar foo"},
"opening_time": "043900",
"physical_modes": [
{
"id": "physical_mode:LongDistanceTrain",
"name": "Train grande vitesse",
}
],
"routes": [
{
"direction": {
"embedded_type": "stop_area",
"id": "stop_area:foo:0000000",
"name": "Lauterbourg (Lauterbourg)",
"quality": 0,
"stop_area": {
"codes": [
{"type": "source", "value": "0000000"},
{"type": "uic", "value": "0000000"},
],
"coord": {"lat": "48.967697", "lon": "8.182682"},
"id": "stop_area:foo:87212464",
"label": "Lauterbourg " "(Lauterbourg)",
"links": [],
"name": "Lauterbourg",
"timezone": "Europe/Paris",
},
},
"direction_type": "forward",
"geojson": {"coordinates": [], "type": "MultiLineString"},
"id": "route:foo:FR:Line::0000000:",
"is_frequence": "False",
"links": [],
"name": "Lauterbourg - Woerth Rhein",
}
],
"text_color": "",
},
],
"pagination": {
"items_on_page": 25,
"items_per_page": 25,
"start_page": 0,
"total_result": 99,
},
}
with open("tests/test_data/line.json", encoding="utf-8") as file:
mock_response.json.return_value = json.load(file)

mock_get_navitia_api.return_value = mock_response

# When
lines, _ = line_apis.get_entity_by_id("tuz", "1")

# Then
assert len(lines) == 1
assert len(lines) == 2
assert isinstance(lines[0], Line)
32 changes: 8 additions & 24 deletions tests/client/apis/public_transportation_apis/test_network_apis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pytest

from unittest.mock import MagicMock, patch
Expand All @@ -19,18 +20,9 @@ def test_list_entity_collection_from_region(
) -> None:
# Given
mock_response = MagicMock()
mock_response.json.return_value = {
"networks": [
{"id": "network:foo", "links": [], "name": "Foo"},
{"id": "network:bar", "links": [], "name": "Bar"},
],
"pagination": {
"items_on_page": 25,
"items_per_page": 25,
"start_page": 0,
"total_result": 99,
},
}
with open("tests/test_data/network.json", encoding="utf-8") as file:
mock_response.json.return_value = json.load(file)

mock_get_navitia_api.return_value = mock_response

# When
Expand All @@ -47,22 +39,14 @@ def test_get_entity_by_id(
) -> None:
# Given
mock_response = MagicMock()
mock_response.json.return_value = {
"networks": [
{"id": "network:foo", "links": [], "name": "Foo"},
],
"pagination": {
"items_on_page": 25,
"items_per_page": 25,
"start_page": 0,
"total_result": 99,
},
}
with open("tests/test_data/network.json", encoding="utf-8") as file:
mock_response.json.return_value = json.load(file)

mock_get_navitia_api.return_value = mock_response

# When
networks, _ = network_apis.get_entity_by_id("tuz", "1")

# Then
assert len(networks) == 1
assert len(networks) == 2
assert isinstance(networks[0], Network)
Loading

0 comments on commit 585b130

Please sign in to comment.