def test_start_boku_transaction_with_valid_data(self): form = BokuTransactionForm(self.post_data) ok_(form.is_valid(), form.errors) transaction = form.start_transaction() ok_('transaction_id' in transaction, transaction) ok_('buy_url' in transaction, transaction)
def post(self, request): form = BokuTransactionForm(request.POST) if form.is_valid(): transaction = form.start_transaction() log.error(('Successfully started Boku Transaction: ' '{transaction_id}').format( transaction_id=transaction['transaction_id'], )) return Response(transaction) else: log.error('Failed to start Boku Transaction: {errors}'.format( errors=form.errors, )) return self.form_errors(form)
def post(self, request): form = BokuTransactionForm(request.DATA) if form.is_valid(): transaction = form.start_transaction() log.info(('Successfully started Boku Transaction: ' '{transaction_id}').format( transaction_id=transaction['transaction_id'], )) return Response(transaction) else: log.error('Failed to start Boku Transaction: {errors}'.format( errors=form.errors.as_text(), )) return self.form_errors(form)
def test_price_requires_an_existing_boku_price_tier(self): self.post_data['price'] = '1.00' form = BokuTransactionForm(self.post_data) ok_(not form.is_valid(), form.errors) ok_(form.ERROR_BAD_PRICE in form.errors['__all__'])
def test_price_requires_a_decimal_value(self): self.post_data['price'] = 'foo' form = BokuTransactionForm(self.post_data) ok_(not form.is_valid(), form.errors) ok_('price' in form.errors)
def test_country_requires_a_defined_country_code(self): self.post_data['country'] = 'foo' form = BokuTransactionForm(self.post_data) ok_(not form.is_valid(), form.errors) ok_('country' in form.errors)
def test_callback_url_requires_a_valid_url(self): self.post_data['callback_url'] = 'foo' form = BokuTransactionForm(self.post_data) ok_(not form.is_valid(), form.errors) ok_('callback_url' in form.errors, form.errors)
def test_currency_must_be_valid(self): self.post_data['currency'] = 'CDN' form = BokuTransactionForm(self.post_data) ok_(not form.is_valid(), form.errors) ok_('currency' in form.errors)
def test_boku_failure_raises_BokuException(self): form = BokuTransactionForm(self.post_data) ok_(form.is_valid(), form.errors) with mock.patch('lib.boku.client.mocks', {'prepare': (500, '')}): assert_raises(BokuException, form.start_transaction)
def test_seller_uuid_requires_a_boku_seller(self): self.seller_boku.delete() form = BokuTransactionForm(self.post_data) ok_(not form.is_valid(), form.errors) ok_('seller_uuid' in form.errors)
def test_seller_uuid_requires_an_existing_seller(self): self.post_data['seller_uuid'] = 'foo' form = BokuTransactionForm(self.post_data) ok_(not form.is_valid(), form.errors) ok_('seller_uuid' in form.errors)
def test_forward_url_requires_a_valid_url(self): self.post_data['forward_url'] = 'not-a-url' form = BokuTransactionForm(self.post_data) ok_(not form.is_valid(), form.errors) ok_('forward_url' in form.errors, form.errors)
def test_starting_a_transaction_before_validation_fails(self): form = BokuTransactionForm(self.post_data) assert_raises(Exception, form.start_transaction)