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)