def test_feature_level(self): """Test getting a users max feature level from their plans""" free = ProfileFactory( user__membership__organization__plan=FreePlanFactory() ) pro = ProfileFactory( user__membership__organization__plan=ProfessionalPlanFactory() ) org = ProfileFactory( user__membership__organization__plan=OrganizationPlanFactory() ) eq_(free.feature_level, 0) eq_(pro.feature_level, 1) eq_(org.feature_level, 2) MembershipFactory( user=free.user, organization__plan__name='Organization' ) # refresh from db because feature level is cached free = Profile.objects.get(pk=free.pk) # if in free plan and org plan, take the larger one eq_(free.feature_level, 2)
def test_feature_level(self): """Test getting a users max feature level from their entitlements""" free = ProfileFactory( user__membership__organization__entitlement=FreeEntitlementFactory() ) pro = ProfileFactory( user__membership__organization__entitlement=ProfessionalEntitlementFactory() ) org = ProfileFactory( user__membership__organization__entitlement=OrganizationEntitlementFactory() ) eq_(free.feature_level, 0) eq_(pro.feature_level, 1) eq_(org.feature_level, 2) MembershipFactory( user=free.user, organization__entitlement__name="Organization" ) # refresh from db because feature level is cached free = Profile.objects.get(pk=free.pk) # if in free entitlement and org entitlement, take the larger one eq_(free.feature_level, 2)
class TestFailedPaymentTask(TestCase): """Tests the failed payment task.""" def setUp(self): mock_invoice.plan.id = 'pro' mock_invoice.attempt_count = 1 self.profile = ProfileFactory(customer_id=mock_invoice.customer) @mock.patch('muckrock.message.email.TemplateEmail.send') def test_failed_invoice_charge(self, mock_send): """Make sure the send method is called for a failed payment notification""" tasks.failed_payment(mock_invoice.id) mock_send.assert_called_with(fail_silently=False) self.profile.refresh_from_db() ok_(self.profile.payment_failed, 'The payment failed flag should be raised.') @mock.patch('muckrock.message.email.TemplateEmail.send') @mock.patch('muckrock.accounts.models.Profile.cancel_pro_subscription') def test_last_attempt_pro(self, mock_cancel, mock_send): """After the last attempt at payment, cancel the user's pro subscription""" self.profile.payment_failed = True self.profile.save() ok_(self.profile.payment_failed, 'The payment failed flag should be raised.') mock_invoice.attempt_count = 4 mock_invoice.lines.data[0].plan.id = 'pro' tasks.failed_payment(mock_invoice.id) self.profile.refresh_from_db() mock_cancel.assert_called_with() mock_send.assert_called_with(fail_silently=False) ok_(not self.profile.payment_failed, 'The payment failed flag should be lowered.') @mock.patch('muckrock.message.email.TemplateEmail.send') @mock.patch('muckrock.organization.models.Organization.cancel_subscription' ) def test_last_attempt_org(self, mock_cancel, mock_send): """After the last attempt at payment, cancel the user's org subscription""" self.profile.payment_failed = True self.profile.save() ok_(self.profile.payment_failed, 'The payment failed flag should be raised.') OrganizationFactory(owner=self.profile.user) mock_invoice.attempt_count = 4 mock_invoice.lines.data[0].plan.id = 'org' tasks.failed_payment(mock_invoice.id) self.profile.refresh_from_db() mock_cancel.assert_called_with() mock_send.assert_called_with(fail_silently=False) ok_(not self.profile.payment_failed, 'The payment failed flag should be lowered.')
def test_pro_invoice_receipt(self, mock_send): """A receipt should be sent after a pro subscription payment is made.""" mock_subscription.plan.id = 'pro' customer_id = 'test-pro' ProfileFactory(customer_id=customer_id) mock_invoice.customer = customer_id tasks.send_invoice_receipt(mock_invoice.id) mock_send.assert_called_with(fail_silently=False)
def setUp(self): """Set up tests""" self.profile = ProfileFactory() self.data = { 'email_pref': self.profile.email_pref, 'use_autologin': self.profile.use_autologin, 'email': self.profile.user.email } self.form = EmailSettingsForm
def test_is_advanced(self): """Test whether the users are marked as advanced.""" pro = ProfileFactory( user__membership__organization__plan=ProfessionalPlanFactory() ) org = ProfileFactory( user__membership__organization__plan=OrganizationPlanFactory() ) free = ProfileFactory( user__membership__organization__plan=FreePlanFactory() ) assert_true(pro.is_advanced()) assert_true(org.is_advanced()) assert_false(free.is_advanced())
def setUp(self): mock_invoice.plan.id = 'pro' mock_invoice.attempt_count = 1 self.profile = ProfileFactory(customer_id=mock_invoice.customer)
def setUp(self): self.profile = ProfileFactory()