Skip to content

Commit

Permalink
Update fakes for data model changes
Browse files Browse the repository at this point in the history
  • Loading branch information
naglepuff committed Aug 30, 2023
1 parent 9d6c73d commit 9571448
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions nmdc_server/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def uuid(self):
return uuid4()


class EnumProvider(BaseProvider):
def enum_value(self, enum_class):
enum_values = list(enum_class)
return self.random_element(enum_values)


db = scoped_session(SessionLocal)
Faker.add_provider(DoiProvider)
Faker.add_provider(date_time)
Expand All @@ -33,6 +39,7 @@ def uuid(self):
Faker.add_provider(misc)
Faker.add_provider(person)
Faker.add_provider(python)
Faker.add_provider(EnumProvider)


class TokenFactory(Factory):
Expand All @@ -56,6 +63,7 @@ class Meta:

id = Faker("doi")
info = Faker("pydict", value_types=["str"])
doi_type = Faker("enum_value", enum_class=models.DOIType)


class AnnotatedFactory(SQLAlchemyModelFactory):
Expand All @@ -78,15 +86,6 @@ class Meta:
sqlalchemy_session = db


class PublicationFactory(SQLAlchemyModelFactory):
id = Faker("uuid")
doi_object = SubFactory(DOIInfoFactory)

class Meta:
model = models.Publication
sqlalchemy_session = db


class EnvoTermFactory(SQLAlchemyModelFactory):
id = Faker("pystr")
label = Faker("word")
Expand Down Expand Up @@ -130,8 +129,8 @@ class StudyFactory(AnnotatedFactory):
gold_description = Faker("sentence")
scientific_objective = Faker("sentence")
principal_investigator = SubFactory(PrincipalInvestigator)
doi_object = SubFactory(DOIInfoFactory)
image = Faker("binary", length=64)
dois: List[models.DOIInfo] = []

class Meta:
model = models.Study
Expand All @@ -148,17 +147,6 @@ def principal_investigator_websites(self, create, extracted, **kwargs):
for website in extracted:
self.principal_investigator_websites.append(website)

@post_generation
def publication_dois(self, create, extracted, **kwargs):
if not create:
return

if not extracted:
extracted = [StudyPublicationFactory(), StudyPublicationFactory()]

for publication in extracted:
self.publication_dois.append(publication)


class StudyWebsiteFactory(SQLAlchemyModelFactory):
website = SubFactory(WebsiteFactory)
Expand All @@ -168,14 +156,6 @@ class Meta:
sqlalchemy_session = db


class StudyPublicationFactory(SQLAlchemyModelFactory):
publication = SubFactory(PublicationFactory)

class Meta:
model = models.StudyPublication
sqlalchemy_session = db


class BiosampleFactory(AnnotatedFactory):
class Meta:
model = models.Biosample
Expand Down

0 comments on commit 9571448

Please sign in to comment.