diff --git a/hypha/apply/activity/tests/factories.py b/hypha/apply/activity/tests/factories.py index 6f98839cee..3eb78d6b60 100644 --- a/hypha/apply/activity/tests/factories.py +++ b/hypha/apply/activity/tests/factories.py @@ -18,6 +18,7 @@ class ActivityFactory(factory.django.DjangoModelFactory): class Meta: model = Activity + skip_postgeneration_save = True class Params: internal = factory.Trait(visibility=TEAM) @@ -38,6 +39,7 @@ def _get_manager(cls, model_class): class EventFactory(factory.django.DjangoModelFactory): class Meta: model = Event + skip_postgeneration_save = True type = factory.Iterator([choice[0] for choice in MESSAGES.choices]) by = factory.SubFactory(UserFactory) @@ -47,6 +49,7 @@ class Meta: class MessageFactory(factory.django.DjangoModelFactory): class Meta: model = Message + skip_postgeneration_save = True type = "Email" content = factory.Faker("sentence") diff --git a/hypha/apply/categories/tests/factories.py b/hypha/apply/categories/tests/factories.py index 2b380422cc..a48537eeb1 100644 --- a/hypha/apply/categories/tests/factories.py +++ b/hypha/apply/categories/tests/factories.py @@ -6,6 +6,7 @@ class CategoryFactory(factory.django.DjangoModelFactory): class Meta: model = Category + skip_postgeneration_save = True name = factory.Faker("word") help_text = factory.Faker("sentence") @@ -14,6 +15,7 @@ class Meta: class OptionFactory(factory.django.DjangoModelFactory): class Meta: model = Option + skip_postgeneration_save = True value = factory.Faker("word") category = factory.SubFactory(CategoryFactory) diff --git a/hypha/apply/determinations/tests/factories.py b/hypha/apply/determinations/tests/factories.py index 7529199565..7d166ea5e8 100644 --- a/hypha/apply/determinations/tests/factories.py +++ b/hypha/apply/determinations/tests/factories.py @@ -39,6 +39,7 @@ def _build(cls, model_class, *args, **kwargs): class DeterminationFactory(factory.django.DjangoModelFactory): class Meta: model = Determination + skip_postgeneration_save = True class Params: accepted = factory.Trait(outcome=ACCEPTED) @@ -94,6 +95,7 @@ class Meta: class DeterminationFormFactory(factory.django.DjangoModelFactory): class Meta: model = DeterminationForm + skip_postgeneration_save = True name = factory.Faker("word") form_fields = DeterminationFormFieldsFactory diff --git a/hypha/apply/funds/tests/factories/models.py b/hypha/apply/funds/tests/factories/models.py index 338bc2f997..d8ef89d29e 100644 --- a/hypha/apply/funds/tests/factories/models.py +++ b/hypha/apply/funds/tests/factories/models.py @@ -77,6 +77,7 @@ def workflow_for_stages(stages): class AbstractApplicationFactory(wagtail_factories.PageFactory): class Meta: abstract = True + skip_postgeneration_save = True class Params: workflow_stages = 1 @@ -103,6 +104,7 @@ def forms(self, create, extracted, **kwargs): application=self, **kwargs, ) + self.save() class FundTypeFactory(AbstractApplicationFactory): @@ -118,6 +120,7 @@ class Meta: class AbstractRelatedFormFactory(factory.django.DjangoModelFactory): class Meta: abstract = True + skip_postgeneration_save = True form = factory.SubFactory( "hypha.apply.funds.tests.factories.ApplicationFormFactory" @@ -134,6 +137,7 @@ class Meta: class ApplicationFormFactory(factory.django.DjangoModelFactory): class Meta: model = ApplicationForm + skip_postgeneration_save = True name = factory.Faker("word") form_fields = blocks.CustomFormFieldsFactory @@ -142,6 +146,7 @@ class Meta: class RoundFactory(wagtail_factories.PageFactory): class Meta: model = Round + skip_postgeneration_save = True class Params: now = factory.Trait( @@ -183,6 +188,7 @@ def forms(self, create, extracted, **kwargs): round=self, **kwargs, ) + self.save() class SealedRoundFactory(RoundFactory): @@ -224,6 +230,7 @@ def forms(self, create, extracted, **kwargs): lab=self, **kwargs, ) + self.save() class LabBaseFormFactory(AbstractRelatedFormFactory): @@ -240,6 +247,7 @@ class ApplicationFormDataFactory(FormDataFactory): class ApplicationSubmissionFactory(factory.django.DjangoModelFactory): class Meta: model = ApplicationSubmission + skip_postgeneration_save = True class Params: workflow_stages = 1 @@ -277,11 +285,13 @@ def reviewers(self, create, reviewers, **kwargs): reviewer=reviewer, submission=self, ) + self.save() class ReviewerRoleFactory(factory.django.DjangoModelFactory): class Meta: model = ReviewerRole + skip_postgeneration_save = True name = factory.Faker("word") order = factory.Sequence(lambda n: n) @@ -290,6 +300,7 @@ class Meta: class AssignedReviewersFactory(factory.django.DjangoModelFactory): class Meta: model = AssignedReviewers + skip_postgeneration_save = True django_get_or_create = ("submission", "reviewer") class Params: @@ -342,6 +353,7 @@ class LabSubmissionFactory(ApplicationSubmissionFactory): class ApplicationRevisionFactory(factory.django.DjangoModelFactory): class Meta: model = ApplicationRevision + skip_postgeneration_save = True submission = factory.SubFactory( "hypha.apply.funds.tests.factories.ApplicationSubmissionFactory" @@ -353,10 +365,16 @@ class Meta: clean=True, ) + @factory.post_generation + def post(instance: ApplicationRevision, create: bool, extracted, **kwargs): + if create: + instance.save() + class AbstractReviewFormFactory(factory.django.DjangoModelFactory): class Meta: abstract = True + skip_postgeneration_save = True form = factory.SubFactory("hypha.apply.review.tests.factories.ReviewFormFactory") @@ -385,6 +403,7 @@ class Meta: class ScreeningStatusFactory(factory.django.DjangoModelFactory): class Meta: model = ScreeningStatus + skip_postgeneration_save = True title = factory.Iterator(["Bad", "Good"]) yes = factory.Iterator([True, False]) @@ -393,6 +412,7 @@ class Meta: class ReminderFactory(factory.django.DjangoModelFactory): class Meta: model = Reminder + skip_postgeneration_save = True submission = factory.SubFactory( "hypha.apply.funds.tests.factories.ApplicationSubmissionFactory" diff --git a/hypha/apply/projects/reports/tests/factories.py b/hypha/apply/projects/reports/tests/factories.py index c215d3fb9f..9c9e043f15 100644 --- a/hypha/apply/projects/reports/tests/factories.py +++ b/hypha/apply/projects/reports/tests/factories.py @@ -18,6 +18,7 @@ class ReportConfigFactory(factory.django.DjangoModelFactory): class Meta: model = ReportConfig + skip_postgeneration_save = True django_get_or_create = ("project",) class Params: @@ -43,6 +44,7 @@ class ReportVersionFactory(factory.django.DjangoModelFactory): class Meta: model = ReportVersion + skip_postgeneration_save = True @factory.post_generation def relate(obj, create, should_relate, **kwargs): @@ -56,6 +58,7 @@ def relate(obj, create, should_relate, **kwargs): obj.report.current = obj obj.report.submitted = obj.submitted obj.report.save() + obj.save() class ReportFactory(factory.django.DjangoModelFactory): @@ -72,6 +75,7 @@ class ReportFactory(factory.django.DjangoModelFactory): class Meta: model = Report + skip_postgeneration_save = True class Params: past_due = factory.Trait( diff --git a/hypha/apply/projects/tests/factories.py b/hypha/apply/projects/tests/factories.py index b78e15c681..9a90c41da7 100644 --- a/hypha/apply/projects/tests/factories.py +++ b/hypha/apply/projects/tests/factories.py @@ -61,11 +61,13 @@ class DocumentCategoryFactory(factory.django.DjangoModelFactory): class Meta: model = DocumentCategory + skip_postgeneration_save = True class ProjectFormFactory(factory.django.DjangoModelFactory): class Meta: model = ProjectForm + skip_postgeneration_save = True name = factory.Faker("word") form_fields = FormFieldsBlockFactory @@ -74,6 +76,7 @@ class Meta: class ProjectSOWFormFactory(factory.django.DjangoModelFactory): class Meta: model = ProjectSOWForm + skip_postgeneration_save = True name = factory.Faker("word") form_fields = FormFieldsBlockFactory @@ -86,6 +89,7 @@ class ProjectFormDataFactory(FormDataFactory): class ProjectReportFormFactory(factory.django.DjangoModelFactory): class Meta: model = ProjectReportForm + skip_postgeneration_save = True name = factory.Faker("word") form_fields = FormFieldsBlockFactory @@ -111,6 +115,7 @@ class ProjectFactory(factory.django.DjangoModelFactory): class Meta: model = Project + skip_postgeneration_save = True class Params: in_approval = factory.Trait( @@ -129,6 +134,7 @@ class PAFReviewerRoleFactory(factory.django.DjangoModelFactory): class Meta: model = PAFReviewersRole + skip_postgeneration_save = True @factory.post_generation def user_roles(self, create, extracted, **kwargs): @@ -137,6 +143,7 @@ def user_roles(self, create, extracted, **kwargs): GroupFactory(name=STAFF_GROUP_NAME), GroupFactory(name=APPROVER_GROUP_NAME), ) + self.save() class PAFApprovalsFactory(factory.django.DjangoModelFactory): @@ -146,6 +153,7 @@ class PAFApprovalsFactory(factory.django.DjangoModelFactory): class Meta: model = PAFApprovals + skip_postgeneration_save = True class ContractFactory(factory.django.DjangoModelFactory): @@ -158,6 +166,7 @@ class ContractFactory(factory.django.DjangoModelFactory): class Meta: model = Contract + skip_postgeneration_save = True class PacketFileFactory(factory.django.DjangoModelFactory): @@ -169,6 +178,7 @@ class PacketFileFactory(factory.django.DjangoModelFactory): class Meta: model = PacketFile + skip_postgeneration_save = True class InvoiceFactory(factory.django.DjangoModelFactory): @@ -181,6 +191,7 @@ class InvoiceFactory(factory.django.DjangoModelFactory): class Meta: model = Invoice + skip_postgeneration_save = True class SupportingDocumentFactory(factory.django.DjangoModelFactory): @@ -190,6 +201,7 @@ class SupportingDocumentFactory(factory.django.DjangoModelFactory): class Meta: model = SupportingDocument + skip_postgeneration_save = True class ApprovedProjectFactory(ProjectFactory): diff --git a/hypha/apply/review/tests/factories/models.py b/hypha/apply/review/tests/factories/models.py index a56a999118..72b3f1d9d5 100644 --- a/hypha/apply/review/tests/factories/models.py +++ b/hypha/apply/review/tests/factories/models.py @@ -20,6 +20,7 @@ class ReviewFormDataFactory(FormDataFactory): class ReviewFactory(factory.django.DjangoModelFactory): class Meta: model = Review + skip_postgeneration_save = True class Params: recommendation_yes = factory.Trait(recommendation=YES) @@ -48,6 +49,7 @@ class Params: class ReviewOpinionFactory(factory.django.DjangoModelFactory): class Meta: model = ReviewOpinion + skip_postgeneration_save = True class Params: opinion_agree = factory.Trait(opinion=AGREE) @@ -65,6 +67,7 @@ class Params: class ReviewFormFactory(factory.django.DjangoModelFactory): class Meta: model = ReviewForm + skip_postgeneration_save = True name = factory.Faker("word") form_fields = blocks.ReviewFormFieldsFactory diff --git a/hypha/apply/users/tests/factories.py b/hypha/apply/users/tests/factories.py index 8d151275f6..33cfa8828c 100644 --- a/hypha/apply/users/tests/factories.py +++ b/hypha/apply/users/tests/factories.py @@ -20,6 +20,7 @@ class GroupFactory(factory.django.DjangoModelFactory): class Meta: model = Group + skip_postgeneration_save = True django_get_or_create = ("name",) name = factory.Sequence("group name {}".format) @@ -28,6 +29,7 @@ class Meta: class UserFactory(factory.django.DjangoModelFactory): class Meta: model = get_user_model() + skip_postgeneration_save = True email = factory.LazyAttribute( lambda o: "{}+{}@email.com".format(slugify(o.full_name), uuid.uuid4()) @@ -44,11 +46,17 @@ def groups(self, create, extracted, **kwargs): groups = extracted self.groups.add(groups) + self.save() class OAuthUserFactory(UserFactory): password = factory.PostGenerationMethodCall("set_unusable_password") + @factory.post_generation + def post(self, create, extracted, **kwargs): + if create: + self.save() + class AdminFactory(UserFactory): is_superuser = True @@ -69,6 +77,7 @@ class Meta: def groups(self, create, extracted, **kwargs): if create: self.groups.add(GroupFactory(name=STAFF_GROUP_NAME)) + self.save() def get_wagtail_admin_access_permission(): @@ -85,6 +94,7 @@ def groups(self, create, extracted, **kwargs): wagtail_admin_access_permission = get_wagtail_admin_access_permission() modifiedStaffGroup.permissions.add(wagtail_admin_access_permission) self.groups.add(modifiedStaffGroup) + self.save() class StaffWithoutWagtailAdminAccessFactory(StaffFactory): @@ -95,6 +105,7 @@ def groups(self, create, extracted, **kwargs): wagtail_admin_access_permission = get_wagtail_admin_access_permission() modifiedStaffGroup.permissions.remove(wagtail_admin_access_permission) self.groups.add(modifiedStaffGroup) + self.save() class FinanceFactory(OAuthUserFactory): @@ -112,6 +123,7 @@ class Meta: def groups(self, create, extracted, **kwargs): if create: self.groups.add(GroupFactory(name=FINANCE_GROUP_NAME)) + self.save() class ApproverFactory(StaffFactory): @@ -122,6 +134,7 @@ def groups(self, create, extracted, **kwargs): GroupFactory(name=STAFF_GROUP_NAME), GroupFactory(name=APPROVER_GROUP_NAME), ) + self.save() class ContractingFactory(UserFactory): @@ -131,6 +144,7 @@ def groups(self, create, extracted, **kwargs): self.groups.add( GroupFactory(name=CONTRACTING_GROUP_NAME), ) + self.save() class ContractingApproverFactory(UserFactory): @@ -141,6 +155,7 @@ def groups(self, create, extracted, **kwargs): GroupFactory(name=CONTRACTING_GROUP_NAME), GroupFactory(name=APPROVER_GROUP_NAME), ) + self.save() class SuperUserFactory(StaffFactory): @@ -152,6 +167,7 @@ class ReviewerFactory(UserFactory): def groups(self, create, extracted, **kwargs): if create: self.groups.add(GroupFactory(name=REVIEWER_GROUP_NAME)) + self.save() class ApplicantFactory(UserFactory): @@ -159,6 +175,7 @@ class ApplicantFactory(UserFactory): def groups(self, create, extracted, **kwargs): if create: self.groups.add(GroupFactory(name=APPLICANT_GROUP_NAME)) + self.save() class CommunityReviewerFactory(UserFactory): @@ -166,6 +183,7 @@ class CommunityReviewerFactory(UserFactory): def groups(self, create, extracted, **kwargs): if create: self.groups.add(GroupFactory(name=COMMUNITY_REVIEWER_GROUP_NAME)) + self.save() class PartnerFactory(UserFactory): @@ -173,3 +191,4 @@ class PartnerFactory(UserFactory): def groups(self, create, extracted, **kwargs): if create: self.groups.add(GroupFactory(name=PARTNER_GROUP_NAME)) + self.save() diff --git a/pyproject.toml b/pyproject.toml index fc4d2dacdc..89b2e70e09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,10 +120,6 @@ DJANGO_SETTINGS_MODULE = 'hypha.settings.test' addopts = ['-n=auto', '--failed-first'] python_files = ['tests.py', 'test_*.py', '*_tests.py'] testpaths = ["hypha"] -filterwarnings = [ - 'ignore::DeprecationWarning', - 'ignore::PendingDeprecationWarning', -] [tool.coverage.run] parallel = true