Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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)