def setUp(self): self.organization = OrganizationFactory() self.included_rps = [] self.not_included_rps = [] for i in range(3): if i % 2 == 0: self.included_rps.append( RevenueProgramFactory(organization=self.organization)) else: self.not_included_rps.append(RevenueProgramFactory()) self.superuser_user = user_model.objects.create_superuser( email="*****@*****.**", password="******") self.hub_admin_user = create_test_user( role_assignment_data={"role_type": Roles.HUB_ADMIN}) self.org_admin_user = create_test_user( role_assignment_data={ "role_type": Roles.ORG_ADMIN, "organization": self.organization }) self.rp_admin_user = create_test_user( role_assignment_data={ "role_type": Roles.RP_ADMIN, "organization": self.organization, "revenue_programs": self.included_rps, }) self.no_role_user = user_model.objects.create( email="*****@*****.**", password="******") self.serializer = serializers.UserSerializer
def setUp(self): self.client = Client() self.mailbox = mail.outbox self.staff_user = user_model.objects.create_superuser( email="*****@*****.**", password="******") organization = OrganizationFactory() self.org_admin_user = create_test_user() self.org_admin_user.organizations.add(organization)
def _create_contribution(self, ref_id=None, **kwargs): org = OrganizationFactory(stripe_account_id="test") return Contribution.objects.create( provider_payment_id=ref_id, amount=1000, status=ContributionStatus.PROCESSING, **kwargs, organization=org)
def setUp(self): self.client = Client() self.mailbox = mail.outbox self.old_password = "******" self.new_password = "******" self.user = create_test_user() self.assertNotEqual(self.old_password, self.new_password) organization = OrganizationFactory() self.user.organizations.add(organization)
def test_get_changes_from_prev_history_obj_wrong_type(db): """ Passing the wrong type of object to get_changes_from_prev_history_obj() raises an error. The get_changes_from_prev_history_obj() function expects its only argument to be an instance of one of the 'historial' models that django_simple_history creates. """ organization = OrganizationFactory() with pytest.raises(AttributeError): get_changes_from_prev_history_obj(organization)
def setUp(self): self.organization = OrganizationFactory() self.model = Organization self.app_label = "organizations" self.model_name = "organization" self.change = RevEngineHistoricalChangeFactory( app_label=self.app_label, model=self.model_name, object_id=self.organization.pk, )
def setUp(self): self.url = reverse("admin:users_roleassignment_add") self.user = get_user_model().objects.create_user( email="*****@*****.**", password="******") self.organization = OrganizationFactory() for _ in range(3): RevenueProgramFactory(org=self.organization) self.rp_qs = RevenueProgram.objects.all() self.form = None
def test_get_changes_from_prev_history_obj_change_no_diff(db): """A historical change to update an object with no changes returns no changes.""" # Create an Organization. organization = OrganizationFactory() historial_change_create = organization.history.first() # Save the Organization, but don't change any of the values. organization.save() historical_change_update = organization.history.exclude( history_id=historial_change_create.history_id).first() # The changes from the update should equal []. assert get_changes_from_prev_history_obj(historical_change_update) == []
def setUp(self): self.amount = 1000 self.org_stripe_account_id = "testing-123-stripe" self.org = OrganizationFactory( stripe_account_id=self.org_stripe_account_id) self.contribution = Contribution.objects.create(amount=self.amount, organization=self.org) self.required_data = { "amount": 1000, "currency": "usd", "organization": self.org }
def setUp(self): self.subscription_id = "test-subscription-id" self.stripe_account_id = "testing-stripe-account-id" self.org = OrganizationFactory( stripe_account_id=self.stripe_account_id) self.contributor = ContributorFactory() self.contribution = ContributionFactory( contributor=self.contributor, organization=self.org, provider_subscription_id=self.subscription_id, ) self.other_contribution = ContributionFactory(organization=self.org) self.payment_method_id = "testing-payment-method-id"
def setUp(self): self.user = create_test_user( role_assignment_data={"role_type": Roles.HUB_ADMIN}) self.subscription_id = "test-subscription-id" self.stripe_account_id = "testing-stripe-account-id" self.org = OrganizationFactory( stripe_account_id=self.stripe_account_id) self.contributor = ContributorFactory() self.contribution = ContributionFactory( contributor=self.contributor, organization=self.org, provider_subscription_id=self.subscription_id, ) self.other_contribution = ContributionFactory()
def set_up_domain_model(cls): """Set up most commonly needed data models in a predictable way for use across tests NB: The names and relations here matter. There is test code that expects that there are two orgs, with the given RevenueProgram, DonationPage, and RoleAssignment/User structures """ cls.org1 = OrganizationFactory() cls.org2 = OrganizationFactory() cls.org1_rp1 = RevenueProgramFactory(organization=cls.org1) cls.org1_rp2 = RevenueProgramFactory(organization=cls.org1) cls.org2_rp = RevenueProgramFactory(organization=cls.org2) cls.orgs = Organization.objects.all() cls.rev_programs = RevenueProgram.objects.all() cls.org_user = create_test_user(role_assignment_data={ "role_type": Roles.ORG_ADMIN, "organization": cls.org1 }) cls.rp_user = create_test_user( role_assignment_data={ "role_type": Roles.RP_ADMIN, "revenue_programs": [ cls.org1_rp1, ], "organization": cls.org1, }) cls.hub_user = create_test_user( role_assignment_data={"role_type": Roles.HUB_ADMIN}) cls.superuser = user_model.objects.create_superuser( email="*****@*****.**", password="******") cls.generic_user = create_test_user() # this must be called before _set_up_contributions cls._set_up_donation_pages_and_templates() cls._set_up_contributions() cls._set_up_feature_sets() cls._set_up_styles() cls._set_up_default_feature_flags()
def test_get_changes_from_prev_history_obj_change_with_diff(db): """A historical change to update an object with a change returns a list of changes.""" # Create an Organization. organization = OrganizationFactory(salesforce_id="", stripe_account_id="1") historial_change_create = organization.history.first() # Save the Organization and change some of the values. organization.salesforce_id = "1" organization.stripe_account_id = "2" organization.save() historical_change_update = organization.history.exclude( history_id=historial_change_create.history_id).first() # The changes from the update should equal be the changes that were made. assert get_changes_from_prev_history_obj(historical_change_update) == [ "'Salesforce ID' changed from '' to '1'", "'stripe account id' changed from '1' to '2'", ]
def setUp(self): self.user = user_model.objects.create_superuser(email="*****@*****.**", password="******") self.list_url = reverse("revenueprogram-list") self.rp_count = 3 self.bl_count = 3 self.b_per_bl_count = 2 organization = OrganizationFactory() for _ in range(self.rp_count): revenue_program = RevenueProgramFactory(organization=organization) for i in range(self.bl_count): benefit_level = BenefitLevelFactory(revenue_program=revenue_program, lower_limit=7, upper_limit=13) for j in range(self.b_per_bl_count): benefit = BenefitFactory(revenue_program=revenue_program) BenefitLevelBenefit.objects.create(benefit=benefit, benefit_level=benefit_level, order=j)
def test_clean_prevents_org_rp_mismatch_when_rp_admin(self): some_other_org = OrganizationFactory() mismatched_rp = RevenueProgramFactory(organization=some_other_org) request_body = { "user": self.user, "role_type": Roles.RP_ADMIN, "organization": self.organization.pk, "revenue_programs": [mismatched_rp.pk], } form_is_valid = self.validate_form(request_body) self.assertFalse(form_is_valid) self.assertIn("revenue_programs", self.form.errors) self.assertIn( "The following RevenuePrograms do not belong to your chosen Org:", self.form.errors["revenue_programs"][0]) self.assertIn(mismatched_rp.name, self.form.errors["revenue_programs"][0])
def test_get_changes_from_prev_history_obj_change_delete(db): """A historical change to delete an object returns no changes.""" # Create an Organization. organization = OrganizationFactory(salesforce_id="", stripe_account_id="1") historial_change_create = organization.history.first() # Create a HistoricalOrganization object to delete the organization. HistoricalOrganization = historial_change_create.__class__ historical_change_delete = HistoricalOrganization.objects.create( id=organization.id, history_date=historial_change_create.history_date, history_type="-", history_user=historial_change_create.history_user, history_change_reason=historial_change_create.history_change_reason or "", ) # The changes from the delete should equal [], since the historical_change_delete # indicates that the organization should now be deleted. assert get_changes_from_prev_history_obj(historical_change_delete) == []
def setUp(self): self.hub_integration = HubSlackIntegration.get_solo() self.hub_integration.bot_token = HUB_TOKEN self.hub_integration.channel = HUB_CHANNEL self.hub_integration.org_channel_prefix = HUB_ORG_PREFIX self.hub_integration.save() self.org = OrganizationFactory() self.org_channel = "org-contributions" self.org_integration = OrganizationSlackIntegration( organization=self.org, channel=ORG_CHANNEL, bot_token=ORG_TOKEN) self.org_channel_name = f"{HUB_ORG_PREFIX}{SlackManager.format_org_name(self.org.name)}" self.contributor = ContributorFactory() self.contribution = ContributionFactory( organization=self.org, contributor=self.contributor, amount=AMOUNT, last_payment_date=PAYMENT_DATE, interval=INTERVAL, )
def test_returns_options_if_successful(self): parent_model_name = SAFE_ADMIN_SELECT_PARENTS[1] accessor_method = SAFE_ADMIN_SELECT_ACCESSOR_METHODS[0] self.assertIn(parent_model_name, SAFE_ADMIN_SELECT_PARENTS) self.assertIn(accessor_method, SAFE_ADMIN_SELECT_ACCESSOR_METHODS) org = OrganizationFactory() revenue_program = RevenueProgramFactory(organization=org) style1 = StyleFactory(revenue_program=revenue_program) style2 = StyleFactory(revenue_program=revenue_program) response = self._make_request_to_view(parentModel=parent_model_name, accessorMethod=accessor_method, parentId=revenue_program.pk) options = response.json()["data"] option1 = next(o for o in options if o[1] == style1.pk) option2 = next(o for o in options if o[1] == style2.pk) self.assertEqual(option1[0], style1.name) self.assertEqual(option2[0], style2.name)
def setUp(self): self.organization = OrganizationFactory() self.hub_admin_user = create_test_user( role_assignment_data={"role_type": models.Roles.HUB_ADMIN}) self.hub_admin_user_role_assignment = self.hub_admin_user.roleassignment self.org_admin_user = create_test_user( role_assignment_data={ "role_type": models.Roles.ORG_ADMIN, "organization": self.organization }) self.org_admin_user_role_assignment = self.org_admin_user.roleassignment rp = RevenueProgramFactory(organization=self.organization) rp_qs = RevenueProgram.objects.filter(pk=rp.pk) self.rp_admin_user = create_test_user( role_assignment_data={ "role_type": models.Roles.ORG_ADMIN, "organization": self.organization, "revenue_programs": rp_qs, }) self.rp_admin_user_role_assignment = self.rp_admin_user.roleassignment
def setUp(self): self.factory = RequestFactory() user_model = get_user_model() self.user = user_model.objects.create_superuser(email="*****@*****.**", password="******") self.contribution_admin = ContributionAdmin(Contribution, AdminSite()) self.organization = OrganizationFactory( default_payment_provider="stripe") self.contrib_score_2 = ContributionFactory( status=ContributionStatus.FLAGGED, bad_actor_score=2, organization=self.organization, payment_provider_used="Stripe", ) self.contrib_score_4 = ContributionFactory( status=ContributionStatus.FLAGGED, bad_actor_score=4, organization=self.organization, payment_provider_used="Stripe", )
def setUp(self): self.organization = OrganizationFactory() self.revenue_program = RevenueProgramFactory( organization=self.organization)
def test_get_changes_from_prev_history_obj_create(db): """A historical change to create an object returns no changes.""" organization = OrganizationFactory() historial_change_create = organization.history.first() assert get_changes_from_prev_history_obj(historial_change_create) == []
def setUp(self): self.serializer = serializers.ContributorContributionSerializer self.test_stripe_account_id = "testing_123" self.org = OrganizationFactory( stripe_account_id=self.test_stripe_account_id) self.contribution = ContributionFactory()