Exemplo n.º 1
0
class TestBoku(Patcher, TestCase):
    fixtures = fixture('user_999')

    def setUp(self, *args, **kw):
        super(TestBoku, self).setUp(*args, **kw)
        self.user = UserProfile.objects.get(pk=999)
        self.boku = Boku()

    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_BOKU)

    def test_account_create(self):
        data = {
            'account_name': 'account',
            'merchant_id': 'f',
            'service_id': 'b'
        }
        res = self.boku.account_create(self.user, data)
        acct = PaymentAccount.objects.get(user=self.user)
        eq_(acct.provider, PROVIDER_BOKU)
        eq_(acct.agreed_tos, True)
        eq_(res.pk, acct.pk)
        self.boku_patcher.seller.post.assert_called_with(data={
            'seller': ANY,
            'merchant_id': 'f',
            'service_id': 'b',
        })

    def test_terms_update(self):
        account = self.make_account()
        assert not account.agreed_tos
        response = self.boku.terms_update(account)
        assert account.agreed_tos
        assert response['agreed']

    def test_product_create_exists(self):
        self.generic_patcher.product.get_object_or_404.return_value = {
            'resource_uri': '/f'
        }
        account = self.make_account()
        app = app_factory()
        eq_(self.boku.product_create(account, app), '/f')
Exemplo n.º 2
0
class TestBoku(Patcher, TestCase):
    fixtures = fixture('user_999')

    def setUp(self, *args, **kw):
        super(TestBoku, self).setUp(*args, **kw)
        self.user = UserProfile.objects.get(pk=999)
        self.boku = Boku()

    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_BOKU)

    def test_account_create(self):
        data = {'account_name': 'account', 'merchant_id': 'f',
                'service_id': 'b'}
        res = self.boku.account_create(self.user, data)
        acct = PaymentAccount.objects.get(user=self.user)
        eq_(acct.provider, PROVIDER_BOKU)
        eq_(acct.agreed_tos, True)
        eq_(res.pk, acct.pk)
        self.boku_patcher.seller.post.assert_called_with(data={
            'seller': ANY,
            'merchant_id': 'f',
            'service_id': 'b',
        })

    def test_terms_update(self):
        account = self.make_account()
        assert not account.agreed_tos
        response = self.boku.terms_update(account)
        assert account.agreed_tos
        assert response['agreed']

    def test_product_create_exists(self):
        self.generic_patcher.product.get_object_or_404.return_value = {
            'resource_uri': '/f'}
        account = self.make_account()
        app = app_factory()
        eq_(self.boku.product_create(account, app), '/f')
Exemplo n.º 3
0
 def setUp(self, *args, **kw):
     super(TestBoku, self).setUp(*args, **kw)
     self.user = UserProfile.objects.get(pk=999)
     self.boku = Boku()
Exemplo n.º 4
0
class TestBoku(Patcher, TestCase):
    fixtures = fixture('user_999')

    def setUp(self, *args, **kw):
        super(TestBoku, self).setUp(*args, **kw)
        self.user = UserProfile.objects.get(pk=999)
        self.boku = Boku()

    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_BOKU)

    def test_account_create(self):
        data = {'account_name': 'account', 'service_id': 'b'}
        res = self.boku.account_create(self.user, data)
        acct = PaymentAccount.objects.get(user=self.user)
        eq_(acct.provider, PROVIDER_BOKU)
        eq_(acct.agreed_tos, True)
        eq_(res.pk, acct.pk)
        self.boku_patcher.seller.post.assert_called_with(data={
            'seller': ANY,
            'service_id': 'b',
        })

    def test_terms_update(self):
        account = self.make_account()
        assert not account.agreed_tos
        response = self.boku.terms_update(account)
        assert account.agreed_tos
        assert response['accepted']

    def test_create_new_product(self):
        account = self.make_account()
        app = app_factory()

        generic_product_uri = '/generic/product/1/'
        boku_product_uri = '/boku/product/1/'
        self.generic_patcher.product.get_object_or_404.return_value = {
            'resource_pk': 1,
            'resource_uri': generic_product_uri,
        }

        self.boku_patcher.product.get.return_value = {
            'meta': {
                'total_count': 0
            },
            'objects': [],
        }
        self.boku_patcher.product.post.return_value = {
            'resource_uri': boku_product_uri,
            'seller_product': generic_product_uri,
            'seller_boku': account.uri,
        }

        product = self.boku.product_create(account, app)
        eq_(product, boku_product_uri)
        self.boku_patcher.product.post.assert_called_with(
            data={
                'seller_boku': account.uri,
                'seller_product': generic_product_uri,
            })

    def test_update_existing_product(self):
        account = self.make_account()
        app = app_factory()

        generic_product_uri = '/generic/product/1/'
        self.generic_patcher.product.get_object_or_404.return_value = {
            'resource_pk': 1,
            'resource_uri': generic_product_uri,
        }

        existing_boku_product_uri = '/boku/product/1/'
        self.boku_patcher.product.get.return_value = {
            'meta': {
                'total_count': 1
            },
            'objects': [{
                'resource_uri': existing_boku_product_uri,
            }],
        }
        patch_mock = Mock()
        patch_mock.patch.return_value = {
            'resource_uri': existing_boku_product_uri,
            'seller_product': generic_product_uri,
            'seller_boku': account.uri,
        }
        self.boku_patcher.by_url.return_value = patch_mock

        product = self.boku.product_create(account, app)
        eq_(product, existing_boku_product_uri)
        self.boku_patcher.by_url.assert_called_with(existing_boku_product_uri)
        patch_mock.patch.assert_called_with(
            data={
                'seller_boku': account.uri,
                'seller_product': generic_product_uri,
            })

    def test_multiple_existing_products_raises_exception(self):
        account = self.make_account()
        app = app_factory()

        generic_product_uri = '/generic/product/1/'
        self.generic_patcher.product.get_object_or_404.return_value = {
            'resource_pk': 1,
            'resource_uri': generic_product_uri,
        }

        self.boku_patcher.product.get.return_value = {
            'meta': {
                'total_count': 2
            },
            'objects': [],
        }
        with self.assertRaises(ValueError):
            self.boku.product_create(account, app)
Exemplo n.º 5
0
class TestBoku(Patcher, TestCase):
    fixtures = fixture('user_999')

    def setUp(self, *args, **kw):
        super(TestBoku, self).setUp(*args, **kw)
        self.user = UserProfile.objects.get(pk=999)
        self.boku = Boku()

    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_BOKU)

    def test_account_create(self):
        data = {'account_name': 'account',
                'service_id': 'b'}
        res = self.boku.account_create(self.user, data)
        acct = PaymentAccount.objects.get(user=self.user)
        eq_(acct.provider, PROVIDER_BOKU)
        eq_(acct.agreed_tos, True)
        eq_(res.pk, acct.pk)
        self.boku_patcher.seller.post.assert_called_with(data={
            'seller': ANY,
            'service_id': 'b',
        })

    def test_terms_update(self):
        account = self.make_account()
        assert not account.agreed_tos
        response = self.boku.terms_update(account)
        assert account.agreed_tos
        assert response['accepted']

    def test_create_new_product(self):
        account = self.make_account()
        app = app_factory()

        generic_product_uri = '/generic/product/1/'
        boku_product_uri = '/boku/product/1/'
        self.generic_patcher.product.get_object_or_404.return_value = {
            'resource_pk': 1,
            'resource_uri': generic_product_uri,
        }

        self.boku_patcher.product.get.return_value = {
            'meta': {'total_count': 0},
            'objects': [],
        }
        self.boku_patcher.product.post.return_value = {
            'resource_uri': boku_product_uri,
            'seller_product': generic_product_uri,
            'seller_boku': account.uri,
        }

        product = self.boku.product_create(account, app)
        eq_(product, boku_product_uri)
        self.boku_patcher.product.post.assert_called_with(data={
            'seller_boku': account.uri,
            'seller_product': generic_product_uri,
        })

    def test_update_existing_product(self):
        account = self.make_account()
        app = app_factory()

        generic_product_uri = '/generic/product/1/'
        self.generic_patcher.product.get_object_or_404.return_value = {
            'resource_pk': 1,
            'resource_uri': generic_product_uri,
        }

        existing_boku_product_uri = '/boku/product/1/'
        self.boku_patcher.product.get.return_value = {
            'meta': {'total_count': 1},
            'objects': [{
                'resource_uri': existing_boku_product_uri,
            }],
        }
        patch_mock = Mock()
        patch_mock.patch.return_value = {
            'resource_uri': existing_boku_product_uri,
            'seller_product': generic_product_uri,
            'seller_boku': account.uri,
        }
        self.boku_patcher.by_url.return_value = patch_mock

        product = self.boku.product_create(account, app)
        eq_(product, existing_boku_product_uri)
        self.boku_patcher.by_url.assert_called_with(existing_boku_product_uri)
        patch_mock.patch.assert_called_with(data={
            'seller_boku': account.uri,
            'seller_product': generic_product_uri,
        })

    def test_multiple_existing_products_raises_exception(self):
        account = self.make_account()
        app = app_factory()

        generic_product_uri = '/generic/product/1/'
        self.generic_patcher.product.get_object_or_404.return_value = {
            'resource_pk': 1,
            'resource_uri': generic_product_uri,
        }

        self.boku_patcher.product.get.return_value = {
            'meta': {'total_count': 2},
            'objects': [],
        }
        with self.assertRaises(ValueError):
            self.boku.product_create(account, app)