コード例 #1
0
 def test_get_context_data(self):
     view = DowngradeConfirmationView()
     view.request = self.factory.get('/', data={'tier': 'tier1'})
     data = view.get_context_data()
     self.assertIsInstance(data.get('form'), TierChangeForm)
     self.assertEqual(data.get('tier'), self.tier1)
     self.assertEqual(data.get('tier_info'), self.tier_info)
     self.assertIsInstance(data.get('admins_to_demote'), list)
     self.assertIsInstance(data.get('videos_to_deactivate'), list)
     self.assertIsInstance(data.get('have_theme'), bool)
コード例 #2
0
    def test_get_context_data__bad_price(self):
        """
        If the tier isn't a downgrade, a 404 should be raised.

        """
        tier3 = self.create_tier(name='Tier3', slug='tier3', price=40)
        self.tier_info.available_tiers.add(tier3)
        view = DowngradeConfirmationView()
        view.request = self.factory.get('/', data={'tier': 'tier3'})
        self.assertRaises(Http404, view.get_context_data)
コード例 #3
0
    def test_get_context_data__bad_slug(self):
        """
        If the slug doesn't represent an available tier, a 404 should be
        raised.

        """
        self.create_tier(name='Tier3', slug='tier3', price=10)
        view = DowngradeConfirmationView()
        view.request = self.factory.get('/', data={'tier': 'tier3'})
        self.assertRaises(Http404, view.get_context_data)
コード例 #4
0
    def test_get_context_data__enforced__cancellation__no_subscription(self):
        """
        If payments are enforced, but there is no active subscription, a
        non-paypal-based form should be used.
        """
        self.tier_info.enforce_payments = True
        self.tier_info.save()

        view = DowngradeConfirmationView()
        view.request = self.factory.get('/', data={'tier': 'tier1'})
        data = view.get_context_data()
        self.assertIsInstance(data.get('form'), TierChangeForm)
        self.assertEqual(data.get('tier'), self.tier1)
        self.assertEqual(data.get('tier_info'), self.tier_info)
        self.assertIsInstance(data.get('admins_to_demote'), list)
        self.assertIsInstance(data.get('videos_to_deactivate'), list)
        self.assertIsInstance(data.get('have_theme'), bool)
コード例 #5
0
    def test_get_context_data__enforced(self):
        """
        If payments are enforced, a paypal-based form should be used.
        """
        self.tier_info.enforce_payments = True
        self.tier_info.save()
        self.tier1.price = 10
        self.tier1.save()

        view = DowngradeConfirmationView()
        view.request = self.factory.get('/', data={'tier': 'tier1'})
        data = view.get_context_data()
        self.assertIsInstance(data.get('form'), PayPalSubscriptionForm)
        self.assertEqual(data.get('tier'), self.tier1)
        self.assertEqual(data.get('tier_info'), self.tier_info)
        self.assertIsInstance(data.get('admins_to_demote'), list)
        self.assertIsInstance(data.get('videos_to_deactivate'), list)
        self.assertIsInstance(data.get('have_theme'), bool)
コード例 #6
0
    def test_get_context_data__enforced__cancellation(self):
        """
        If payments are enforced, a paypal-based form should be used.
        """
        self.tier_info.enforce_payments = True
        self.tier_info.save()

        view = DowngradeConfirmationView()
        view.request = self.factory.get('/', data={'tier': 'tier1'})
        with mock.patch.object(self.tier_info,
                               'subscription',
                               signup_or_modify=self.create_ipn()):
            data = view.get_context_data()
        self.assertIsInstance(data.get('form'), PayPalCancellationForm)
        self.assertEqual(data.get('tier'), self.tier1)
        self.assertEqual(data.get('tier_info'), self.tier_info)
        self.assertIsInstance(data.get('admins_to_demote'), list)
        self.assertIsInstance(data.get('videos_to_deactivate'), list)
        self.assertIsInstance(data.get('have_theme'), bool)