Skip to content

Commit

Permalink
Reorganize mandatory filter tests, to use pytest parametrize
Browse files Browse the repository at this point in the history
This makes it easier to expand test conditions, and uncovered some
missing bits (resolved in earlier commits).
  • Loading branch information
vdboor committed Aug 1, 2024
1 parent d752ee5 commit 3396bb6
Show file tree
Hide file tree
Showing 3 changed files with 313 additions and 237 deletions.
Empty file.
185 changes: 185 additions & 0 deletions src/tests/test_dynamic_api/views/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import pytest
from schematools.contrib.django import models
from schematools.types import ProfileSchema


@pytest.fixture
def basic_parkeervak(parkeervakken_parkeervak_model):
return parkeervakken_parkeervak_model.objects.create(
id=1,
type="Langs",
soort="NIET FISCA",
aantal="1.0",
)


@pytest.fixture
def profile1_mandatory():
"""A profile that enforces a particular set of filters"""
return models.Profile.create_for_schema(
ProfileSchema.from_dict(
{
"name": "parkeerwacht-filter1",
"scopes": ["PROFIEL/SCOPE"],
"datasets": {
"parkeervakken": {
"tables": {
"parkeervakken": {
"permissions": "read",
"mandatoryFilterSets": [
["buurtcode", "type"],
["regimes.eindtijd"],
],
}
}
}
},
}
)
)


@pytest.fixture
def profile2_mandatory():
"""A profile that enforces a different set of filters"""
models.Profile.create_for_schema(
ProfileSchema.from_dict(
{
"name": "parkeerwacht-filter2",
"scopes": ["PROFIEL2/SCOPE"],
"datasets": {
"parkeervakken": {
"tables": {
"parkeervakken": {
"permissions": "read",
"mandatoryFilterSets": [
["regimes.aantal[gte]"],
],
}
}
}
},
}
)
)


@pytest.fixture
def profile_limited_soort():
"""A profile that only exposes a field in limited way."""
models.Profile.create_for_schema(
ProfileSchema.from_dict(
{
"name": "parkeerwacht-limited1",
"scopes": ["PROFIEL/SCOPE"],
"datasets": {
"parkeervakken": {
"tables": {
"parkeervakken": {
"mandatoryFilterSets": [
["id"],
],
"fields": {
"type": "read",
"soort": "letters:1",
},
}
}
}
},
}
)
)


@pytest.fixture
def profile_limited_type():
"""A profile that only exposes a field in limited way."""
return models.Profile.create_for_schema(
ProfileSchema.from_dict(
{
"name": "parkeerwacht-limited2",
"scopes": ["PROFIEL2/SCOPE"],
"datasets": {
"parkeervakken": {
"tables": {
"parkeervakken": {
"mandatoryFilterSets": [
["id", "type"],
],
"fields": {
"type": "letters:1",
"soort": "read",
},
}
}
}
},
}
)
)


@pytest.fixture
def profiles_may():
models.Profile.create_for_schema(
ProfileSchema.from_dict(
{
"name": "mag_niet",
"scopes": ["MAY/NOT"],
"datasets": {
"parkeervakken": {
"tables": {
"parkeervakken": {
"permissions": "read",
"mandatoryFilterSets": [
["buurtcode", "type"],
],
}
}
}
},
}
)
)
models.Profile.create_for_schema(
ProfileSchema.from_dict(
{
"name": "mag_wel",
"scopes": ["MAY/ENTER"],
"datasets": {
"parkeervakken": {
"tables": {
"parkeervakken": {
"permissions": "read",
"mandatoryFilterSets": [
["buurtcode", "type"],
["id"],
],
}
}
}
},
}
)
)
models.Profile.create_for_schema(
ProfileSchema.from_dict(
{
"name": "alleen_volgnummer",
"scopes": ["ONLY/VOLGNUMMER"],
"datasets": {
"parkeervakken": {
"tables": {
"parkeervakken": {
"permissions": "read",
"mandatoryFilterSets": [
["id", "volgnummer"],
],
}
}
}
},
}
)
)
Loading

0 comments on commit 3396bb6

Please sign in to comment.