def test_it_orders_a_digital_media_item(self): expected_mail = Mail( address='*****@*****.**', subject='Purchase details', body=( 'Hello Anthonio\n' 'You have purchased "Kung Fury"\n' 'Use the following code for a 10% discount in the next order:\n' 'ABC1234\n' ) ) customer = Customer('Anthonio', email='*****@*****.**') credit_card = CreditCard.fetch_by_hashed('43567890-987654367') item = Product(name='Kung Fury', type=ProductType.DIGITAL, price=15.0) order = Order(customer, Address('46100')) order.add_product(item, 2) order_service.pay(order, payment_method=credit_card) assert order.is_paid assert order.customer == customer assert order.items[0].product == item assert order.payment.amount == 30.0 assert expected_mail in EmailClient.queue assert 'ABC1234' in DiscountCodes.by_customer(customer)
def test_pay_order_with_digital_items(self): expected_mail = Mail( address='*****@*****.**', subject='Purchase details', body=( 'Hello Asd\n' 'You have purchased "Need for Acceleration", "Fogata Artica"\n' 'Use the following code for a 10% discount in the next order:\n' 'ABC1234\n')) customer = Customer('Asd', '*****@*****.**') credit_card = CreditCard.fetch_by_hashed('01234-4321') order = Order(customer) order.add_product(Product('Need for Acceleration', ProductType.DIGITAL, price=20), quantity=1) order.add_product(Product('Fogata Artica', ProductType.DIGITAL, price=30), quantity=1) order_service.pay(order, credit_card) assert expected_mail in EmailClient.queue assert 'ABC1234' in DiscountCodes.by_customer(customer)
def test_pay_order_with_physical_item(self): expected_label = ('Name: Manuela\n' 'ZipCode: 46100\n') credit_card = CreditCard.fetch_by_hashed('01234-4321') order = Order(Customer('Manuela'), Address('46100')) order.add_product(Product('Untitled', ProductType.PHYSICAL, price=20), quantity=10) order_service.pay(order, credit_card) assert expected_label in LabelPrinter.queue
def test_pay_order(self): self.datetime.now.return_value = datetime(2020, 1, 1) credit_card = CreditCard.fetch_by_hashed('01234-4321') self.order.add_product(Product('Untitled', ProductType.BOOK, price=20), quantity=10) order_service.pay(self.order, payment_method=credit_card) assert self.order.is_paid assert self.order.payment.paid_at == datetime(2020, 1, 1) assert self.order.payment.amount == 200 assert self.order.payment.invoice == Invoice(self.order.address, self.order.address)
def test_compra_item_fisico(self): self.order.add_product(self.pan) self.pan.type.shipping(self.order) # Verifica se o produto possui etiqueta de entrega preenchida self.assertEqual(self.order.address, self.pan.type.label) attributes = dict( order=self.order, payment_method=CreditCard.fetch_by_hashed('43567890-987654367')) payment = Payment(attributes=attributes) payment.pay() self.assertTrue(payment.is_paid())
def test_compra_assinatura_de_servico(self): self.order.add_product(self.netflix) # Possui email cadastrado para envio de aviso? self.assertIsNotNone(self.customer.email) self.netflix.type.shipping(self.order) # Tornou o assinante ativo? self.assertTrue(self.netflix.type.is_membership_active()) attributes = dict( order=self.order, payment_method=CreditCard.fetch_by_hashed('43567890-987654367')) payment = Payment(attributes=attributes) payment.pay() # Está pago? self.assertTrue(payment.is_paid())
def test_it_orders_a_physical_item(self): expected_shipping_label = ( 'Name: Antonio\n' 'ZipCode: 46100\n' ) customer = Customer('Antonio') credit_card = CreditCard.fetch_by_hashed('43567890-987654367') item = Product(name='Awesome bottle', type=ProductType.PHYSICAL, price=15.0) order = Order(customer, Address('46100')) order.add_product(item, 1) order_service.pay(order, payment_method=credit_card) assert order.is_paid assert order.customer == customer assert order.items[0].product == item assert order.payment.amount == 15.0 assert expected_shipping_label in LabelPrinter.queue
def test_compra_uma_midia_digital(self): self.order.add_product(self.show) # Possui email cadastrado para envio de aviso? self.assertIsNotNone(self.customer.email) self.show.type.shipping(self.order) # Adicionou voucher ao pedido? # Somente uma vez self.assertEqual(self.order.total_amount(), 0) attributes = dict( order=self.order, payment_method=CreditCard.fetch_by_hashed('43567890-987654367')) payment = Payment(attributes=attributes) payment.pay() # Está pago? self.assertTrue(payment.is_paid())
def test_compra_de_um_livro(self): self.order.add_product(self.book) self.book.type.shipping(self.order) # Adicionou o aviso de isenção? self.assertEqual( self.book.type.label, str(self.order.address) + ' Item isento de impostos conforme disposto na Constituição Art. 150, VI, d.' ) attributes = dict( order=self.order, payment_method=CreditCard.fetch_by_hashed('43567890-987654367')) payment = Payment(attributes=attributes) payment.pay() # Está pago? self.assertTrue(payment.is_paid())
def test_it_orders_a_book(self): expected_shipping_label = ( 'Name: Foolano\n' 'ZipCode: 12345\n' '** Tax exempt **\n' ) foolano = Customer('Foolano') foolanos_credit_card = CreditCard.fetch_by_hashed('43567890-987654367') book = Product(name='Awesome book', type=ProductType.BOOK, price=10.0) book_order = Order(foolano, Address('12345')) book_order.add_product(book, 1) order_service.pay(book_order, payment_method=foolanos_credit_card) assert book_order.is_paid assert book_order.customer == foolano assert book_order.items[0].product == book assert book_order.payment.amount == 10.0 assert expected_shipping_label in LabelPrinter.queue
def test_pay_order_with_subscription(self): expected_mail = Mail( address='*****@*****.**', subject='24/7 sl terminal show subscription', body= ('Hello Ofelia\n' 'You have been subscribed to "24/7 sl terminal show" for 12 months\n' )) customer = Customer('Ofelia', '*****@*****.**') credit_card = CreditCard.fetch_by_hashed('01234-4321') order = Order(customer, Address('42100')) order.add_product(Product('24/7 sl terminal show', ProductType.MEMBERSHIP, price=20), quantity=12) order_service.pay(order, credit_card) assert expected_mail in EmailClient.queue assert '24/7 sl terminal show' in Subscriptions.by_customer(customer)
def test_it_orders_a_service_subscription_item(self): expected_mail = Mail( address='*****@*****.**', subject='Netflix subscription', body=( 'Hello Cuenta Puertas\n' 'You have been subscribed to "Netflix" for 2 months\n' ) ) customer = Customer('Cuenta Puertas', email='*****@*****.**') credit_card = CreditCard.fetch_by_hashed('43567890-987654367') item = Product(name='Netflix', type=ProductType.MEMBERSHIP, price=15.0) order = Order(customer, Address('46100')) order.add_product(item, 2) order_service.pay(order, payment_method=credit_card) assert order.is_paid assert order.customer == customer assert order.items[0].product == item assert order.payment.amount == 30.0 assert expected_mail in EmailClient.queue assert 'Netflix' in Subscriptions.by_customer(customer)
from bootstrap import Costomer, Product, Order, Payment, CreditCard, Shipping # Book Example (build new payments if you need to properly test it) foolano = Costomer("William", "*****@*****.**") book = Product(name='Awesome book', type='book') book_order = Order(foolano) book_order.add_product(book) attributes = dict( order=book_order, payment_method=CreditCard.fetch_by_hashed('43567890-987654367')) payment_book = Payment(attributes=attributes) payment_book.pay() if payment_book.is_paid(): print(" ***** Pagamento realizado ******* ") shipping = Shipping(payment_book) shipping.ship() else: print(" ======= Falaha no pagamento ======")