コード例 #1
0
    def test_existing_user_addon_cancel(self, mocked_date):
        user = self._make_user()
        user.groups.append(self.ipn_group)
        self.ipn_group.name = 'foo'
        self.ipn_group.addon = True
        mocked_date.today.return_value = date(2013, 12, 30)

        view = IPNView(testing.DummyRequest())
        view.provider = 'jvzoo'
        view.params = AttrDict({
            'email': '*****@*****.**',
            'trans_type': 'RFND',
            'trans_id': 123,
            'product_id': 1,
        })

        resp = view.ipn()
        self.assertEqual(resp, 'Done.')

        # nothing should change for user's main subscription
        self.assertEqual(user.enabled, True)
        self.assertEqual([g.name for g in user.groups], ['enabled', ])

        self.assertEqual(len(user.audit_log_entries), 1)
        self.assertEqual(
            user.audit_log_entries[0].event_type.name, u'UserDisabled')
        self.assertEqual(
            user.audit_log_entries[0].comment,
            u'Addon "foo" disabled by jvzoo, transaction id: 123, type: RFND, '
            u'note: removed from groups: foo',
        )
コード例 #2
0
    def test_existing_user_billing_email_and_rejoin(self, mocked_date):
        user = self._make_user(billing_email='*****@*****.**', enabled=False)
        mocked_date.today.return_value = date(2013, 12, 30)

        view = IPNView(testing.DummyRequest())
        view.provider = 'jvzoo'
        view.params = AttrDict({
            'email': '*****@*****.**',
            'trans_type': 'SALE',
            'trans_id': 123,
            'product_id': 1,
        })

        resp = view.ipn()
        self.assertEqual(resp, 'Done.')
        self.assertEqual(user.enabled, True)
        self.assertEqual(user.trial, True)
        self.assertEqual(user.valid_to, date(2014, 1, 6))
        self.assertEqual(user.last_payment, date(2013, 12, 30))

        self.assertEqual(len(user.audit_log_entries), 1)
        self.assertEqual(
            user.audit_log_entries[0].event_type.name, u'UserEnabled')
        self.assertEqual(
            user.audit_log_entries[0].comment,
            u'Enabled by jvzoo, transaction id: 123, type: SALE, '
            u'note: trial until 2014-01-06',
        )
コード例 #3
0
    def test_existing_user_cancel_subscription(self, mocked_date):
        user = self._make_user(
            email='*****@*****.**',
            groups=[
                Group.by_name('enabled'),
                Group.by_name('trial'),
                Group.by_name('monthly'),
            ])
        mocked_date.today.return_value = date(2013, 12, 30)

        view = IPNView(testing.DummyRequest())
        view.provider = 'clickbank'
        view.params = AttrDict({
            'email': '*****@*****.**',
            'trans_type': 'RFND',
            'trans_id': 123,
            'product_id': 1,
        })
        resp = view.ipn()
        self.assertEqual(resp, 'Done.')
        self.assertEqual(user.enabled, False)
        self.assertEqual(user.valid_to, date(2013, 12, 30))

        self.assertEqual(len(user.audit_log_entries), 1)
        self.assertEqual(
            user.audit_log_entries[0].event_type.name, u'UserDisabled')
        self.assertEqual(
            user.audit_log_entries[0].comment,
            u'Disabled by clickbank, transaction id: 123, type: RFND, note: '
            u'removed from groups: enabled, trial, monthly',
        )
コード例 #4
0
    def test_existing_trial_user_new_subscription_payment(
        self, mocked_date, user=None
    ):
        if not user:
            user = self._make_user(
                email='*****@*****.**',
                groups=[Group.by_name('enabled'), Group.by_name('trial')],
            )

        mocked_date.today.return_value = date(2013, 12, 30)
        view = IPNView(testing.DummyRequest())
        view.provider = 'jvzoo'
        view.params = AttrDict({
            'email': '*****@*****.**',
            'fullname': u'Föo Bar',
            'trans_type': 'BILL',
            'trans_id': 123,
            'product_id': 1,
        })

        resp = view.ipn()
        self.assertEqual(resp, 'Done.')
        self.assertEqual(user.enabled, True)
        self.assertEqual(user.trial, False)
        self.assertEqual(user.valid_to, date(2014, 1, 30))
        self.assertEqual(user.last_payment, date(2013, 12, 30))

        self.assertEqual(len(user.audit_log_entries), 1)
        self.assertEqual(
            user.audit_log_entries[0].event_type.name, u'UserEnabled')
        self.assertEqual(
            user.audit_log_entries[0].comment,
            u'Enabled by jvzoo, transaction id: 123, type: BILL, note: '
            u'regular until 2014-01-30',
        )
コード例 #5
0
    def test_new_user_no_trial(self, mocked_date):
        Group.by_name('monthly').trial_validity = None
        mocked_date.today.return_value = date(2013, 12, 30)

        view = IPNView(testing.DummyRequest())
        view.provider = 'clickbank'
        view.params = AttrDict({
            'email': '*****@*****.**',
            'fullname': u'Föo Bar',
            'trans_type': 'SALE',
            'trans_id': 123,
            'product_id': 1,
            'affiliate': '*****@*****.**',
        })
        resp = view.ipn()
        self.assertEqual(resp, 'Done.')

        user = User.by_email('*****@*****.**')
        self.assertEqual(user.enabled, True)
        self.assertEqual(user.trial, False)
        self.assertEqual(user.affiliate, '*****@*****.**')
        self.assertEqual(user.valid_to, date(2014, 1, 30))
        self.assertEqual(user.last_payment, date(2013, 12, 30))

        self.assertEqual(len(user.audit_log_entries), 2)

        self.assertEqual(
            user.audit_log_entries[0].event_type.name, u'UserCreated')
        self.assertEqual(
            user.audit_log_entries[0].comment,
            u'Created by clickbank, transaction id: 123, type: SALE, note: ',
        )

        self.assertEqual(
            user.audit_log_entries[1].event_type.name, u'UserEnabled')
        self.assertEqual(
            user.audit_log_entries[1].comment,
            u'Enabled by clickbank, transaction id: 123, type: SALE, note: '
            u'regular until 2014-01-30',
        )
コード例 #6
0
    def test_existing_user_addon_subscription_new_payment(self, mocked_date):
        user = self._make_user(valid_to=date(2014, 1, 20))
        self.ipn_group.name = 'foo'
        self.ipn_group.addon = True
        mocked_date.today.return_value = date(2013, 12, 30)

        view = IPNView(testing.DummyRequest())
        view.provider = 'jvzoo'
        view.params = AttrDict({
            'email': '*****@*****.**',
            'trans_type': 'BILL',
            'trans_id': 123,
            'product_id': 1,
        })

        resp = view.ipn()
        self.assertEqual(resp, 'Done.')

        # nothing should change for user's main subscription
        self.assertEqual(user.enabled, True)
        self.assertEqual(user.trial, False)
        self.assertEqual(user.valid_to, date(2014, 1, 20))
        self.assertEqual(user.last_payment, None)

        self.assertEqual(
            user.get_property('addon_1_valid_to'), date(2014, 1, 30))
        self.assertEqual(
            user.get_property('addon_1_last_payment'), date(2013, 12, 30))

        self.assertEqual(len(user.audit_log_entries), 1)
        self.assertEqual(
            user.audit_log_entries[0].event_type.name, u'UserEnabled')
        self.assertEqual(
            user.audit_log_entries[0].comment,
            u'Addon "foo" enabled by jvzoo, transaction id: 123, type: BILL, '
            u'note: regular until 2014-01-30',
        )
コード例 #7
0
    def test_existing_user_refund_after_upgrade(self, mocked_date):
        user = self._make_user(
            email='*****@*****.**',
            groups=[
                Group.by_name('enabled'),
                Group.by_name('trial'),
                Group.by_name('monthly'),
            ])
        user.set_property('upgrade_completed', True)

        view = IPNView(testing.DummyRequest())
        view.provider = 'clickbank'
        view.params = AttrDict({
            'email': '*****@*****.**',
            'trans_type': 'RFND',
            'trans_id': 123,
            'product_id': 1,
        })
        resp = view.ipn()
        self.assertEqual(resp, 'Done.')
        self.assertEqual(user.enabled, True)
        self.assertIn(Group.by_name('monthly'), user.groups)

        self.assertEqual(len(user.audit_log_entries), 0)