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 test_unexpected_role_type(self): novel = create_test_user( role_assignment_data={"role_type": "never-before-seen"}) self.assert_user_cannot_get( reverse("contribution-list"), novel, expected_status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
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 test_unexpected_role_type(self): novel = create_test_user( role_assignment_data={"role_type": "this-is-new"}) self.assert_user_cannot_get( reverse("organization-list"), novel, expected_status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, )
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 setUp(self): super().setUp() self.is_authed_user = create_test_user() self.post_data = {} self.expected_user_types = ( self.superuser, self.hub_user, self.org_user, self.rp_user, ) self.detail_url = reverse("organization-detail", args=(self.org1.pk, )) self.list_url = reverse("organization-list")
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.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_user_serializer_flags( flag1_everyone, flag1_superusers, flag1_add_user, flag2_everyone, flag2_superusers, flag2_add_user, user_under_test, expect_flag1, expect_flag2, ): user = { "superuser": user_model.objects.create_superuser(email="*****@*****.**", password="******"), "hub_admin": create_test_user(role_assignment_data={"role_type": Roles.HUB_ADMIN}), }[user_under_test] Flag = get_waffle_flag_model() flag1 = Flag.objects.create(name="flag1", everyone=flag1_everyone, superusers=flag1_superusers) if flag1_add_user: flag1.users.add(user) flag1.save() flag2 = Flag.objects.create(name="flag2", everyone=flag2_everyone, superusers=flag2_superusers) if flag2_add_user: flag2.users.add(user) flag2.save() request = APIRequestFactory().get("/") request.user = user data = serializers.UserSerializer(user, context={"request": request}).data expected_flag_count = sum([x for x in [expect_flag1, expect_flag2] if x]) assert len(data["flags"]) == expected_flag_count flags = [(flag["name"], flag["id"]) for flag in data["flags"]] if expect_flag1: assert (flag1.name, flag1.id) in flags if not expect_flag1: assert (flag1.name, flag1.id) not in flags if expect_flag2: assert (flag2.name, flag2.id) in flags if not expect_flag2: assert (flag2.name, flag2.id) not in flags
def test_str_method_with_different_user_types(self): str(self.hub_admin_user) str(self.org_admin_user) str(self.rp_admin_user) str(create_test_user())