def test_get_invoice_excel(self): gen_id = f'{__name__}-{int(datetime.now().timestamp())}' self.try_add_entities([ Product(id=gen_id, weight=1), Invoice(id=gen_id, country_id='c1'), Order(id=gen_id, invoice_id=gen_id, country_id='c1'), InvoiceItem(invoice_id=gen_id, product_id=gen_id, price=1, quantity=1) ]) self.try_admin_operation( lambda: self.client.get(f'/api/v1/admin/invoice/{gen_id}/excel'))
def test_get_invoice_cumulative_excel(self): gen_id = f'{__name__}-{int(datetime.now().timestamp())}' self.try_add_entities([ Product(id=gen_id, weight=1), Invoice(id=gen_id, country_id='c1'), Order(id=gen_id, invoice_id=gen_id, country_id='c1'), InvoiceItem(invoice_id=gen_id, product_id=gen_id, price=1, quantity=1) ]) res = self.try_admin_operation( lambda: self.client.get(f'/api/v1/admin/invoice/excel?invoices={gen_id}&invoices={gen_id}')) self.assertTrue(res.status_code, 200)
def test_save_invoice(self): gen_id = f'{__name__}-{int(datetime.now().timestamp())}' self.try_add_entities([ Invoice(id=gen_id, customer='Customer 1') ]) res = self.try_admin_operation( lambda: self.client.post(f'/api/v1/admin/invoice/{gen_id}', json={ 'customer': 'Customer 2' })) self.assertEqual(res.status_code, 200) invoice = Invoice.query.get(gen_id) self.assertEqual(invoice.customer, 'Customer 2')
def test_create_invoice_item(self): gen_id = f'{__name__}-{int(datetime.now().timestamp())}' order = Order(id=gen_id) self.try_add_entities([ Product(id=gen_id, name='Product 1') ]) self.try_add_entities([ order, Suborder(id=gen_id, order=order), OrderProduct(suborder_id=gen_id, product_id=gen_id, price=10, quantity=10), Invoice(id=gen_id, order_id=gen_id) ]) self.try_admin_operation( lambda: self.client.post(f'/api/v1/admin/invoice/{gen_id}/item/new') ) res = self.client.post(f'/api/v1/admin/invoice/{gen_id}/item/new', json={'invoice_id': gen_id, 'product_id': gen_id, 'price': 10, 'quantity': 10}) self.assertTrue(res.status_code, 200)
def test_get_old_invoice(self): gen_id = f'{__name__}-{int(datetime.now().timestamp())}' self.try_add_entities([ Product(id=gen_id, name='Product 1', weight=10), Invoice(id=gen_id, country_id='c1', when_created=datetime(2020, 1, 1, 1, 0, 0), when_changed=datetime(2020, 1, 1, 1, 0, 0)), Order(id=gen_id, invoice_id=gen_id, country_id='c1') ]) suborder = Suborder(order_id=gen_id) self.try_add_entities([ suborder, OrderProduct(suborder=suborder, product_id=gen_id, price=10, quantity=1) ]) res = self.try_admin_operation( lambda: self.client.get(f'/api/v1/admin/invoice/{gen_id}')) self.assertEqual(res.status_code, 200) self.assertEqual(len(res.json), 1) self.assertEqual(res.json[0], { 'address': None, 'country': 'country1', 'customer': None, 'payee': None, 'id': gen_id, 'invoice_items': [{ 'id': 1, 'invoice_id': gen_id, 'product_id': gen_id, 'product': 'Product 1', 'price': 5.0, 'weight': 10, 'quantity': 1, 'subtotal': 5.0, 'when_created': None, 'when_changed': None }], 'orders': [gen_id], 'phone': None, 'total': 5.0, 'weight': 10, 'when_changed': '2020-01-01 01:00:00', 'when_created': '2020-01-01 01:00:00' })
def test_delete_invoice_item(self): gen_id = f'{__name__}-{int(datetime.now().timestamp())}' order = Order(id=gen_id) self.try_add_entities([ Product(id=gen_id, name='Product 1') ]) self.try_add_entities([ order, Suborder(id=gen_id, order=order), OrderProduct(suborder_id=gen_id, product_id=gen_id, price=10, quantity=10), Invoice(id=gen_id, order_id=gen_id), InvoiceItem(id=10, invoice_id=gen_id, product_id=gen_id, price=10, quantity=10) ]) res = self.try_admin_operation( lambda: self.client.delete(f'/api/v1/admin/invoice/{gen_id}/item/10') ) self.assertEqual(res.status_code, 200) invoice_item = InvoiceItem.query.get(10) self.assertEqual(invoice_item, None)
def test_get_invoices(self): self.try_add_entities([ Product(id='0001', name='Product 1', name_english='P1', weight=10), Invoice(id='INV-2020-00-00', country_id='c1', customer='Customer 1', when_created=datetime(2020, 1, 1, 1, 0, 0), when_changed=datetime(2020, 1, 1, 1, 0, 0)), InvoiceItem(invoice_id='INV-2020-00-00', product_id='0001', price=10, quantity=1), Order(id=__name__ + '-1', invoice_id='INV-2020-00-00', country_id='c1', customer_name='Customer 1') ]) self.try_admin_operation( lambda: self.client.get('/api/v1/admin/invoice')) res = self.client.get('/api/v1/admin/invoice/INV-2020-00-00') self.assertEqual(len(res.json), 1) self.assertEqual(res.json[0], { 'address': None, 'country': 'country1', 'customer': 'Customer 1', 'payee': None, 'id': 'INV-2020-00-00', 'invoice_items': [{ 'id': 1, 'invoice_id': 'INV-2020-00-00', 'product_id': '0001', 'product': 'P1', 'price': 10.0, 'weight': 10, 'quantity': 1, 'subtotal': 10.0, 'when_created': None, 'when_changed': None }], 'orders': [__name__ + '-1'], 'phone': None, 'total': 10.0, 'weight': 10, 'when_changed': '2020-01-01 01:00:00', 'when_created': '2020-01-01 01:00:00' })
def test_get_invoice(self): self.try_add_entities([Invoice(id=1), Currency(code='USD', rate=1)]) self.try_admin_operation(lambda: self.client.get('/admin/invoices/1'))