def get_invoice(self): customer = self.get_customer() with self.recorder.use_cassette("TestInvoicePayment.get_invoice"): gen = InvoiceItemGenerator() items = [ gen.generate_title("dummy invoice item title"), gen.generate_description("dummy invoice item description"), gen.generate_lump_position("server hardware", 2000) ] invoice_create = self.moco.Invoice.create( customer.id, "dummy invoice", date(2020, 1, 1), date(2021, 1, 1), date(2020, 1, 1), date(2020, 3, 1), "dummy invoice", 19, "EUR", items, ) return invoice_create.data
def get_invoice(self): customer = self.get_customer() with self.recorder.use_cassette("TestInvoicePayment.get_invoice"): gen = InvoiceItemGenerator() items = [ gen.generate_title(title="dummy invoice item title"), gen.generate_description( description="dummy invoice item description"), gen.generate_lump_position(title="server hardware", net_total=2000) ] invoice_create = self.moco.Invoice.create( customer_id=customer.id, recipient_address="MY customer dummy address", created_date=date(2020, 1, 1), due_date=date(2021, 1, 1), service_period_from=date(2020, 1, 1), service_period_to=date(2020, 3, 1), title="TestInvoicePayment.get_invoice", tax=19, currency="EUR", items=items, ) return invoice_create.data
def test_create_default_status(self): generator = InvoiceItemGenerator() default_status = 'created' customer_id = 123456 recipient_address = "My customer..." created_date = "2018-09-17" due_date = "2018-10-16" service_period_from = date(2019, 10, 1) service_period_to = date(2019, 10, 31) title = "Invoice" tax = 8.0 currency = "CHF" items = [ generator.generate_title("this is the title"), generator.generate_separator() ] response = self.moco.Invoice.create(customer_id, recipient_address, created_date, due_date, service_period_from, service_period_to, title, tax, currency, items) data = response["data"] assert data["status"] == default_status
class TestInvoiceItemGenerator(object): def setup(self): self.generator = InvoiceItemGenerator() def test_generate_title(self): title_text = "this is the content" item = self.generator.generate_title(title_text) assert item["title"] == title_text assert item["type"] == "title" def test_generate_description(self): description_text = "this is the content" item = self.generator.generate_description(description_text) assert item["description"] == description_text assert item["type"] == "description" def test_generate_item(self): title = "this is the title" unit = "this is the unit" unit_price = 55 net_total = 44 quantity = 3 item = self.generator.generate_item(title, quantity=quantity, unit=unit, unit_price=unit_price, net_total=net_total) assert item["title"] == title assert item["unit"] == unit assert item["unit_price"] == unit_price assert item["quantity"] == quantity assert item["net_total"] == net_total def test_generate_separator(self): item = self.generator.generate_separator() assert item["type"] == "separator" def test_generate_separator(self): item = self.generator.generate_separator() assert item["type"] == "separator" def test_generate_subtotal(self): title = "zwischensumme" item = self.generator.generate_subtotal(title) assert item["type"] == "subtotal" assert item["title"] == title def test_generate_pagebreak(self): item = self.generator.generate_pagebreak() assert item["type"] == "page-break"
def test_create(self): customer = self.get_customer() with self.recorder.use_cassette("TestInvoice.test_create"): recipient_address = "My Customer Address 22" creation_date = date(2018, 9, 17) due_date = date(2018, 10, 16) title = "TestInvoice.test_create" tax = 8.0 currency = "EUR" service_from_date = date(2019, 12, 1) service_to_date = date(2019, 12, 31) item_generator = InvoiceItemGenerator() items = [ item_generator.generate_title(title="Hours"), item_generator.generate_description( description="Listing of all hours"), item_generator.generate_item(title="Service", quantity=2, unit="hours", unit_price=65, net_total=130) ] inv_create = self.moco.Invoice.create( customer_id=customer.id, recipient_address=recipient_address, created_date=creation_date, due_date=due_date, service_period_from=service_from_date, service_period_to=service_to_date, title=title, tax=tax, currency=currency, items=items) assert inv_create.response.status_code == 200 assert type(inv_create) is ObjectResponse assert inv_create.data.title == title assert inv_create.data.currency == currency assert inv_create.data.customer_id == customer.id assert inv_create.data.service_period_from == service_from_date.isoformat( ) assert inv_create.data.service_period_to == service_to_date.isoformat( ) assert inv_create.data.date == creation_date.isoformat() assert inv_create.data.due_date == due_date.isoformat() assert inv_create.data.recipient_address == recipient_address assert inv_create.data.tax == tax
def test_update_status(self): customer = self.get_customer() with self.recorder.use_cassette("TestInvoice.test_update_status"): recipient_address = "Mein Kunde\nHauptstrasse 1\n8000 Zürich" creation_date = date(2018, 9, 17) due_date = date(2018, 10, 16) title = "invoice" tax = 8.0 currency = "EUR" service_from_date = date(2019, 12, 1) service_to_date = date(2019, 12, 31) item_generator = InvoiceItemGenerator() items = [ item_generator.generate_title("Hours"), item_generator.generate_description("Listing of all hours"), item_generator.generate_item("Service", quantity=2, unit="hours", unit_price=65, net_total=130) ] inv_create = self.moco.Invoice.create( customer.id, recipient_address, creation_date, due_date, service_from_date, service_to_date, title, tax, currency, items ) inv_update = self.moco.Invoice.update_status( inv_create.data.id, InvoiceStatus.IGNORED ) inv_get = self.moco.Invoice.get(inv_create.data.id) assert inv_create.response.status_code == 200 assert inv_update.response.status_code == 204 assert inv_get.response.status_code == 200 assert isinstance(inv_create, JsonResponse) assert isinstance(inv_update, EmptyResponse) assert isinstance(inv_get, JsonResponse) assert inv_create.data.status == InvoiceStatus.CREATED assert inv_get.data.status == InvoiceStatus.IGNORED
def test_create(self): customer = self.get_customer() with self.recorder.use_cassette("TestInvoice.test_create"): recipient_address = "Mein Kunde\nHauptstrasse 1\n8000 Zürich" creation_date = date(2018, 9, 17) due_date = date(2018, 10, 16) title = "invoice" tax = 8.0 currency = "EUR" service_from_date = date(2019, 12, 1) service_to_date = date(2019, 12, 31) item_generator = InvoiceItemGenerator() items = [ item_generator.generate_title("Hours"), item_generator.generate_description("Listing of all hours"), item_generator.generate_item("Service", quantity=2, unit="hours", unit_price=65, net_total=130) ] inv_create = self.moco.Invoice.create( customer.id, recipient_address, creation_date, due_date, service_from_date, service_to_date, title, tax, currency, items ) assert inv_create.response.status_code == 200 assert isinstance(inv_create, JsonResponse) assert inv_create.data.title == "invoice" assert inv_create.data.currency == "EUR" assert inv_create.data.customer_id == customer.id assert inv_create.data.service_period_from == service_from_date.isoformat() assert inv_create.data.service_period_to == service_to_date.isoformat() assert inv_create.data.date == creation_date.isoformat() assert inv_create.data.due_date == due_date.isoformat() assert inv_create.data.recipient_address == recipient_address assert inv_create.data.tax == tax
def test_create_full(self): project = self.get_project() customer = self.get_customer() with self.recorder.use_cassette("TestInvoice.test_create_full"): recipient_address = "Mein Kunde\nHauptstrasse 1\n8000 Zürich" creation_date = date(2018, 9, 17) due_date = date(2018, 10, 16) title = "invoice" tax = 8.0 currency = "EUR" service_from_date = date(2019, 12, 1) service_to_date = date(2019, 12, 31) tags = ["Hosting", "Europe"] item_generator = InvoiceItemGenerator() items = [ item_generator.generate_title("Hours"), item_generator.generate_description("Listing of all hours"), item_generator.generate_item("Service", quantity=2, unit="hours", unit_price=65, net_total=130) ] change_add = InvoiceChangeAddress.CUSTOMER salutation = "salut" footer = "this is the footer" cash_discount_days = 200 cash_discount = 10.2 inv_create = self.moco.Invoice.create( customer.id, recipient_address, creation_date, due_date, service_from_date, service_to_date, title, tax, currency, items, status=InvoiceStatus.SENT, change_address=change_add, salutation=salutation, footer=footer, cash_discount_days=cash_discount_days, cash_discount=cash_discount, project_id=project.id, tags=tags ) assert inv_create.response.status_code == 200 assert isinstance(inv_create, JsonResponse) assert inv_create.data.title == "invoice" assert inv_create.data.currency == "EUR" assert inv_create.data.customer_id == customer.id assert inv_create.data.service_period_from == service_from_date.isoformat() assert inv_create.data.service_period_to == service_to_date.isoformat() assert inv_create.data.date == creation_date.isoformat() assert inv_create.data.due_date == due_date.isoformat() assert inv_create.data.recipient_address == recipient_address assert inv_create.data.tax == tax assert inv_create.data.project_id == project.id assert inv_create.data.footer == footer assert inv_create.data.cash_discount == cash_discount assert inv_create.data.cash_discount_days == cash_discount_days assert sorted(inv_create.data.tags) == sorted(tags)
def test_create(self): generator = InvoiceItemGenerator() customer_id = 123456 recipient_address = "My customer..." create_date = "2018-09-17" due_date = "2018-10-16" service_period_from = date(2019, 10, 1) service_period_to = date(2019, 10, 31) title = "Invoice" tax = 8.0 currency = "CHF" items = [ generator.generate_title("this is the title"), generator.generate_separator() ] status = "created" change_address = "customer" salutation = "salute" footer = "footer text" discount = 10 cash_discount = 2.5 cash_discount_days = 5 project_id = 654321 tags = ["Hosting", "Europe"] response = self.moco.Invoice.create( customer_id, recipient_address, create_date, due_date, service_period_from, service_period_to, title, tax, currency, items, status=status, change_address=change_address, salutation=salutation, footer=footer, discount=discount, cash_discount=cash_discount, cash_discount_days=cash_discount_days, project_id=project_id, tags=tags) data = response["data"] assert data["customer_id"] == customer_id assert data["recipient_address"] == recipient_address assert data["date"] == create_date assert data["due_date"] == due_date assert data["service_period_from"] == service_period_from.isoformat() assert data["service_period_to"] == service_period_to.isoformat() assert data["title"] == title assert data["tax"] == tax assert data["currency"] == currency assert data["items"] == items assert data["status"] == status assert data["change_address"] == change_address assert data["salutation"] == salutation assert data["footer"] == footer assert data["discount"] == discount assert data["cash_discount"] == cash_discount assert data["cash_discount_days"] == cash_discount_days assert data["project_id"] == project_id assert data["tags"] == tags assert response["method"] == "POST"