Ejemplo n.º 1
0
 def setUp(self):
     self.title = "My Social Title"
     self.description = "My Social Description"
     self.url = "https://example.com"
     self.social_meta = SocialMeta.objects.create(
         title=self.title, description=self.description, url=self.url)
     self.revenue_program = RevenueProgramFactory()
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
def test_revenue_program_default_donation_page_options_limited(admin_client):
    my_revenue_program = RevenueProgramFactory()
    some_other_rp = RevenueProgramFactory()
    dp1 = DonationPageFactory(revenue_program=my_revenue_program)
    dp2 = DonationPageFactory(revenue_program=my_revenue_program)
    dp3 = DonationPageFactory(revenue_program=some_other_rp)

    response = admin_client.get(
        reverse("admin:organizations_revenueprogram_change",
                args=[my_revenue_program.pk]))
    soup = bs4(response.content)

    select = soup.find("select", {"name": "default_donation_page"})
    assert str(dp1.pk) in str(select)
    assert str(dp2.pk) in str(select)
    assert str(dp3.pk) not in str(select)
Ejemplo n.º 4
0
    def setUp(self):
        self.serializer = serializers.AbstractPaymentSerializer
        self.revenue_program = RevenueProgramFactory()
        self.page = DonationPageFactory(revenue_program=self.revenue_program)
        self.element = {
            "type": "Testing",
            "uuid": "testing-123",
            "requiredFields": [],
            "content": {}
        }

        self.payment_data = {
            "amount": 123,
            "currency": "USD",
            "email": "*****@*****.**",
            "first_name": "test",
            "last_name": "test",
            "ip": "127.0.0.1",
            "mailing_city": "test",
            "mailing_country": "test",
            "mailing_postal_code": "12345",
            "mailing_state": "test",
            "mailing_street": "test",
            "organization_country": "ts",
            "referer": "https://test.test",
            "revenue_program_slug": "test",
            "page_id": self.page.pk,
        }
Ejemplo n.º 5
0
def test_benefitlevel_change_has_level_attribute_populated(admin_client):
    my_revenue_program = RevenueProgramFactory()
    my_benefit_level = BenefitLevelFactory(revenue_program=my_revenue_program)
    response = admin_client.get(
        reverse("admin:organizations_benefitlevel_change",
                args=[my_benefit_level.pk]))
    soup = bs4(response.content)
    assert int(soup.find("input", {"name": "level"}).attrs["value"]) == 1
Ejemplo n.º 6
0
def test_benefitlevel_change_where_revenue_program_is_readonly(admin_client):
    my_revenue_program = RevenueProgramFactory()
    my_benefit_level = BenefitLevelFactory(revenue_program=my_revenue_program)
    response = admin_client.get(
        reverse("admin:organizations_benefitlevel_change",
                args=[my_benefit_level.pk]))
    soup = bs4(response.content)
    assert my_revenue_program.name == soup.select_one(
        ".field-revenue_program .readonly a").text
Ejemplo n.º 7
0
 def setUp(self):
     self.rev_program = RevenueProgramFactory()
     self.style_1 = StyleFactory(revenue_program=self.rev_program)
     self.style_2 = StyleFactory(revenue_program=self.rev_program)
     self.donation_page_live = DonationPageFactory(
         published_date=timezone.now(), styles=self.style_1, revenue_program=self.rev_program
     )
     self.donation_page_unlive = DonationPageFactory(styles=self.style_2, revenue_program=self.rev_program)
     self.serializer = StyleListSerializer
     self.other_rev_program = RevenueProgramFactory()
     valid_styles_json = {}
     for k, v in required_style_keys.items():
         valid_styles_json[k] = v()
     self.updated_styled_data = {
         "name": "New Test Styles",
         "revenue_program": {"name": self.rev_program.name, "slug": self.rev_program.slug},
         **valid_styles_json,
     }
Ejemplo n.º 8
0
 def setUp(self):
     self.factory = RequestFactory()
     user_model = get_user_model()
     self.user = user_model.objects.create_superuser(email="*****@*****.**",
                                                     password="******")
     self.revenue_program = RevenueProgramFactory()
     self.page_admin = DonationPageAdmin(DonationPage, AdminSite())
     self.page = DonationPageFactory(name="My Test Page",
                                     revenue_program=self.revenue_program)
     self.change_url = reverse("admin:pages_donationpage_changelist")
Ejemplo n.º 9
0
class SocialMetaTest(TestCase):
    def setUp(self):
        self.title = "My Social Title"
        self.description = "My Social Description"
        self.url = "https://example.com"
        self.social_meta = SocialMeta.objects.create(
            title=self.title, description=self.description, url=self.url)
        self.revenue_program = RevenueProgramFactory()

    def test_social_meta_string(self):
        expected_unrelated_string = f"Social media Metatags: {self.title}"
        self.assertEqual(expected_unrelated_string, str(self.social_meta))

        # Add related model
        self.revenue_program.social_meta = self.social_meta
        self.revenue_program.save()

        expected_related_string = f'Social media Metatags for Revenue Program "{self.revenue_program.name}"'
        self.assertEqual(expected_related_string, str(self.social_meta))
Ejemplo n.º 10
0
    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
Ejemplo n.º 11
0
def test_revenue_program_change_list_existing_benefit_levels(admin_client):
    my_revenue_program = RevenueProgramFactory()
    my_benefit_level = BenefitLevelFactory(revenue_program=my_revenue_program)
    response = admin_client.get(
        reverse("admin:organizations_revenueprogram_change",
                args=[my_revenue_program.pk]))
    soup = bs4(response.content)
    benefit_level_id = soup.find("input", {
        "name": "benefitlevel_set-0-id"
    }).attrs["value"]
    assert my_benefit_level.pk == int(benefit_level_id)
Ejemplo n.º 12
0
    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()
Ejemplo n.º 13
0
 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])
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
 def setUp(self):
     self.serializer = serializers.ContributionMetadataSerializer
     self.revenue_program = RevenueProgramFactory()
     self.page = DonationPageFactory(revenue_program=self.revenue_program)
     self.processor_mapping = serializers.ContributionMetadataSerializer.PROCESSOR_MAPPING
     self.all_fields = [
         k for k, v in self.processor_mapping.items()
         if v == self.serializer.ALL
     ]
     self.payment_fields = [
         k for k, v in self.processor_mapping.items()
         if v == self.serializer.PAYMENT
     ]
     self.customer_fields = [
         k for k, v in self.processor_mapping.items()
         if v == self.serializer.CUSTOMER
     ]
     self.payment_data = {
         "amount": 123,
         "donor_selected_amount": 123,
         "currency": "USD",
         "email": "*****@*****.**",
         "first_name": "test",
         "last_name": "test",
         "ip": "127.0.0.1",
         "mailing_city": "test",
         "mailing_country": "test",
         "mailing_postal_code": "12345",
         "mailing_state": "test",
         "mailing_street": "test",
         "phone": "9195555555",
         "organization_country": "ts",
         "referer": "https://test.test",
         "revenue_program_slug": self.revenue_program.slug,
         "page_id": self.page.pk,
         "contributor_id": 1,
         "revenue_program_id": self.revenue_program.pk,
         "reason_for_giving": "Extortion",
         "honoree": "test honoree",
         "in_memory_of": "test in memory of",
         "sf_campaign_id": "TEST123",
         "comp_subscription": True,
         "swag_choice_T Shirt": "sm",
     }
Ejemplo n.º 16
0
    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)
Ejemplo n.º 17
0
 def setUp(self):
     self.rp_name = "My RP"
     self.title = "My Title"
     self.description = "My Description"
     self.url = "https://www.testing.com"
     file = get_test_image_file_jpeg()
     file.url = "/media/whatever.png"
     self.card = get_test_image_file_jpeg()
     self.twitter_handle = "tweetzor"
     self.social_meta = SocialMeta.objects.create(
         title=self.title,
         description=self.description,
         url=self.url,
         card=self.card)
     self.revenue_program = RevenueProgramFactory(
         name=self.rp_name,
         social_meta=self.social_meta,
         twitter_handle=self.twitter_handle)
     self.serializer = SocialMetaInlineSerializer
     factory = RequestFactory()
     self.request = factory.get("/")
Ejemplo n.º 18
0
    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
Ejemplo n.º 19
0
 def setUp(self):
     self.revenue_program = RevenueProgramFactory(name="My Test",
                                                  slug="my-test")
Ejemplo n.º 20
0
 def setUp(self):
     self.organization = OrganizationFactory()
     self.revenue_program = RevenueProgramFactory(
         organization=self.organization)
Ejemplo n.º 21
0
 def setUp(self):
     self.revenue_program = RevenueProgramFactory()