Esempio n. 1
0
    def test_noop_ok(self) -> None:
        self.mark_skippable()

        self.submit_form('update_membership',
                         'input_id_submit',
                         select_dropdowns={
                             "id_tier":
                             TierField.get_description(self.start_tier)
                         })

        # refresh the alumni
        self.user.alumni.refresh_from_db()

        # check that we were redirected to the update_membership page
        self.assert_url_equal('update_membership')
        self.assert_element_exists('div.message.uk-alert-success')

        # check that the new subscription was as expected
        subscription = self.user.alumni.subscription
        self._assert_subscription_equal(subscription,
                                        subscription=self.start_subscription,
                                        tier=self.start_tier,
                                        start=self.start_time,
                                        end=self.end_time)
        self.assertEqual(self.user.alumni.membership.tier, self.start_tier)
    def test_setup_tier_fail(self, mocked: mock.Mock) -> None:
        # fill out the form an select the starter tier
        btn = self.fill_out_form('setup_membership', 'input_id_submit', select_dropdowns={
            "id_tier": TierField.get_description(self.__class__.tier)
        })

        # click the submit button and wait for the page to load
        btn.click()
        self.find_element(None)

        # we stay on the same page
        self.assert_url_equal('setup_membership',
                              'Check that the user does not get redirected to the final page')

        # check that the stripe api was called with the object as a parameter
        alumni = self.user.alumni
        mocked.assert_has_calls([mock.call(alumni)])

        # Check that the membership object was *not* created
        with self.assertRaises(MembershipInformation.DoesNotExist):
            alumni.membership

        # Check that the subscription object was *not* created
        with self.assertRaises(SubscriptionInformation.DoesNotExist):
            SubscriptionInformation.objects.get(member=alumni)
Esempio n. 3
0
    def setUp(self):
        super().setUp()

        self.start_subscription = self.user.alumni.subscription.subscription
        self.subscribe_field_value = TierField.get_stripe_id(
            self.__class__.target_tier)
        self.start_tier = self.user.alumni.membership.tier
        self.start_time = self.user.alumni.subscription.start
        self.end_time = self.user.alumni.subscription.end
Esempio n. 4
0
    def setUp(self) -> None:
        super().setUp()

        self.start_tier: str = self.user.alumni.membership.tier
        self.subscribe_field_value: str = TierField.get_stripe_id(
            self.__class__.target_tier)

        self.start_time: datetime = self.user.alumni.subscription.start
        self.end_time: Optional[datetime] = self.user.alumni.subscription.end
    def test_setup_tier_elements(self) -> None:
        # fill out the tier and check that the right tier into is displayed
        self.fill_out_form('setup_membership', 'input_id_submit', select_dropdowns={
            "id_tier": TierField.get_description(self.__class__.tier)
        })

        for tier in [TierField.STARTER, TierField.CONTRIBUTOR, TierField.PATRON]:
            if tier == self.__class__.tier:
                self.assert_element_displayed('#description-{}'.format(tier))
            else:
                self.assert_element_not_displayed(
                    '#description-{}'.format(tier))
Esempio n. 6
0
    def _assert_select_redirect_payment(self) -> None:
        """ Asserts that selecting an update redirects to the payment method """

        # select to upgrade the membership
        self.submit_form('update_membership',
                         'input_id_submit',
                         select_dropdowns={
                             "id_tier":
                             TierField.get_description(
                                 self.__class__.target_tier)
                         })

        # and check that we are on the right url
        self.assert_url_equal(
            'setup_subscription',
            'Check that the user is directed to enter payment details')
        self.assert_element_exists('div.message.uk-alert-primary')

        # we are still on the original tier
        self._assert_tier_unchanged()
    def test_setup_tier_ok(self, mocked: mock.Mock) -> None:
        # fill out the form an select the contributor tier
        self.submit_form('setup_membership', 'input_id_submit', select_dropdowns={
            "id_tier": TierField.get_description(self.__class__.tier)
        })

        self.assert_url_equal('setup_subscription',
                              'Check that the user gets redirected to the subscription page')

        # check that the stripe api was called with the object as a parameter
        alumni = self.user.alumni
        mocked.assert_has_calls([mock.call(alumni)])

        # check that the membership object was created
        membership = alumni.membership
        self.assertEqual(membership.tier, self.__class__.tier)
        self.assertEqual(membership.customer, MOCKED_CUSTOMER)

        # Check that the subscription object was *not* created
        with self.assertRaises(SubscriptionInformation.DoesNotExist):
            SubscriptionInformation.objects.get(member=alumni)
Esempio n. 8
0
    def test_switch_ok(self, umock: mock.Mock) -> None:
        # select to upgrade the membership
        self.submit_form('update_membership',
                         'input_id_submit',
                         select_dropdowns={
                             "id_tier":
                             TierField.get_description(
                                 self.__class__.target_tier)
                         })

        # check that the methods to downgrade were called
        umock.assert_has_calls(
            [mock.call(self.start_subscription, self.subscribe_field_value)])

        self.user.alumni.refresh_from_db()

        # check that we were redirected to the update_membership page
        self.assert_url_equal('update_membership')
        self.assert_element_exists('div.message.uk-alert-success')

        # check that the new subscription was created
        self._assert_tier_changed()
Esempio n. 9
0
    def test_downgrade_fail_cancel(self, pmock: mock.Mock,
                                   smock: mock.Mock) -> None:
        # select to downgrade the membership
        self.submit_form('update_membership',
                         'input_id_submit',
                         select_dropdowns={
                             "id_tier":
                             TierField.get_description(TierField.STARTER)
                         })

        # check that the methods to downgrade were called
        smock.assert_has_calls([mock.call(self.start_subscription)])
        pmock.assert_not_called()

        self.user.alumni.refresh_from_db()

        # check that we were redirected to the update_membership page and shown an error
        self.assert_url_equal('update_membership')
        self.assert_element_exists('div .message.uk-alert-danger')

        # assert that the tier hasn't changed
        self._assert_tier_unchanged()
    def test_setup_tier_ok(self, mocked: mock.Mock) -> None:
        self.submit_form('setup_membership', 'input_id_submit', select_dropdowns={
            "id_tier": TierField.get_description(TierField.STARTER)
        })

        self.assert_url_equal('setup_setup',
                              'Check that the user gets redirected to the final page')

        # check that the stripe api was called with the object as a parameter
        alumni = self.user.alumni
        mocked.assert_has_calls([mock.call(alumni)])

        # check that the membership object was created
        membership = alumni.membership
        self.assertEqual(membership.tier, TierField.STARTER)
        self.assertEqual(membership.customer, 'cus_Fq8yG7rLrc6sKZ')

        # check that the subscription was created appropriately
        subscription = SubscriptionInformation.objects.get(member=alumni)
        self.assertEqual(subscription.start, MOCKED_TIME)
        self.assertEqual(subscription.end, MOCKED_END)
        self.assertEqual(subscription.subscription, None)
        self.assertEqual(subscription.external, False)
        self.assertEqual(subscription.tier, TierField.STARTER)