def test_invoice_number_increments(self): order = factories.create_pending_order_for_self() actions.confirm_order(order, 'ch_abcdefghijklmnopqurstuvw', 1495355163) self.assertEqual(order.invoice_number, 1) order = factories.create_pending_order_for_self() actions.confirm_order(order, 'ch_abcdefghijklmnopqurstuvx', 1495355164) self.assertEqual(order.invoice_number, 2)
def test_when_not_paid(self): bob = factories.create_user('Bob') order = factories.create_pending_order_for_self(user=bob) self.client.force_login(bob) rsp = self.client.get(f'/orders/{order.order_id}/receipt/', follow=True) self.assertRedirects(rsp, f'/orders/{order.order_id}/') self.assertContains(rsp, 'This order has not been paid')
def test_mark_order_as_errored_after_charge(self): order = factories.create_pending_order_for_self() actions.mark_order_as_errored_after_charge(order, 'ch_abcdefghijklmnopqurstuvw') self.assertEqual(order.stripe_charge_id, 'ch_abcdefghijklmnopqurstuvw') self.assertEqual(order.status, 'errored')
def test_mark_order_as_failed(self): order = factories.create_pending_order_for_self() actions.mark_order_as_failed(order, 'There was a problem') self.assertEqual(order.stripe_charge_failure_reason, 'There was a problem') self.assertEqual(order.status, 'failed')
def test_order_for_self(self): order = factories.create_pending_order_for_self() actions.confirm_order(order, 'ch_abcdefghijklmnopqurstuvw', 1495355163) self.assertEqual(order.stripe_charge_id, 'ch_abcdefghijklmnopqurstuvw') self.assertEqual(order.stripe_charge_created.timestamp(), 1495355163) self.assertEqual(order.stripe_charge_failure_reason, '') self.assertEqual(order.status, 'successful') self.assertEqual(order.invoice_number, 1) self.assertEqual(order.order_rows.count(), 1) [row] = order.all_order_rows() self.assertEqual(row.cost_excl_vat, 125) self.assertEqual(row.item_descr, '3-day individual-rate ticket') self.assertEqual(row.item_descr_extra, 'Saturday, Sunday, Monday') ticket = row.item self.assertEqual(ticket.owner, order.purchaser) self.assertEqual(ticket.rate, 'individual') self.assertEqual(ticket.days(), ['Saturday', 'Sunday', 'Monday']) self.assertEqual(order.purchaser.orders.count(), 1) self.assertIsNotNone(order.purchaser.get_ticket()) self.assertEqual(len(mail.outbox), 1)
def test_for_pending_order_for_self_when_already_has_ticket(self): user = factories.create_user(email_addr='*****@*****.**') factories.create_confirmed_order_for_self(user) order = factories.create_pending_order_for_self(user) self.client.force_login(user) rsp = self.client.get(f'/orders/{order.order_id}/', follow=True) self.assertRedirects(rsp, f'/tickets/orders/{order.order_id}/edit/') self.assertContains(rsp, 'You already have a ticket. Please amend your order.')
def test_billing_addr_formatted(self): order = factories.create_pending_order_for_self(rate='corporate') order.billing_addr = ''' City Hall, Cathays Park Cardiff '''.strip() self.assertEqual(order.billing_addr_formatted(), 'City Hall, Cathays Park, Cardiff')
def test_sends_slack_message(self): backend = get_slack_backend() order = factories.create_pending_order_for_self() backend.reset_messages() actions.confirm_order(order, 'ch_abcdefghijklmnopqurstuvw', 1495355163) messages = backend.retrieve_messages() self.assertEqual(len(messages), 1) text = messages[0]['text'] self.assertIn('Alice has just placed an order for 1 ticket', text)
def test_ticket_purchase_after_refund(self): user = factories.create_user() factories.create_confirmed_order_for_self(user) ticket = user.get_ticket() order = factories.create_pending_order_for_self(user) token = 'tok_abcdefghijklmnopqurstuvwx' with utils.patched_charge_creation_success(), utils.patched_refund_creation(): actions.process_stripe_charge(order, token) self.assertEqual(order.status, 'errored') with utils.patched_refund_creation(): actions.refund_item(ticket, 'Refund requested by user') user.refresh_from_db() self.assertIsNone(user.get_ticket()) order = factories.create_pending_order_for_self(user) with utils.patched_charge_creation_success(): actions.process_stripe_charge(order, token) self.assertEqual(order.status, 'successful') user.refresh_from_db() self.assertIsNotNone(user.get_ticket())
def test_after_order_marked_as_failed(self): order = factories.create_pending_order_for_self() actions.mark_order_as_failed(order, 'There was a problem') actions.confirm_order(order, 'ch_abcdefghijklmnopqurstuvw', 1495355163) self.assertEqual(order.stripe_charge_id, 'ch_abcdefghijklmnopqurstuvw') self.assertEqual(order.stripe_charge_created.timestamp(), 1495355163) self.assertEqual(order.stripe_charge_failure_reason, '') self.assertEqual(order.status, 'successful') self.assertEqual(order.invoice_number, 1) self.assertEqual(order.purchaser.orders.count(), 1) self.assertIsNotNone(order.purchaser.get_ticket()) ticket = order.purchaser.get_ticket() self.assertEqual(ticket.days(), ['Saturday', 'Sunday', 'Monday'])
def test_for_pending_order(self): user = factories.create_user(email_addr='*****@*****.**') order = factories.create_pending_order_for_self(user) self.client.force_login(user) rsp = self.client.get(f'/orders/{order.order_id}/', follow=True) self.assertContains(rsp, f'Details of your order ({order.order_id})') self.assertContains(rsp, '<div id="stripe-form">') self.assertContains(rsp, 'data-amount="15000"') self.assertContains(rsp, 'data-email="*****@*****.**"') self.assertContains(rsp, ''' <tr> <td>Alice</td> <td>3-day individual-rate ticket</td> <td>Saturday, Sunday, Monday</td> <td>£150.00</td> </tr> ''', html=True)
def setUpTestData(cls): cls.order = factories.create_pending_order_for_self()
def setUpTestData(cls): cls.order = factories.create_pending_order_for_self() cls.url = f'/orders/{cls.order.order_id}/payment/'
def setUp(self): self.order = factories.create_pending_order_for_self()