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()
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()
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')
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')
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())
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()
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'])
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'])
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()
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')
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')
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'])
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'])
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)
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'])
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'])
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)
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')
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')
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())
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')
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())
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')
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)
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()
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()
def create_paymethod(self): buyer, braintree_buyer = create_braintree_buyer() return create_method(braintree_buyer)
def create_paymethod(self): buyer, braintree_buyer = create_braintree_buyer() return create_method(braintree_buyer)
def create_method_all(): buyer, braintree_buyer = create_braintree_buyer() seller, seller_product = create_seller() method = create_method(braintree_buyer) return method, seller_product
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'])
def setUp(self): self.buyer, self.braintree_buyer = create_braintree_buyer() self.url = reverse('braintree:mozilla:paymethod-list') super(TestBraintreeBuyerMethod, self).setUp()
def setUp(self): self.buyer, self.braintree_buyer = create_braintree_buyer() self.url = reverse('braintree:mozilla:paymethod-list') super(TestBraintreeBuyerMethod, self).setUp()
def create_method_all(): buyer, braintree_buyer = create_braintree_buyer() seller, seller_product = create_seller() method = create_method(braintree_buyer) return method, seller_product
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)
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'])