From 21abe9c667aaa193d4facd761b3f2945dcb55a4d Mon Sep 17 00:00:00 2001 From: naglepuff Date: Tue, 29 Aug 2023 17:45:31 -0400 Subject: [PATCH] Update fakes for data model changes --- nmdc_server/fakes.py | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/nmdc_server/fakes.py b/nmdc_server/fakes.py index 22fede1c..2fd6dd4b 100644 --- a/nmdc_server/fakes.py +++ b/nmdc_server/fakes.py @@ -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) @@ -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): @@ -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): @@ -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") @@ -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 @@ -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) @@ -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