Skip to content

Commit

Permalink
Set min value in random_int factories
Browse files Browse the repository at this point in the history
Typically we require the min valeu to be 1 in the model definitions,
so set it in the factories.
  • Loading branch information
amstilp committed Jun 21, 2024
1 parent 6c50e46 commit a12e0ab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion primed/cdsa/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Meta:
model = models.AgreementVersion

major_version = SubFactory(AgreementMajorVersionFactory)
minor_version = Faker("random_int")
minor_version = Faker("random_int", min=1)
date_approved = Faker("date")


Expand Down
18 changes: 9 additions & 9 deletions primed/dbgap/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class dbGaPWorkspaceFactory(TimeStampedModelFactory, DjangoModelFactory):

workspace = SubFactory(WorkspaceFactory, workspace_type="dbgap")
dbgap_study_accession = SubFactory(dbGaPStudyAccessionFactory)
dbgap_version = Faker("random_int")
dbgap_participant_set = Faker("random_int")
dbgap_consent_code = Faker("random_int")
dbgap_version = Faker("random_int", min=1)
dbgap_participant_set = Faker("random_int", min=1)
dbgap_consent_code = Faker("random_int", min=1)
dbgap_consent_abbreviation = Faker("word")
data_use_limitations = Faker("paragraph")
acknowledgments = Faker("paragraph")
Expand Down Expand Up @@ -138,11 +138,11 @@ class dbGaPDataAccessRequestFactory(DjangoModelFactory):
"""A factory for the dbGaPApplication model."""

dbgap_data_access_snapshot = SubFactory(dbGaPDataAccessSnapshotFactory)
dbgap_phs = Faker("random_int")
dbgap_phs = Faker("random_int", min=1)
dbgap_dar_id = Sequence(lambda n: n + 1)
original_version = Faker("random_int")
original_participant_set = Faker("random_int")
dbgap_consent_code = Faker("random_int")
original_version = Faker("random_int", min=1)
original_participant_set = Faker("random_int", min=1)
dbgap_consent_code = Faker("random_int", min=1)
dbgap_consent_abbreviation = Faker("word")
dbgap_current_status = models.dbGaPDataAccessRequest.APPROVED
dbgap_dac = Faker("word")
Expand Down Expand Up @@ -172,9 +172,9 @@ class dbGaPJSONRequestFactory(DictFactory):

DAC_abbrev = Faker("word")
consent_abbrev = Faker("word")
consent_code = Faker("random_int")
consent_code = Faker("random_int", min=1)
DAR = Sequence(lambda n: n + 1)
current_version = Faker("random_int")
current_version = Faker("random_int", min=1)
current_DAR_status = FuzzyChoice(
models.dbGaPDataAccessRequest.DBGAP_CURRENT_STATUS_CHOICES,
getter=lambda c: c[0],
Expand Down
2 changes: 1 addition & 1 deletion primed/dbgap/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ def test_unique_dbgap_dar_id(self):
obj = factories.dbGaPDataAccessRequestFactory.create()
instance = factories.dbGaPDataAccessRequestFactory.build(
dbgap_data_access_snapshot=obj.dbgap_data_access_snapshot,
dbgap_phs=fake.random_int(),
dbgap_phs=fake.random_int(min=1),
dbgap_dar_id=obj.dbgap_dar_id,
)
with self.assertRaises(ValidationError) as e:
Expand Down
20 changes: 10 additions & 10 deletions primed/dbgap/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,7 @@ def test_form_class(self):

def test_can_create_object(self):
"""Can create a dbGaPSnapshot and related dbGaPDataAccessRequests for this dbGaPApplication."""
phs = "phs{phs:06d}".format(phs=fake.random_int())
phs = "phs{phs:06d}".format(phs=fake.random_int(min=1))
study_json = factories.dbGaPJSONStudyFactory(study_accession=phs)
project_json = factories.dbGaPJSONProjectFactory(dbgap_application=self.dbgap_application, studies=[study_json])
self.dbgap_response_mock.add(
Expand Down Expand Up @@ -2315,7 +2315,7 @@ def test_can_create_object_and_related_dars(self):
def test_redirect_url(self):
"""Redirects to successful url."""
# Add responses with the study version and participant_set.
phs = "phs{phs:06d}".format(phs=fake.random_int())
phs = "phs{phs:06d}".format(phs=fake.random_int(min=1))
study_json = factories.dbGaPJSONStudyFactory(study_accession=phs)
project_json = factories.dbGaPJSONProjectFactory(
dbgap_application=self.dbgap_application,
Expand All @@ -2341,7 +2341,7 @@ def test_redirect_url(self):

def test_success_message(self):
"""Redirects to successful url."""
phs = "phs{phs:06d}".format(phs=fake.random_int())
phs = "phs{phs:06d}".format(phs=fake.random_int(min=1))
study_json = factories.dbGaPJSONStudyFactory(study_accession=phs)
project_json = factories.dbGaPJSONProjectFactory(
dbgap_application=self.dbgap_application,
Expand Down Expand Up @@ -2407,7 +2407,7 @@ def test_post_dbgap_application_pk_does_not_exist(self):
self.get_view()(request, dbgap_project_id=self.dbgap_application.pk + 999)

def test_has_form_when_one_snapshot_exists(self):
phs_int = fake.random_int()
phs_int = fake.random_int(min=1)
phs = "phs{phs_int:06d}".format(phs_int=phs_int)
request_json = factories.dbGaPJSONRequestFactory(
DAR=1234,
Expand Down Expand Up @@ -2446,7 +2446,7 @@ def test_has_form_when_one_snapshot_exists(self):

def test_updates_existing_snapshot_is_most_recent(self):
"""Updates the is_most_recent for older snapshots."""
phs_int = fake.random_int()
phs_int = fake.random_int(min=1)
phs = "phs{phs_int:06d}".format(phs_int=phs_int)
request_json = factories.dbGaPJSONRequestFactory(
DAR=1234,
Expand Down Expand Up @@ -2499,7 +2499,7 @@ def test_updates_existing_snapshot_is_most_recent(self):

def test_can_add_a_second_snapshot_with_dars(self):
"""Can add a second snapshot and new DARs."""
phs_int = fake.random_int()
phs_int = fake.random_int(min=1)
phs = "phs{phs_int:06d}".format(phs_int=phs_int)
request_json = factories.dbGaPJSONRequestFactory(
DAR=1234,
Expand Down Expand Up @@ -2616,7 +2616,7 @@ def test_context_includes_dbgap_application(self):

def test_snapshot_not_created_if_http404(self):
"""The dbGaPDataAccessSnapshot is not created if DARs cannot be created due to a HTTP 404 response."""
phs_int = fake.random_int()
phs_int = fake.random_int(min=1)
phs = "phs{phs_int:06d}".format(phs_int=phs_int)
request_json = factories.dbGaPJSONRequestFactory(
DAR=1234,
Expand Down Expand Up @@ -2658,7 +2658,7 @@ def test_snapshot_not_created_if_http404(self):

def test_existing_snapshot_not_updated_http404(self):
"""The dbGaPDataAccessSnapshot is not created if there is an HTTP 404 error."""
phs_int = fake.random_int()
phs_int = fake.random_int(min=1)
phs = "phs{phs_int:06d}".format(phs_int=phs_int)
request_json = factories.dbGaPJSONRequestFactory(
DAR=1234,
Expand Down Expand Up @@ -2702,7 +2702,7 @@ def test_existing_snapshot_not_updated_http404(self):

def test_snapshot_not_created_if_dar_error(self):
"""The dbGaPDataAccessSnapshot is not created if DARs cannot be created due to duplicated DAR id."""
phs = "phs{phs_int:06d}".format(phs_int=fake.random_int())
phs = "phs{phs_int:06d}".format(phs_int=fake.random_int(min=1))
request_json_1 = factories.dbGaPJSONRequestFactory(
DAR=1234,
consent_code=1,
Expand Down Expand Up @@ -2746,7 +2746,7 @@ def test_snapshot_not_created_if_dar_error(self):

def test_existing_snapshot_is_most_recent_with_dar_errors(self):
"""An existing dbGaPDataAccessSnapshot.is_most_recent value is not updated if DARs cannot be created."""
phs = "phs{phs_int:06d}".format(phs_int=fake.random_int())
phs = "phs{phs_int:06d}".format(phs_int=fake.random_int(min=1))
request_json_1 = factories.dbGaPJSONRequestFactory(
DAR=1234,
consent_code=1,
Expand Down

0 comments on commit a12e0ab

Please sign in to comment.