def test_pdf(self): project = self.get_project() with self.recorder.use_cassette("TestOffer.test_pdf"): gen = OfferItemGenerator() items = [ gen.generate_title( title="title" ), gen.generate_lump_position( title="pos 1", net_total=200 ) ] offer_create = self.moco.Offer.create( deal_id=None, project_id=project.id, recipient_address="My Customer Address 24", creation_date=date(2020, 1, 1), due_date=date(2021, 1, 1), title="TestOffer.test_pdf_create", tax=21, currency="EUR", items=items ) offer_pdf = self.moco.Offer.pdf( offer_id=offer_create.data.id ) assert offer_create.response.status_code == 201 assert offer_pdf.response.status_code == 200 assert type(offer_pdf) is FileResponse
def test_create_with_project(self): project = self.get_project() with self.recorder.use_cassette("TestOffer.test_create_with_project"): rec_address = "this is the recpipient address" creation_date = date(2020, 1, 2) due_date = date(2021, 1, 1) title = "offer created from deal" tax = 21.5 currency = "EUR" gen = OfferItemGenerator() items = [ gen.generate_title("offer from project title"), gen.generate_lump_position("misc", 2000) ] offer_create = self.moco.Offer.create(None, project.id, rec_address, creation_date, due_date, title, tax, currency, items) assert offer_create.response.status_code == 201 assert isinstance(offer_create, JsonResponse) assert offer_create.data.project.id == project.id assert offer_create.data.date == creation_date.isoformat() assert offer_create.data.title == title assert offer_create.data.tax == tax assert offer_create.data.currency == currency
def test_create_full(self): project = self.get_project() contact = self.get_contact() deal = self.get_deal() with self.recorder.use_cassette("TestOffer.test_create_full"): rec_address = "My Customer Address 34" creation_date = date(2020, 1, 2) due_date = date(2021, 1, 1) title = "TestOffer.test_create_full" tax = 21.5 currency = "EUR" salutation = "salute" footer = "footer" discount = 20 tags = ["test1", "test2"] gen = OfferItemGenerator() items = [ gen.generate_title( title="offer from project title" ), gen.generate_lump_position( title="misc", net_total=2000 ) ] offer_create = self.moco.Offer.create( deal_id=deal.id, project_id=project.id, recipient_address=rec_address, creation_date=creation_date, due_date=due_date, title=title, tax=tax, currency=currency, items=items, salutation=salutation, footer=footer, discount=discount, contact_id=contact.id, tags=tags ) assert offer_create.response.status_code == 201 assert type(offer_create) is ObjectResponse assert offer_create.data.project.id == project.id assert offer_create.data.date == creation_date.isoformat() assert offer_create.data.title == title assert offer_create.data.tax == tax assert offer_create.data.currency == currency assert offer_create.data.salutation == salutation assert offer_create.data.footer == footer assert offer_create.data.discount == discount assert sorted(offer_create.data.tags) == sorted(tags)
def test_create_with_all_items(self): deal = self.get_deal() user = self.get_user() with self.recorder.use_cassette( "TestOffer.test_create_with_all_items"): gen = OfferItemGenerator() items = [ gen.generate_title("this is the title"), gen.generate_description("This is the first description"), gen.generate_detail_postion("support", 1, "h", 65), gen.generate_lump_position("server hardware", 200), gen.generate_subtotal("subtotal position"), gen.generate_detail_postion("special support", 3, "h", 90), gen.generate_pagebreak() ] offer_create = self.moco.Offer.create( deal.id, None, "this is the recipient address", date(2020, 1, 1), date(2021, 1, 1), "offer title", 19, "EUR", items) assert offer_create.response.status_code == 201 assert isinstance(offer_create, JsonResponse) assert len(offer_create.data.items) == 7
def test_update_status(self): project = self.get_project() with self.recorder.use_cassette("TestOffer.test_update_status"): offer_status = OfferStatus.ACCEPTED gen = OfferItemGenerator() items = [ gen.generate_title( title="title" ), gen.generate_lump_position( title="pos 1", net_total=200 ) ] offer_create = self.moco.Offer.create( deal_id=None, project_id=project.id, recipient_address="My Customer Address 44", creation_date=date(2020, 1, 1), due_date=date(2021, 1, 1), title="TestOffer.test_update_status_create", tax=21, currency="EUR", items=items ) offer_update_status = self.moco.Offer.update_status( offer_id=offer_create.data.id, status=offer_status ) offer_get = self.moco.Offer.get( offer_id=offer_create.data.id ) assert offer_create.response.status_code == 201 assert offer_update_status.response.status_code == 204 assert offer_get.response.status_code == 200 assert type(offer_create) is ObjectResponse assert type(offer_update_status) is EmptyResponse assert type(offer_get) is ObjectResponse assert offer_create.data.status == OfferStatus.CREATED assert offer_get.data.status == offer_status
def test_create_full(self): project = self.get_project() contact = self.get_contact() deal = self.get_deal() with self.recorder.use_cassette("TestOffer.test_create_full"): rec_address = "this is the recpipient address" creation_date = date(2020, 1, 2) due_date = date(2021, 1, 1) title = "offer created from deal" tax = 21.5 currency = "EUR" salutation = "salute" footer = "footer" discount = 20 gen = OfferItemGenerator() items = [ gen.generate_title("offer from project title"), gen.generate_lump_position("misc", 2000) ] offer_create = self.moco.Offer.create(deal.id, project.id, rec_address, creation_date, due_date, title, tax, currency, items, salutation=salutation, footer=footer, discount=discount, contact_id=contact.id) assert offer_create.response.status_code == 201 assert isinstance(offer_create, JsonResponse) assert offer_create.data.project.id == project.id assert offer_create.data.date == creation_date.isoformat() assert offer_create.data.title == title assert offer_create.data.tax == tax assert offer_create.data.currency == currency assert offer_create.data.salutation == salutation assert offer_create.data.footer == footer assert offer_create.data.discount == discount
def test_create_with_all_items(self): deal = self.get_deal() with self.recorder.use_cassette("TestOffer.test_create_with_all_items"): gen = OfferItemGenerator() items = [ gen.generate_title( title="this is the title" ), gen.generate_description( description="This is the first description" ), gen.generate_detail_position( title="support", quantity=1, unit="h", unit_price=65 ), gen.generate_lump_position( title="server hardware", net_total=200 ), gen.generate_subtotal( title="subtotal position" ), gen.generate_detail_position( title="special support", quantity=3, unit="h", unit_price=90 ), gen.generate_pagebreak() ] offer_create = self.moco.Offer.create( deal_id=deal.id, project_id=None, recipient_address="My Customer Address 43", creation_date=date(2020, 1, 1), due_date=date(2021, 1, 1), title="TestOffer.test_create_with_all_items", tax=19, currency="EUR", items=items ) assert offer_create.response.status_code == 201 assert type(offer_create) is ObjectResponse assert len(offer_create.data.items) == 7
def test_create_with_company(self): company = self.get_customer() with self.recorder.use_cassette("TestOffer.test_create_with_company"): rec_address = "My Customer Address 34" creation_date = date(2020, 1, 2) due_date = date(2021, 1, 1) title = "TestOffer.test_create_company" tax = 21.5 currency = "EUR" gen = OfferItemGenerator() items = [ gen.generate_title( title="offer from company title" ), gen.generate_lump_position( title="misc", net_total=2000 ) ] offer_create = self.moco.Offer.create( deal_id=None, company_id=company.id, recipient_address=rec_address, creation_date=creation_date, due_date=due_date, title=title, tax=tax, currency=currency, items=items ) assert offer_create.response.status_code == 201 assert type(offer_create) is ObjectResponse assert offer_create.data.company.id == company.id assert offer_create.data.date == creation_date.isoformat() assert offer_create.data.title == title assert offer_create.data.tax == tax assert offer_create.data.currency == currency
def test_pdf(self): project = self.get_project() with self.recorder.use_cassette("TestOffer.test_pdf"): gen = OfferItemGenerator() items = [ gen.generate_title("title"), gen.generate_lump_position("pos 1", 200) ] offer_create = self.moco.Offer.create(None, project.id, "rec address", date(2020, 1, 1), date(2021, 1, 1), "title", 21, "EUR", items) offer_pdf = self.moco.Offer.pdf(offer_create.data.id) assert offer_create.response.status_code == 201 assert offer_pdf.response.status_code == 200 assert isinstance(offer_pdf, FileResponse)
def test_create_from_deal(self): deal = self.get_deal() with self.recorder.use_cassette("TestOffer.test_create_from_deal"): rec_address = "My Customer Address 34" creation_date = date(2020, 1, 2) due_date = date(2021, 1, 1) title = "TestOffer.test_create_from_deal" tax = 21.5 currency = "EUR" gen = OfferItemGenerator() items = [ gen.generate_title( title="This is the title of the offer" ), gen.generate_description( description="this is the description" ), gen.generate_item( title="MailChimp Setup", quantity=1, unit="h", unit_price=100.0, net_total=400 ), gen.generate_item( title="On-Site Support", quantity=20, unit_price=20, unit="h", net_total=400, optional=True ) ] offer_create = self.moco.Offer.create( deal_id=deal.id, project_id=None, recipient_address=rec_address, creation_date=creation_date, due_date=due_date, title=title, tax=tax, currency=currency, items=items ) assert offer_create.response.status_code == 201 assert type(offer_create) is ObjectResponse assert offer_create.data.deal.id == deal.id assert offer_create.data.date == creation_date.isoformat() assert offer_create.data.due_date == due_date.isoformat() assert offer_create.data.title == title assert offer_create.data.tax == tax assert offer_create.data.currency == currency
def test_get(self): deal = self.get_deal() user = self.get_user() with self.recorder.use_cassette("TestOffer.test_get"): rec_address = "this is the recpipient address" creation_date = date(2020, 1, 2) due_date = date(2021, 1, 1) title = "offer created from deal" tax = 21.5 currency = "EUR" gen = OfferItemGenerator() items = [ gen.generate_title("This is the title of the offer"), gen.generate_description("this is the description"), gen.generate_item("MailChimp Einrichtung", quantity=1, unit="h", unit_price=100.0, net_total=400), gen.generate_item("On Site Support", quantity=20, unit_price=20, unit="h", net_total=400, optional=True) ] offer_create = self.moco.Offer.create(deal.id, None, rec_address, creation_date, due_date, title, tax, currency, items) offer_get = self.moco.Offer.get(offer_create.data.id) assert offer_create.response.status_code == 201 assert offer_get.response.status_code == 200 assert isinstance(offer_create, JsonResponse) assert isinstance(offer_get, JsonResponse) assert offer_get.data.deal.id == deal.id assert offer_get.data.date == creation_date.isoformat() assert offer_get.data.due_date == due_date.isoformat() assert offer_get.data.title == title assert offer_get.data.tax == tax assert offer_get.data.currency == currency
def setup(self): self.generator = OfferItemGenerator()
class TestOfferItemGenerator(object): def setup(self): self.generator = OfferItemGenerator() 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_detail_item(self): title = "this is the title" unit = "h" unit_price = 25 quantity = 3 item = self.generator.generate_detail_postion(title, quantity, unit, unit_price) assert item["type"] == "item" assert item["title"] == title assert item["unit"] == unit assert item["unit_price"] == unit_price assert item["quantity"] == quantity def test_generate_lump_item(self): title = "this is the title" net_total = 300 item = self.generator.generate_lump_position(title, net_total) assert item["type"] == "item" assert item["title"] == title assert item["net_total"] == net_total 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"