Skip to content

Commit 3f62016

Browse files
authored
split query params on "," rather than aggregate list and adjust tests (#59)
1 parent 81a0d89 commit 3f62016

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/schema_api/views.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ def retrieve(self, request, name):
4949
dataset_schema = dataset.schema
5050

5151
# Table filtering
52-
tables_param = request.query_params.getlist("tables")
52+
tables_param = request.query_params.get("tables")
5353
if tables_param:
54-
dataset_schema = DatasetSchema.filter_on_tables(dataset_schema, tables_param)
54+
tables = tables_param.split(",")
55+
dataset_schema = DatasetSchema.filter_on_tables(dataset_schema, tables)
5556

5657
# Scope filtering
57-
scopes_param = request.query_params.getlist("scopes")
58+
scopes_param = request.query_params.get("scopes")
5859
if scopes_param:
59-
6060
# Transform url safe scope ids to regular ids
61-
scopes = [scope.replace("_", "/").upper() for scope in scopes_param]
61+
scopes = [scope.replace("_", "/").upper() for scope in scopes_param.split(",")]
6262
dataset_schema = DatasetSchema.filter_on_scopes(dataset_schema, scopes)
6363

6464
return Response(dataset_schema)
@@ -71,16 +71,17 @@ def version(self, request, name, vmajor):
7171
dataset_schema = dataset.schema
7272

7373
# Table filtering
74-
tables_param = request.query_params.getlist("tables")
74+
tables_param = request.query_params.get("tables")
7575
if tables_param:
76-
dataset_schema = DatasetSchema.filter_on_tables(dataset_schema, tables_param)
76+
tables = tables_param.split(",")
77+
dataset_schema = DatasetSchema.filter_on_tables(dataset_schema, tables)
7778

7879
# Scope filtering
79-
scopes_param = request.query_params.getlist("scopes")
80+
scopes_param = request.query_params.get("scopes")
8081
if scopes_param:
8182

8283
# Transform url safe scope ids to regular ids
83-
scopes = [scope.replace("_", "/").upper() for scope in scopes_param]
84+
scopes = [scope.replace("_", "/").upper() for scope in scopes_param.split(",")]
8485
dataset_schema = DatasetSchema.filter_on_scopes(dataset_schema, scopes)
8586

8687
try:
@@ -98,11 +99,11 @@ def table(self, request, name, vmajor, table_id):
9899
dataset_schema = dataset.schema
99100

100101
# Scope filtering
101-
scopes_param = request.query_params.getlist("scopes")
102+
scopes_param = request.query_params.get("scopes")
102103
if scopes_param:
103104

104105
# Transform url safe scope ids to regular ids
105-
scopes = [scope.replace("_", "/").upper() for scope in scopes_param]
106+
scopes = [scope.replace("_", "/").upper() for scope in scopes_param.split(",")]
106107
dataset_schema = DatasetSchema.filter_on_scopes(dataset_schema, scopes)
107108

108109
try:

src/tests/test_views.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_dataset_detail_filter_on_tables(self, client, gebieden_dataset):
3434
reverse(
3535
"dataset-detail",
3636
kwargs={"name": "gebieden"},
37-
query={"tables": ["bouwblokken", "buurten", "wijken"]},
37+
query={"tables": "bouwblokken,buurten,wijken"},
3838
),
3939
)
4040
assert response.status_code == 200
@@ -46,7 +46,7 @@ def test_dataset_detail_filter_on_tables_ignores_non_existent(self, client, gebi
4646
reverse(
4747
"dataset-detail",
4848
kwargs={"name": "gebieden"},
49-
query={"tables": ["bouwblokken", "buurten", "wijken", "huisnummerplaten"]},
49+
query={"tables": "bouwblokken,buurten,wijken,huisnummerplaten"},
5050
),
5151
)
5252
assert response.status_code == 200
@@ -65,7 +65,7 @@ def test_dataset_version_filter_on_tables(self, client, gebieden_dataset):
6565
reverse(
6666
"dataset-version",
6767
kwargs={"name": "gebieden", "vmajor": "v1"},
68-
query={"tables": ["bouwblokken", "buurten", "wijken"]},
68+
query={"tables": "bouwblokken,buurten,wijken"},
6969
),
7070
)
7171
assert response.status_code == 200
@@ -140,12 +140,13 @@ def test_dataset_multiple_scope_access(self, client, bomen_dataset, scope_fixtur
140140
"name": "bomen",
141141
},
142142
query={
143-
"scopes": ["openbaar", "fp_mdw"],
143+
"scopes": "openbaar,fp_mdw",
144144
},
145145
),
146146
)
147147
assert response.status_code == 200
148-
assert response.data["versions"]["v1"]["tables"][0]["schema"]["properties"]
148+
fields = set(response.data["versions"]["v1"]["tables"][0]["schema"]["properties"].keys())
149+
assert fields == {"schema", "id", "groeiplaatsBoom", "guid", "begindatum"}
149150

150151
def test_dataset_scope_version_access(self, client, bomen_dataset, scope_fixture):
151152
response = client.get(

0 commit comments

Comments
 (0)