Example #1
0
class TestReference(TestCase):
    fixtures = fixture('user_999')

    def setUp(self):
        self.user = UserProfile.objects.get(pk=999)
        self.ref = Reference()

    @patch('mkt.developers.models.client')
    def test_setup_seller(self, client):
        self.ref.setup_seller(self.user)
        ok_(SolitudeSeller.objects.filter(user=self.user).exists())

    @patch('mkt.developers.models.client')
    @patch.object(Reference, 'client')
    def test_account_create(self, providers, models):
        data = {'account_name': 'account', 'name': 'f', 'email': '*****@*****.**'}
        res = self.ref.account_create(self.user, data)
        acct = PaymentAccount.objects.get(user=self.user)
        eq_(acct.provider, PROVIDER_REFERENCE)
        eq_(res.pk, acct.pk)
Example #2
0
class TestReference(Patcher, TestCase):
    fixtures = fixture('user_999')

    def setUp(self, *args, **kw):
        super(TestReference, self).setUp(*args, **kw)
        self.user = UserProfile.objects.get(pk=999)
        self.ref = Reference()

    def test_setup_seller(self):
        self.ref.setup_seller(self.user)
        ok_(SolitudeSeller.objects.filter(user=self.user).exists())

    def test_account_create(self):
        data = {'account_name': 'account', 'name': 'f', 'email': '*****@*****.**'}
        res = self.ref.account_create(self.user, data)
        acct = PaymentAccount.objects.get(user=self.user)
        eq_(acct.provider, PROVIDER_REFERENCE)
        eq_(res.pk, acct.pk)
        self.ref_patcher.sellers.post.assert_called_with(data={
            'status': 'ACTIVE',
            'email': '*****@*****.**',
            'uuid': ANY,
            'name': 'f',
        })

    def make_account(self):
        seller = SolitudeSeller.objects.create(user=self.user)
        return PaymentAccount.objects.create(user=self.user,
                                             solitude_seller=seller,
                                             uri='/f/b/1',
                                             name='account name')

    def test_terms_retrieve(self):
        account = self.make_account()
        self.ref.terms_retrieve(account)
        assert self.ref_patcher.terms.called

    def test_terms_bleached(self):
        account = self.make_account()
        account_mock = Mock()
        account_mock.get.return_value = {
            'text': '<script>foo</script><a>bar</a>'
        }
        self.ref_patcher.terms.return_value = account_mock
        eq_(
            self.ref.terms_retrieve(account)['text'],
            u'&lt;script&gt;foo&lt;/script&gt;<a>bar</a>')

    def test_terms_update(self):
        seller_mock = Mock()
        seller_mock.get.return_value = {
            'id': 1,
            'resource_uri': '/a/b/c',
            'resource_name': 'x',
            'initial_field': u'initial content',
        }
        seller_mock.put.return_value = {}
        self.ref_patcher.sellers.return_value = seller_mock
        account = self.make_account()
        self.ref.terms_update(account)
        eq_(account.reload().agreed_tos, True)
        assert self.ref_patcher.sellers.called
        seller_mock.get.assert_called_with()
        seller_mock.put.assert_called_with({
            'agreement':
            datetime.now().strftime('%Y-%m-%d'),
            'initial_field':
            u'initial content',
        })

    def test_account_retrieve(self):
        account = self.make_account()
        acc = self.ref.account_retrieve(account)
        eq_(acc, {'account_name': 'account name'})
        assert self.ref_patcher.sellers.called

    def test_account_update(self):
        account_data = {
            'status': '',
            'resource_name': 'sellers',
            'uuid': 'custom-uuid',
            'agreement': '',
            'email': '*****@*****.**',
            'id': 'custom-uuid',
            'resource_uri': '/provider/reference/sellers/custom-uuid/',
            'account_name': u'Test',
            'name': 'Test',
        }
        seller_mock = Mock()
        seller_mock.get.return_value = account_data
        self.ref_patcher.sellers.return_value = seller_mock
        account = self.make_account()
        self.ref.account_update(account, account_data)
        eq_(self.ref.forms['account']().hidden_fields()[0].name, 'uuid')
        eq_(account.reload().name, 'Test')
        seller_mock.put.assert_called_with(account_data)

    def test_product_create_exists(self):
        self.ref_patcher.products.get.return_value = [{'resource_uri': '/f'}]
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)
        # Product should have been got from zippy, but not created by a post.
        assert self.ref_patcher.products.get.called

    @raises(ValueError)
    def test_product_mulitple(self):
        self.ref_patcher.products.get.return_value = [{}, {}]
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)

    def test_product_create_not(self):
        self.generic_patcher.product.get_object_or_404.return_value = {
            'external_id': 'ext'
        }
        self.ref_patcher.products.get.return_value = []
        self.ref_patcher.products.post.return_value = {'resource_uri': '/f'}
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)
        self.ref_patcher.products.get.assert_called_with(seller_id='1',
                                                         external_id='ext')
        self.ref_patcher.products.post.assert_called_with(
            data={
                'seller_id': '1',
                'external_id': 'ext',
                'name': unicode(app.name),
                'uuid': ANY,
            })
Example #3
0
class TestReference(Patcher, TestCase):
    fixtures = fixture('user_999')

    def setUp(self, *args, **kw):
        super(TestReference, self).setUp(*args, **kw)
        self.user = UserProfile.objects.get(pk=999)
        self.ref = Reference()

    def test_setup_seller(self):
        self.ref.setup_seller(self.user)
        ok_(SolitudeSeller.objects.filter(user=self.user).exists())

    def test_account_create(self):
        data = {'account_name': 'account', 'name': 'f', 'email': '*****@*****.**'}
        res = self.ref.account_create(self.user, data)
        acct = PaymentAccount.objects.get(user=self.user)
        eq_(acct.provider, PROVIDER_REFERENCE)
        eq_(res.pk, acct.pk)
        self.ref_patcher.sellers.post.assert_called_with(data={
            'status': 'ACTIVE',
            'email': '*****@*****.**',
            'uuid': ANY,
            'name': 'f',
        })

    def make_account(self):
        seller = SolitudeSeller.objects.create(user=self.user)
        return PaymentAccount.objects.create(user=self.user,
                                             solitude_seller=seller,
                                             uri='/f/b/1',
                                             name='account name',
                                             provider=PROVIDER_REFERENCE)

    def test_terms_retrieve(self):
        account = self.make_account()
        self.ref.terms_retrieve(account)
        assert self.ref_patcher.terms.called

    def test_terms_bleached(self):
        account = self.make_account()
        account_mock = Mock()
        account_mock.get.return_value = {'text':
                                         '<script>foo</script><a>bar</a>'}
        self.ref_patcher.terms.return_value = account_mock
        eq_(self.ref.terms_retrieve(account)['text'],
            u'&lt;script&gt;foo&lt;/script&gt;<a>bar</a>')

    def test_terms_update(self):
        seller_mock = Mock()
        seller_mock.get.return_value = {
            'id': 1,
            'resource_uri': '/a/b/c',
            'resource_name': 'x',
            'initial_field': u'initial content',
        }
        seller_mock.put.return_value = {}
        self.ref_patcher.sellers.return_value = seller_mock
        account = self.make_account()
        self.ref.terms_update(account)
        eq_(account.reload().agreed_tos, True)
        assert self.ref_patcher.sellers.called
        seller_mock.get.assert_called_with()
        seller_mock.put.assert_called_with({
            'agreement': datetime.now().strftime('%Y-%m-%d'),
            'initial_field': u'initial content',
        })

    def test_account_retrieve(self):
        account = self.make_account()
        acc = self.ref.account_retrieve(account)
        eq_(acc, {'account_name': 'account name'})
        assert self.ref_patcher.sellers.called

    def test_account_update(self):
        account_data = {
            'status': '',
            'resource_name': 'sellers',
            'uuid': 'custom-uuid',
            'agreement': '',
            'email': '*****@*****.**',
            'id': 'custom-uuid',
            'resource_uri': '/provider/reference/sellers/custom-uuid/',
            'account_name': u'Test',
            'name': 'Test',
        }
        seller_mock = Mock()
        seller_mock.get.return_value = account_data
        self.ref_patcher.sellers.return_value = seller_mock
        account = self.make_account()
        self.ref.account_update(account, account_data)
        eq_(self.ref.forms['account']().hidden_fields()[0].name, 'uuid')
        eq_(account.reload().name, 'Test')
        seller_mock.put.assert_called_with(account_data)

    def test_product_create_exists(self):
        self.ref_patcher.products.get.return_value = [{'resource_uri': '/f'}]
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)
        # Product should have been got from zippy, but not created by a post.
        assert self.ref_patcher.products.get.called

    @raises(ValueError)
    def test_product_mulitple(self):
        self.ref_patcher.products.get.return_value = [{}, {}]
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)

    def test_product_create_not(self):
        self.generic_patcher.product.get_object_or_404.return_value = {
            'external_id': 'ext'}
        self.ref_patcher.products.get.return_value = []
        self.ref_patcher.products.post.return_value = {'resource_uri': '/f'}
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)
        self.ref_patcher.products.get.assert_called_with(
            seller_id='1', external_id='ext')
        self.ref_patcher.products.post.assert_called_with(data={
            'seller_id': '1',
            'external_id': 'ext',
            'name': unicode(app.name),
            'uuid': ANY,
        })
Example #4
0
class TestReference(Patcher, TestCase):
    fixtures = fixture('user_999')

    def setUp(self, *args, **kw):
        super(TestReference, self).setUp(*args, **kw)
        self.user = UserProfile.objects.get(pk=999)
        self.ref = Reference()

    def test_setup_seller(self):
        self.ref.setup_seller(self.user)
        ok_(SolitudeSeller.objects.filter(user=self.user).exists())

    def test_account_create(self):
        data = {'account_name': 'account', 'name': 'f', 'email': '*****@*****.**'}
        res = self.ref.account_create(self.user, data)
        acct = PaymentAccount.objects.get(user=self.user)
        eq_(acct.provider, PROVIDER_REFERENCE)
        eq_(res.pk, acct.pk)

    def make_account(self):
        seller = SolitudeSeller.objects.create(user=self.user)
        return PaymentAccount.objects.create(user=self.user,
                                             solitude_seller=seller,
                                             uri='/f/b/1')

    def test_terms_retrieve(self):
        account = self.make_account()
        self.ref.terms_retrieve(account)
        assert self.ref_patcher.terms.called

    def test_terms_update(self):
        account = self.make_account()
        self.ref.terms_update(account)
        eq_(account.reload().agreed_tos, True)
        assert self.ref_patcher.sellers.called

    def test_account_retrieve(self):
        account = self.make_account()
        self.ref.account_retrieve(account)
        assert self.ref_patcher.sellers.called

    def test_account_update(self):
        account = self.make_account()
        self.ref.account_update(account, {'account_name': 'foo'})
        eq_(account.reload().name, 'foo')
        assert self.ref_patcher.sellers.called

    def test_product_create_exists(self):
        self.ref_patcher.products.get.return_value = [{'resource_uri': '/f'}]
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)
        # Product should have been got from zippy, but not created by a post.
        assert self.ref_patcher.products.get.called

    @raises(ValueError)
    def test_product_mulitple(self):
        self.ref_patcher.products.get.return_value = [{}, {}]
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)

    def test_product_create_not(self):
        self.generic_patcher.product.get_object_or_404.return_value = {
            'external_id': 'ext'}
        self.ref_patcher.products.get.return_value = []
        self.ref_patcher.products.post.return_value = {'resource_uri': '/f'}
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)
        self.ref_patcher.products.get.assert_called_with(
            seller_id='1', external_id='ext')
        self.ref_patcher.products.post.assert_called_with(data={
            'seller_id': '1', 'external_id': 'ext', 'name': unicode(app.name)})
Example #5
0
class TestReference(Patcher, TestCase):
    fixtures = fixture('user_999')

    def setUp(self, *args, **kw):
        super(TestReference, self).setUp(*args, **kw)
        self.user = UserProfile.objects.get(pk=999)
        self.ref = Reference()

    def test_setup_seller(self):
        self.ref.setup_seller(self.user)
        ok_(SolitudeSeller.objects.filter(user=self.user).exists())

    def test_account_create(self):
        data = {'account_name': 'account', 'name': 'f', 'email': '*****@*****.**'}
        res = self.ref.account_create(self.user, data)
        acct = PaymentAccount.objects.get(user=self.user)
        eq_(acct.provider, PROVIDER_REFERENCE)
        eq_(res.pk, acct.pk)

    def make_account(self):
        seller = SolitudeSeller.objects.create(user=self.user)
        return PaymentAccount.objects.create(user=self.user,
                                             solitude_seller=seller,
                                             uri='/f/b/1')

    def test_terms_retrieve(self):
        account = self.make_account()
        self.ref.terms_retrieve(account)
        assert self.ref_patcher.terms.called

    def test_terms_update(self):
        account = self.make_account()
        self.ref.terms_update(account)
        eq_(account.reload().agreed_tos, True)
        assert self.ref_patcher.sellers.called

    def test_account_retrieve(self):
        account = self.make_account()
        self.ref.account_retrieve(account)
        assert self.ref_patcher.sellers.called

    def test_account_update(self):
        account = self.make_account()
        self.ref.account_update(account, {'account_name': 'foo'})
        eq_(account.reload().name, 'foo')
        assert self.ref_patcher.sellers.called

    def test_product_create_exists(self):
        self.ref_patcher.products.get.return_value = [{'resource_uri': '/f'}]
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)
        # Product should have been got from zippy, but not created by a post.
        assert self.ref_patcher.products.get.called

    @raises(ValueError)
    def test_product_mulitple(self):
        self.ref_patcher.products.get.return_value = [{}, {}]
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)

    def test_product_create_not(self):
        self.generic_patcher.product.get_object_or_404.return_value = {
            'external_id': 'ext'
        }
        self.ref_patcher.products.get.return_value = []
        self.ref_patcher.products.post.return_value = {'resource_uri': '/f'}
        account = self.make_account()
        app = app_factory()
        self.ref.product_create(account, app)
        self.ref_patcher.products.get.assert_called_with(seller_id='1',
                                                         external_id='ext')
        self.ref_patcher.products.post.assert_called_with(
            data={
                'seller_id': '1',
                'external_id': 'ext',
                'name': unicode(app.name)
            })