-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from OpenDataServices/476-bad-duplicate-ids
[#476] Don't 500 error on duplicate IDs with unexpected types
- Loading branch information
Showing
4 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from cove.lib.ocds import get_releases_aggregates | ||
from cove.lib.threesixtygiving import get_grants_aggregates | ||
from hypothesis import given, assume, strategies as st, example, settings | ||
from cove.input.models import SuppliedData | ||
from django.core.files.base import ContentFile | ||
import pytest | ||
import json | ||
|
||
|
||
""" | ||
## Suggested testing patterns (from CamPUG talk) | ||
* simple fuzzing | ||
* round trip | ||
* invariants and idempotents | ||
* test oracle | ||
""" | ||
|
||
general_json = st.recursive(st.floats() | st.integers() | st.booleans() | st.text() | st.none(), | ||
lambda children: st.lists(children) | st.dictionaries(st.text(), children)) | ||
|
||
|
||
@pytest.mark.xfail | ||
@given(general_json) | ||
def test_get_grants_aggregates(json_data): | ||
get_grants_aggregates(json_data) | ||
|
||
|
||
@given(general_json) | ||
def test_get_releases_aggregates(json_data): | ||
get_releases_aggregates(json_data) | ||
|
||
|
||
@given(general_json) | ||
def test_get_grants_aggregates_dict(json_data): | ||
assume(type(json_data) is dict) | ||
get_grants_aggregates(json_data) | ||
|
||
|
||
@given(general_json) | ||
def test_get_releases_aggregates_dict(json_data): | ||
assume(type(json_data) is dict) | ||
get_releases_aggregates(json_data) | ||
|
||
|
||
@pytest.mark.xfail | ||
@pytest.mark.django_db | ||
@pytest.mark.parametrize('current_app', ['cove-ocds']) # , 'cove-360']) | ||
@given( | ||
general_json | | ||
st.fixed_dictionaries({'releases': general_json}) | ||
) | ||
def test_explore_page(client, current_app, json_data): | ||
data = SuppliedData.objects.create() | ||
data.original_file.save('test.json', ContentFile(json.dumps(json_data))) | ||
data.current_app = current_app | ||
resp = client.get(data.get_absolute_url()) | ||
assert resp.status_code == 200 | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize('current_app', ['cove-ocds']) # , 'cove-360']) | ||
@given(general_json) | ||
@example(1) | ||
@settings(max_examples=50) | ||
def test_explore_page_duplicate_ids(client, current_app, json_data): | ||
duplicate_id_releases = { | ||
'releases': [ | ||
{'id': json_data}, | ||
{'id': json_data} | ||
] | ||
} | ||
data = SuppliedData.objects.create() | ||
data.original_file.save('test.json', ContentFile(json.dumps(duplicate_id_releases))) | ||
data.current_app = current_app | ||
resp = client.get(data.get_absolute_url()) | ||
assert resp.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ transifex-client | |
libsass | ||
Sphinx | ||
recommonmark | ||
hypothesis | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters