Beispiel #1
0
    def test_save_payment_arcs_command_mocked(self):
        command_with_item_forms = Mock()
        items = [
            PagSegItem(description='Python Birds',
                       price=Decimal('18.99'),
                       quantity=3),
            PagSegItem(description='Objetos Pythônicos',
                       price=Decimal('24.99'),
                       quantity=2,
                       reference=ndb.Key(PagSegItem, 10))
        ]
        command_with_item_forms.items = items

        ndb.put_multi(items)
        payment = mommy.save_one(PagSegPayment)
        command_with_item_forms.result = payment

        payment_owner = mommy.save_one(Node)
        save_payment_arcs_cmd = SavePaymentArcsCmd(payment_owner)
        CommandSequential(command_with_item_forms,
                          save_payment_arcs_cmd).execute()

        self.assertEqual(payment,
                         pagseguro_facade.search_payments(payment_owner)()[0])

        logs = SearchLogs(payment)()
        self.assertEqual(1, len(logs))
        self.assertEqual(STATUS_CREATED, logs[0].status)

        self.assertListEqual(items, SearchItems(payment)())
    def test_save_payment_arcs_command_mocked(self):
        command_with_item_forms = Mock()
        items = [PagSegItem(description='Python Birds', price=Decimal('18.99'), quantity=3),
                 PagSegItem(description='Objetos Pythônicos', price=Decimal('24.99'), quantity=2,
                            reference=ndb.Key(PagSegItem, 10))]
        command_with_item_forms.items = items

        ndb.put_multi(items)
        payment = mommy.save_one(PagSegPayment)
        command_with_item_forms.result = payment

        payment_owner = mommy.save_one(Node)
        save_payment_arcs_cmd = SavePaymentArcsCmd(payment_owner)
        CommandSequential(command_with_item_forms, save_payment_arcs_cmd).execute()

        self.assertEqual(payment, pagseguro_facade.search_payments(payment_owner)()[0])

        logs = SearchLogs(payment)()
        self.assertEqual(1, len(logs))
        self.assertEqual(STATUS_CREATED, logs[0].status)

        self.assertListEqual(items, SearchItems(payment)())
Beispiel #3
0
    def test_succesfull_call(self, UrlFetchCommandMock):
        # Mocking call to pagseguro
        UrlFetchCommandMock.return_value = _build_mock()

        # Before making a payment, email and token must be saved
        pagseguro_facade.create_or_update_access_data_cmd('*****@*****.**', 'abc123')()

        # Creating the address validation cmd that will be used on payment
        validate_address_cmd = pagseguro_facade.validate_address_cmd(complement='apto 4', state='SP',
                                                                     town='São Paulo',
                                                                     postalcode='12345-678',
                                                                     quarter='Jardins', number='2',
                                                                     street='Av Vicente de Carvalho')

        # Creating items included on payment
        class ProductMock(Node):
            pass

        product1 = ProductMock()
        product2 = ProductMock()
        ndb.put_multi([product1, product2])
        validate_item_cmds = [pagseguro_facade.validate_item_cmd('Python Birds', '18.99', '1', product1.key),
                              pagseguro_facade.validate_item_cmd('App Engine', '45.58', '2', product2.key)]

        # Creating payment owner. User or other mother can be payment owner

        class UserMock(Node):
            name = ndb.StringProperty(required=True)
            email = ndb.StringProperty(required=True)

        owner = UserMock(name='Renzo Nuccitelli', email='*****@*****.**')
        owner.put()

        # Generating payment

        payment_cmd = pagseguro_facade.generate_payment('http://somedomain.com/receive',
                                                        owner.name,
                                                        owner.email,
                                                        owner,
                                                        validate_address_cmd, *validate_item_cmds)

        payment = payment_cmd()

        # Payment assertions
        self.assertEqual(_SUCCESS_PAGSEGURO_CODE, payment_cmd.checkout_code)
        self.assertEqual(STATUS_SENT_TO_PAGSEGURO, payment.status)
        self.assertEqual(Decimal('110.15'), payment.total, "Should be the sum of item's totals")

        # Owner assertion

        owner_payments = pagseguro_facade.search_payments(owner, relations=['owner', 'pay_items', 'logs'])()
        self.assertListEqual([payment], owner_payments)
        payment = owner_payments[0]
        # Log assertions

        statuses = [log.status for log in payment.logs]
        self.assertEqual([STATUS_CREATED, STATUS_SENT_TO_PAGSEGURO], statuses)

        # Items assertions
        self.assertEqual(2, len(payment.pay_items))
        self.assertIsInstance(payment.pay_items[0], PagSegItem)

        # Dictionary genartion assertions

        # Items Assertions

        form = pagseguro_facade.payment_form()
        payment_dct = form.fill_with_model(payment)

        items = payment.pay_items
        items_dcts = [{u'id': items[0].key.id(), 'price': u'18.99', 'description': u'Python Birds',
                       'reference': items[0].reference.id(), 'quantity': u'1',
                       'total': '18.99'},
                      {u'id': items[1].key.id(), 'price': u'45.58', 'description': u'App Engine',
                       'reference': items[1].reference.id(), 'quantity': u'2',
                       'total': '91.16'}]
        self.assertListEqual(items_dcts, payment_dct['pay_items'])


        # Log Assertions
        self.assertListEqual([STATUS_CREATED, STATUS_SENT_TO_PAGSEGURO], [log['status'] for log in payment_dct['logs']])