Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 Remove hypothesis testing #512

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ moto==1.3.10
pycodestyle==2.5.0
pytest-codestyle==1.4.0
pytest-mock==1.10.4
hypothesis==4.32.3
pytest-cov==2.8.1
-e git+https://github.com/codecov/codecov-python.git@4ec70db255cc2dc332fbd01aab3069d9b2e699dc#egg=codecov
34 changes: 14 additions & 20 deletions tests/studies/test_create_study.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from hypothesis import given, settings
from hypothesis.strategies import text, integers, characters, dates
from datetime import datetime
from graphql_relay import to_global_id
from django.contrib.auth import get_user_model

Expand Down Expand Up @@ -323,8 +322,6 @@ def test_workflows(db, settings, mocker, clients, mock_post):
)


@given(s=text(alphabet=characters(blacklist_categories=("Cc", "Cs"))))
@settings(max_examples=10)
@pytest.mark.parametrize(
"field",
[
Expand All @@ -339,7 +336,7 @@ def test_workflows(db, settings, mocker, clients, mock_post):
"awardeeOrganization",
],
)
def test_text_fields(db, clients, settings, mock_post, s, field):
def test_text_fields(db, clients, settings, mock_post, field):
"""
Test text inputs for different fields
"""
Expand All @@ -348,7 +345,7 @@ def test_text_fields(db, clients, settings, mock_post, s, field):
settings.FEAT_CAVATICA_CREATE_PROJECTS = False

variables = {"input": {"externalId": "TEST"}}
variables["input"][field] = s
variables["input"][field] = "Lorem Ipsum"
resp = client.post(
"/graphql",
content_type="application/json",
Expand All @@ -358,10 +355,8 @@ def test_text_fields(db, clients, settings, mock_post, s, field):
assert "errors" not in resp.json()


@given(s=integers(min_value=0, max_value=2_147_483_647))
@settings(max_examples=10)
@pytest.mark.parametrize("field", ["anticipatedSamples"])
def test_integer_fields(db, clients, settings, mock_post, s, field):
def test_integer_fields(db, clients, settings, mock_post, field):
"""
Test positive integer inputs for different fields
"""
Expand All @@ -370,7 +365,7 @@ def test_integer_fields(db, clients, settings, mock_post, s, field):
settings.FEAT_CAVATICA_CREATE_PROJECTS = False

variables = {"input": {"externalId": "TEST"}}
variables["input"][field] = s
variables["input"][field] = 324
resp = client.post(
"/graphql",
content_type="application/json",
Expand All @@ -380,10 +375,8 @@ def test_integer_fields(db, clients, settings, mock_post, s, field):
assert "errors" not in resp.json()


@given(s=text(alphabet=characters(blacklist_categories=("Cc", "Cs"))))
@settings(max_examples=10)
@pytest.mark.parametrize("field", ["description", "awardeeOrganization"])
def test_internal_fields(db, clients, settings, mock_post, s, field):
def test_internal_fields(db, clients, settings, mock_post, field):
"""
Test that inputs for our internal study fields are saved correctly.

Expand All @@ -394,20 +387,18 @@ def test_internal_fields(db, clients, settings, mock_post, s, field):
settings.FEAT_CAVATICA_CREATE_PROJECTS = False

variables = {"input": {"externalId": "TEST"}}
variables["input"][field] = s
variables["input"][field] = "Lorem Ipsum"
resp = client.post(
"/graphql",
content_type="application/json",
data={"query": CREATE_STUDY_MUTATION, "variables": variables},
)
assert "errors" not in resp.json()
assert resp.json()["data"]["createStudy"]["study"][field] == s
assert resp.json()["data"]["createStudy"]["study"][field] == "Lorem Ipsum"


@given(s=dates())
@settings(max_examples=10)
@pytest.mark.parametrize("field", ["releaseDate"])
def test_internal_datetime_fields(db, clients, settings, mock_post, s, field):
def test_internal_datetime_fields(db, clients, settings, mock_post, field):
"""
Test that inputs datetime study fields are saved correctly.
"""
Expand All @@ -416,14 +407,17 @@ def test_internal_datetime_fields(db, clients, settings, mock_post, s, field):
settings.FEAT_CAVATICA_CREATE_PROJECTS = False

variables = {"input": {"externalId": "TEST"}}
variables["input"][field] = s
d = datetime.now()
variables["input"][field] = d.strftime("%Y-%m-%d")
resp = client.post(
"/graphql",
content_type="application/json",
data={"query": CREATE_STUDY_MUTATION, "variables": variables},
)
assert "errors" not in resp.json()
assert resp.json()["data"]["createStudy"]["study"][field] == str(s)
assert resp.json()["data"]["createStudy"]["study"][field] == str(
d.strftime("%Y-%m-%d")
)


def test_attach_volumes(db, clients, settings, mock_cavatica_api):
Expand Down
38 changes: 14 additions & 24 deletions tests/studies/test_update_study.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from hypothesis import given, settings
from hypothesis.strategies import text, integers, characters, dates
from datetime import datetime
from graphql_relay import to_global_id

from creator.files.models import Study
Expand Down Expand Up @@ -203,8 +202,6 @@ def test_dataservice_error(db, clients, mock_error, mock_study):
assert resp_message.startswith("Problem updating study:")


@given(s=text(alphabet=characters(blacklist_categories=("Cc", "Cs"))))
@settings(max_examples=10)
@pytest.mark.parametrize(
"field",
[
Expand All @@ -218,7 +215,7 @@ def test_dataservice_error(db, clients, mock_error, mock_study):
"description",
],
)
def test_text_fields(db, clients, settings, mock_patch, mock_study, s, field):
def test_text_fields(db, clients, settings, mock_patch, mock_study, field):
"""
Test that text fields may be updated
"""
Expand All @@ -227,7 +224,7 @@ def test_text_fields(db, clients, settings, mock_patch, mock_study, s, field):
"id": to_global_id("StudyNode", mock_study.kf_id),
"input": {},
}
variables["input"][field] = s
variables["input"][field] = "Lorem Ipsum"
resp = client.post(
"/graphql",
content_type="application/json",
Expand All @@ -237,12 +234,8 @@ def test_text_fields(db, clients, settings, mock_patch, mock_study, s, field):
assert "errors" not in resp.json()


@given(s=integers(min_value=0, max_value=2_147_483_647))
@settings(max_examples=10)
@pytest.mark.parametrize("field", ["anticipatedSamples"])
def test_integer_fields(
db, clients, settings, mock_patch, mock_study, s, field
):
def test_integer_fields(db, clients, settings, mock_patch, mock_study, field):
"""
Test that integer fields may be updated
"""
Expand All @@ -251,7 +244,7 @@ def test_integer_fields(
"id": to_global_id("StudyNode", mock_study.kf_id),
"input": {},
}
variables["input"][field] = s
variables["input"][field] = 232
resp = client.post(
"/graphql",
content_type="application/json",
Expand All @@ -261,10 +254,8 @@ def test_integer_fields(
assert "errors" not in resp.json()


@given(s=text(alphabet=characters(blacklist_categories=("Cc", "Cs"))))
@settings(max_examples=10)
@pytest.mark.parametrize("field", ["description", "awardeeOrganization"])
def test_internal_fields(db, clients, mock_patch, mock_study, s, field):
def test_internal_fields(db, clients, mock_patch, mock_study, field):
"""
Test that inputs for our internal study fields are updated correctly.
"""
Expand All @@ -273,22 +264,18 @@ def test_internal_fields(db, clients, mock_patch, mock_study, s, field):
"id": to_global_id("StudyNode", mock_study.kf_id),
"input": {},
}
variables["input"][field] = s
variables["input"][field] = "Lorem Ipsum"
resp = client.post(
"/graphql",
content_type="application/json",
data={"query": UPDATE_STUDY_MUTATION, "variables": variables},
)
assert "errors" not in resp.json()
assert resp.json()["data"]["updateStudy"]["study"][field] == s
assert resp.json()["data"]["updateStudy"]["study"][field] == "Lorem Ipsum"


@given(s=dates())
@settings(max_examples=10)
@pytest.mark.parametrize("field", ["releaseDate"])
def test_internal_datetime_fields(
db, clients, mock_patch, mock_study, s, field
):
def test_internal_datetime_fields(db, clients, mock_patch, mock_study, field):
"""
Test that inputs for study datetime fields are updated correctly.
"""
Expand All @@ -297,14 +284,17 @@ def test_internal_datetime_fields(
"id": to_global_id("StudyNode", mock_study.kf_id),
"input": {},
}
variables["input"][field] = s
d = datetime.now()
variables["input"][field] = d.strftime("%Y-%m-%d")
resp = client.post(
"/graphql",
content_type="application/json",
data={"query": UPDATE_STUDY_MUTATION, "variables": variables},
)
assert "errors" not in resp.json()
assert resp.json()["data"]["updateStudy"]["study"][field] == str(s)
assert resp.json()["data"]["updateStudy"]["study"][field] == str(
d.strftime("%Y-%m-%d")
)


def test_update_study_collaborators_not_mutable(
Expand Down