Esempio n. 1
0
 def test_both_paymethod_nonce(self):
     method = create_method(create_braintree_buyer()[1])
     form, errors = self.process({
         'nonce': 'abc',
         'paymethod': method.get_uri()
     })
     assert '__all__' in errors, errors.as_text()
Esempio n. 2
0
 def test_both_paymethod_nonce(self):
     method = create_method(create_braintree_buyer()[1])
     form, errors = self.process({
         'nonce': 'abc',
         'paymethod': method.get_uri()
     })
     assert '__all__' in errors, errors.as_text()
Esempio n. 3
0
 def test_patch_readonly(self):
     buyer, braintree_buyer = create_braintree_buyer()
     url = reverse('braintree:mozilla:buyer-detail',
                   kwargs={'pk': braintree_buyer.pk})
     self.client.patch(url, {'active': False, 'braintree_id': 'foo'})
     res = self.client.get(url)
     eq_(res.json['braintree_id'], 'sample:id')
Esempio n. 4
0
 def test_patch_readonly(self):
     buyer, braintree_buyer = create_braintree_buyer()
     url = reverse('braintree:mozilla:buyer-detail',
                   kwargs={'pk': braintree_buyer.pk})
     self.client.patch(url, {'active': False, 'braintree_id': 'foo'})
     res = self.client.get(url)
     eq_(res.json['braintree_id'], 'sample:id')
Esempio n. 5
0
    def test_pay_method(self):
        self.mocks['sale'].create.return_value = successful_method()
        self.product_mock.get('moz-brick').recurrence = None
        seller, seller_product = create_seller()
        method = create_method(create_braintree_buyer()[1])

        res = self.client.post(
            self.url,
            data={
                'amount': '10.00',
                'paymethod': method.get_uri(),
                'product_id': 'moz-brick'
            }
        )

        self.mocks['sale'].create.assert_called_with({
            'amount': Decimal('10.00'),
            'type': 'sale',
            'options': {'submit_for_settlement': True},
            'payment_method_token': mock.ANY}
        )
        eq_(res.status_code, 200)
        generic = res.json['mozilla']['generic']
        eq_(generic['buyer'], method.braintree_buyer.buyer.get_uri())
        braintree = res.json['mozilla']['braintree']
        eq_(braintree['paymethod'], method.get_uri())
Esempio n. 6
0
 def setUp(self):
     self.buyer, self.braintree_buyer = create_braintree_buyer()
     self.method = create_method(self.braintree_buyer)
     self.seller, self.seller_product = create_seller()
     self.sub = create_subscription(self.method, self.seller_product)
     self.url = reverse('braintree:mozilla:transaction-list')
     self.transaction = Transaction.objects.create(uuid='some:uid')
     super(TestBraintreeTransactionrMethod, self).setUp()
Esempio n. 7
0
    def test_no_buyerbraintree(self):
        buyer, braintree_buyer = create_braintree_buyer()
        braintree_buyer.delete()

        res = self.client.post(self.url,
                               data={'buyer_uuid': buyer.uuid, 'nonce': '123'})
        eq_(res.status_code, 422, res.content)
        eq_(self.mozilla_error(res.json, 'buyer_uuid'), ['does_not_exist'])
Esempio n. 8
0
    def test_no_buyerbraintree(self):
        buyer, braintree_buyer = create_braintree_buyer()
        braintree_buyer.delete()

        res = self.client.post(self.url,
                               data={'buyer_uuid': buyer.uuid, 'nonce': '123'})
        eq_(res.status_code, 422, res.content)
        eq_(self.mozilla_error(res.json, 'buyer_uuid'), ['does_not_exist'])
Esempio n. 9
0
 def setUp(self):
     self.buyer, self.braintree_buyer = create_braintree_buyer()
     self.method = create_method(self.braintree_buyer)
     self.seller, self.seller_product = create_seller()
     self.sub = create_subscription(self.method, self.seller_product)
     self.url = reverse('braintree:mozilla:transaction-list')
     self.transaction = Transaction.objects.create(uuid='some:uid',
                                                   buyer=self.buyer)
     super(TestBraintreeTransaction, self).setUp()
Esempio n. 10
0
 def setUp(self):
     self.buyer, self.braintree_buyer = create_braintree_buyer()
     self.method = create_method(self.braintree_buyer)
     self.seller, self.seller_product = create_seller()
     self.braintree_sub = BraintreeSubscription.objects.create(
         paymethod=self.method,
         seller_product=self.seller_product,
         provider_id='some-bt:id')
     self.sub = subscription(id='some-bt:id')
Esempio n. 11
0
 def setUp(self):
     self.buyer, self.braintree_buyer = create_braintree_buyer()
     self.method = create_method(self.braintree_buyer)
     self.seller, self.seller_product = create_seller()
     self.braintree_sub = BraintreeSubscription.objects.create(
         paymethod=self.method,
         seller_product=self.seller_product,
         provider_id='some-bt:id'
     )
     self.sub = subscription(id='some-bt:id')
Esempio n. 12
0
    def test_reached_max(self):
        self.mocks['method'].create.return_value = successful_method()
        buyer, braintree_buyer = create_braintree_buyer()
        res = self.client.post(
            self.url, data={'buyer_uuid': buyer.uuid, 'nonce': '123'})
        eq_(res.status_code, 201, res.content)

        with self.settings(BRAINTREE_MAX_METHODS=1):
            res = self.client.post(
                self.url, data={'buyer_uuid': buyer.uuid, 'nonce': '1234'})
            eq_(res.status_code, 422, res.content)
            eq_(self.mozilla_error(res.json, 'buyer_uuid'), ['max_size'])
Esempio n. 13
0
    def test_reached_max(self):
        self.mocks['method'].create.return_value = successful_method()
        buyer, braintree_buyer = create_braintree_buyer()
        res = self.client.post(
            self.url, data={'buyer_uuid': buyer.uuid, 'nonce': '123'})
        eq_(res.status_code, 201, res.content)

        with self.settings(BRAINTREE_MAX_METHODS=1):
            res = self.client.post(
                self.url, data={'buyer_uuid': buyer.uuid, 'nonce': '1234'})
            eq_(res.status_code, 422, res.content)
            eq_(self.mozilla_error(res.json, 'buyer_uuid'), ['max_size'])
Esempio n. 14
0
    def test_ok_method(self):
        seller, seller_product = create_seller()
        self.product_mock.get('moz-brick').recurrence = None
        method = create_method(create_braintree_buyer()[1])

        form, errors = self.process({
            'amount': '10.00',
            'paymethod': method.get_uri(),
            'product_id': seller_product.public_id
        })
        assert not errors, errors.as_text()
        assert 'payment_method_nonce' not in form.braintree_data
        eq_(form.braintree_data['payment_method_token'], method.provider_id)
Esempio n. 15
0
    def test_braintree_fails(self):
        self.mocks['method'].create.return_value = error([{
            'attribute': 'payment_method_nonce',
            'message': 'Payment method nonce is invalid.',
            'code': '91925'
        }])

        buyer, braintree_buyer = create_braintree_buyer()
        res = self.client.post(self.url,
                               data={'buyer_uuid': buyer.uuid, 'nonce': '123'})
        ok_(not BraintreePaymentMethod.objects.exists())
        eq_(res.status_code, 422)
        eq_(self.braintree_error(res.json, 'payment_method_nonce'), ['91925'])
Esempio n. 16
0
    def test_braintree_fails(self):
        self.mocks['method'].create.return_value = error([{
            'attribute': 'payment_method_nonce',
            'message': 'Payment method nonce is invalid.',
            'code': '91925'
        }])

        buyer, braintree_buyer = create_braintree_buyer()
        res = self.client.post(self.url,
                               data={'buyer_uuid': buyer.uuid, 'nonce': '123'})
        ok_(not BraintreePaymentMethod.objects.exists())
        eq_(res.status_code, 422)
        eq_(self.braintree_error(res.json, 'payment_method_nonce'), ['91925'])
Esempio n. 17
0
    def test_ok_method(self):
        seller, seller_product = create_seller()
        self.product_mock.get('moz-brick').recurrence = None
        method = create_method(create_braintree_buyer()[1])

        form, errors = self.process({
            'amount': '10.00',
            'paymethod': method.get_uri(),
            'product_id': seller_product.public_id
        })
        assert not errors, errors.as_text()
        assert 'payment_method_nonce' not in form.braintree_data
        eq_(form.braintree_data['payment_method_token'], method.provider_id)
Esempio n. 18
0
    def test_create_with_custom_amount(self):
        self.mocks['sub'].create.return_value = successful_subscription()

        buyer, braintree_buyer = create_braintree_buyer()
        seller, seller_product = create_seller(seller_product_data={
            'public_id': 'charity-donation-monthly',
        })
        method = create_method(braintree_buyer)
        res = self.post(paymethod=method.get_uri(), amount='4.99',
                        plan=seller_product.public_id)

        eq_(res.status_code, 201, res.content)
        subscription = BraintreeSubscription.objects.get()
        eq_(subscription.amount, Decimal('4.99'))

        # Make sure price is in braintree creation.
        data = self.mocks['sub'].create.call_args[0][0]
        eq_(data['price'], '4.99')
Esempio n. 19
0
    def test_ok(self):
        self.mocks['method'].create.return_value = successful_method()

        buyer, braintree_buyer = create_braintree_buyer()
        res = self.client.post(self.url,
                               data={'buyer_uuid': buyer.uuid, 'nonce': '123'}
                               )
        data = {
            'customer_id': 'sample:id',
            'options': {'verify_card': True},
            'payment_method_nonce': u'123'
        }
        self.mocks['method'].create.assert_called_with(data)

        eq_(res.status_code, 201)
        eq_(res.json['braintree']['token'], 'da-token')

        method = BraintreePaymentMethod.objects.get()
        eq_(method.type_name, 'visa')
Esempio n. 20
0
    def test_filter_by_buyer(self):
        # Create the first transaction:
        trans1 = self.create()

        # Create another transaction:
        gen_buyer2, bt_buyer2 = create_braintree_buyer(braintree_id='bt2')
        gen_trans2 = Transaction.objects.create(uuid='t2', buyer=gen_buyer2)
        paymethod2 = create_method(bt_buyer2)
        trans2 = self.create(paymethod=paymethod2, transaction=gen_trans2)

        objects = self.get(
            transaction__buyer__uuid=self.buyer.uuid).json['objects']
        eq_(len(objects), 1, objects)
        eq_(objects[0]['resource_uri'], trans1.get_uri())

        objects = self.get(
            transaction__buyer__uuid=gen_buyer2.uuid).json['objects']
        eq_(len(objects), 1, objects)
        eq_(objects[0]['resource_uri'], trans2.get_uri())
Esempio n. 21
0
    def test_ok(self):
        self.mocks['method'].create.return_value = successful_method()

        buyer, braintree_buyer = create_braintree_buyer()
        res = self.client.post(self.url,
                               data={'buyer_uuid': buyer.uuid, 'nonce': '123'}
                               )
        data = {
            'customer_id': 'sample:id',
            'options': {'verify_card': True},
            'payment_method_nonce': u'123'
        }
        self.mocks['method'].create.assert_called_with(data)

        eq_(res.status_code, 201)
        eq_(res.json['braintree']['token'], 'da-token')

        method = BraintreePaymentMethod.objects.get()
        eq_(method.type_name, 'visa')
Esempio n. 22
0
    def test_filter_by_buyer(self):
        # Create the first transaction:
        trans1 = self.create()

        # Create another transaction:
        gen_buyer2, bt_buyer2 = create_braintree_buyer(braintree_id='bt2')
        gen_trans2 = Transaction.objects.create(uuid='t2', buyer=gen_buyer2)
        paymethod2 = create_method(bt_buyer2)
        trans2 = self.create(paymethod=paymethod2, transaction=gen_trans2)

        objects = self.get(
            transaction__buyer__uuid=self.buyer.uuid).json['objects']
        eq_(len(objects), 1, objects)
        eq_(objects[0]['resource_uri'], trans1.get_uri())

        objects = self.get(
            transaction__buyer__uuid=gen_buyer2.uuid).json['objects']
        eq_(len(objects), 1, objects)
        eq_(objects[0]['resource_uri'], trans2.get_uri())
Esempio n. 23
0
    def test_create_with_custom_amount(self):
        self.mocks['sub'].create.return_value = successful_subscription()

        buyer, braintree_buyer = create_braintree_buyer()
        seller, seller_product = create_seller(
            seller_product_data={
                'public_id': 'charity-donation-monthly',
            })
        method = create_method(braintree_buyer)
        res = self.post(paymethod=method.get_uri(),
                        amount='4.99',
                        plan=seller_product.public_id)

        eq_(res.status_code, 201, res.content)
        subscription = BraintreeSubscription.objects.get()
        eq_(subscription.amount, Decimal('4.99'))

        # Make sure price is in braintree creation.
        data = self.mocks['sub'].create.call_args[0][0]
        eq_(data['price'], '4.99')
Esempio n. 24
0
 def test_lookup(self):
     create_braintree_buyer()
     buyer, braintree_buyer = create_braintree_buyer(braintree_id='f:id')
     res = self.client.get(self.url, {'buyer': buyer.pk})
     eq_(res.json['meta']['total_count'], 1)
     eq_(res.json['objects'][0]['id'], braintree_buyer.pk)
Esempio n. 25
0
 def setUp(self):
     self.buyer, self.braintree_buyer = create_braintree_buyer()
     self.method = create_method(self.braintree_buyer)
     self.seller, self.seller_product = create_seller()
     self.url = reverse('braintree:mozilla:subscription-list')
     super(TestSubscriptionViewSet, self).setUp()
Esempio n. 26
0
 def setUp(self):
     self.buyer, self.braintree_buyer = create_braintree_buyer()
     self.method = create_method(self.braintree_buyer)
     self.seller, self.seller_product = create_seller()
     self.url = reverse('braintree:mozilla:subscription-list')
     super(TestSubscriptionViewSet, self).setUp()
Esempio n. 27
0
 def create_paymethod(self):
     buyer, braintree_buyer = create_braintree_buyer()
     return create_method(braintree_buyer)
Esempio n. 28
0
 def create_paymethod(self):
     buyer, braintree_buyer = create_braintree_buyer()
     return create_method(braintree_buyer)
Esempio n. 29
0
def create_method_all():
    buyer, braintree_buyer = create_braintree_buyer()
    seller, seller_product = create_seller()
    method = create_method(braintree_buyer)
    return method, seller_product
Esempio n. 30
0
 def test_braintree_buyer_exists(self):
     buyer, braintree_buyer = create_braintree_buyer()
     res = self.client.post(self.url, data={'uuid': buyer.uuid})
     eq_(res.status_code, 422)
     eq_(self.mozilla_error(res.json, 'uuid'), ['already_exists'])
Esempio n. 31
0
 def setUp(self):
     self.buyer, self.braintree_buyer = create_braintree_buyer()
     self.url = reverse('braintree:mozilla:paymethod-list')
     super(TestBraintreeBuyerMethod, self).setUp()
Esempio n. 32
0
 def setUp(self):
     self.buyer, self.braintree_buyer = create_braintree_buyer()
     self.url = reverse('braintree:mozilla:paymethod-list')
     super(TestBraintreeBuyerMethod, self).setUp()
Esempio n. 33
0
def create_method_all():
    buyer, braintree_buyer = create_braintree_buyer()
    seller, seller_product = create_seller()
    method = create_method(braintree_buyer)
    return method, seller_product
Esempio n. 34
0
 def test_lookup(self):
     create_braintree_buyer()
     buyer, braintree_buyer = create_braintree_buyer(braintree_id='f:id')
     res = self.client.get(self.url, {'buyer': buyer.pk})
     eq_(res.json['meta']['total_count'], 1)
     eq_(res.json['objects'][0]['id'], braintree_buyer.pk)
Esempio n. 35
0
 def test_braintree_buyer_exists(self):
     buyer, braintree_buyer = create_braintree_buyer()
     res = self.client.post(self.url, data={'uuid': buyer.uuid})
     eq_(res.status_code, 422)
     eq_(self.mozilla_error(res.json, 'uuid'), ['already_exists'])