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_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_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_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 setUp(self): self.customer = Customer() self.order = Order(self.customer) self.pan = Product(name='Awsome pan', type=Physical()) self.netflix = Product(name='Video streaming service', type=Membership()) self.book = Product(name='Awsome book', type=Book()) self.show = Product(name='AC/DC Live in Argentina', type=Digital()) self.customer.email = '*****@*****.**'
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_pay_order_with_digital_item(self): expected_mail = Mail( address='*****@*****.**', subject='Purchase details', body=( 'Hello Asd\n' 'You have purchased "Need for Acceleration"\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_service.pay(order, credit_card) assert expected_mail in EmailClient.queue assert 'ABC1234' in DiscountCodes.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 ======")
foolano = Customer(customerAttributes) book = Product(name='My first book', type='book', value=10.50) smartphone_charger = Product(name='Smartphone Charger', type='physical', value=21.30) wineMembership = Product(name='Wine Membership', type='membership', value=10.00) babySharkVideo = Product(name='Baby Shark Video', type='digital', value=13.40) cardsMembership = Product(name='Cards Membership', type='membership', value=10.20) myOrder = Order(foolano) myOrder.add_product(book) myOrder.add_product(babySharkVideo) myOrder.add_product(wineMembership) myOrder.add_product(smartphone_charger) myOrder.add_product(cardsMembership) paymentAttributes = dict( order=myOrder, payment_method=CreditCard.fetch_by_hashed('43567890-987654367')) payment = Payment(paymentAttributes) payment.pay() myOrder.ship(payment)
def setUp(self): self.datetime = patch('order_service.datetime').start() self.order = Order(Customer('Antonio'))
class TestOrder(TestCase): def setUp(self): self.datetime = patch('order_service.datetime').start() self.order = Order(Customer('Antonio')) def tearDown(self): LabelPrinter.reset() EmailClient.reset() Subscriptions.reset() DiscountCodes.reset() patch.stopall() def test_add_a_single_product(self): self.order.add_product( Product(name='Product 1', type=ProductType.DIGITAL, price=10.0), 1) assert len(self.order.items) == 1 def test_add_multiple_products(self): self.order.add_product( Product(name='Product 1', type=ProductType.DIGITAL, price=10.0), 1) self.order.add_product( Product(name='Product 2', type=ProductType.BOOK, price=11.0), 1) self.order.add_product( Product(name='Product 3', type=ProductType.PHYSICAL, price=12.0), 1) assert len(self.order.items) == 3 def test_add_two_of_a_single_product(self): self.order.add_product(Product(name='Product 1', type=ProductType.DIGITAL, price=10.0), quantity=2) assert len(self.order.items) == 1 def test_add_many_products_with_many_quantities(self): self.order.add_product(Product(name='Product 1', type=ProductType.DIGITAL, price=10.0), quantity=1) self.order.add_product(Product(name='Product 2', type=ProductType.DIGITAL, price=10.0), quantity=3) self.order.add_product(Product(name='Product 3', type=ProductType.PHYSICAL, price=12.0), quantity=10) assert len(self.order.items) == 3 def test_total_amount(self): self.order.add_product(Product(name='Product 1', type=ProductType.DIGITAL, price=10), quantity=2) self.order.add_product(Product(name='Product 2', type=ProductType.DIGITAL, price=15), quantity=2) assert self.order.total_amount == 50 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_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_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_pay_order_with_book_item(self): expected_label = ('Name: Manuela\n' 'ZipCode: 46100\n' '** Tax exempt **\n') credit_card = CreditCard.fetch_by_hashed('01234-4321') order = Order(Customer('Manuela'), Address('46100')) order.add_product(Product('Untitled', ProductType.BOOK, price=20), quantity=10) order_service.pay(order, credit_card) assert expected_label in LabelPrinter.queue def test_pay_order_with_digital_item(self): expected_mail = Mail( address='*****@*****.**', subject='Purchase details', body=( 'Hello Asd\n' 'You have purchased "Need for Acceleration"\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_service.pay(order, credit_card) 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)
from bootstrap import Costomer, Product, Order, Payment, CreditCard, Shipping foolano = Costomer("William", "*****@*****.**") phone = Product(name="Xiaomi Redmi 7", type="physical") phone_order = Order(foolano) phone_order.add_product(phone) attributes = dict( order=phone_order, payment_method=CreditCard.fetch_by_hashed('43567890-987654367')) payment_phone = Payment(attributes=attributes) payment_phone.pay() if payment_phone.is_paid(): print(" ***** Pagamento realizado ******* ") shipping = Shipping(payment_phone) shipping.ship() else: print(" ======= Falaha no pagamento ======")