Ejemplo n.º 1
0
    def test_save_pagseguro_data(self):
        access_data = CreateOrUpdateAccessData('*****@*****.**', 'abc1234')()
        command_with_item_forms = Mock()
        command_with_item_forms.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))]
        address_form_mock = Mock()
        client_form_mock = Mock()
        command_with_item_forms.address_form = address_form_mock
        command_with_item_forms.client_form = client_form_mock
        command_with_item_forms.access_data = access_data

        save_pagseguro_data_cmd = SavePagseguroDataCmd()
        CommandSequential(command_with_item_forms, save_pagseguro_data_cmd).execute()

        items = PagSegItem.query().fetch()
        self.assertEqual(2, len(items))
        self.assertEqual(set(i.key for i in items), set(i.key for i in save_pagseguro_data_cmd.items))
        payment = PagSegPayment.query().get()
        self.assertIsNotNone(payment)
        self.assertEqual(payment, save_pagseguro_data_cmd.result)
        self.assertEqual(Decimal('106.95'), save_pagseguro_data_cmd.result.total,
                         'Total should be the some of the total of items')
        self.assertEqual('*****@*****.**', save_pagseguro_data_cmd.access_data.email)
        self.assertEqual('abc1234', save_pagseguro_data_cmd.access_data.token)

        # Data used for sequential commands
        self.assertEqual(save_pagseguro_data_cmd.address_form, address_form_mock)
        self.assertEqual(save_pagseguro_data_cmd.client_form, client_form_mock)
Ejemplo n.º 2
0
 def test_save_items(self):
     command_with_item_forms = Mock()
     command_with_item_forms.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))]
     save_items_cmd = SaveItemCmd()
     CommandSequential(command_with_item_forms, save_items_cmd).execute()
     items = PagSegItem.query().fetch()
     self.assertEqual(2, len(items))
     self.assertEqual(items, save_items_cmd.result)
Ejemplo n.º 3
0
 def test_save_items(self):
     command_with_item_forms = Mock()
     command_with_item_forms.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))
     ]
     save_items_cmd = SaveItemCmd()
     CommandSequential(command_with_item_forms, save_items_cmd).execute()
     items = PagSegItem.query().fetch()
     self.assertEqual(2, len(items))
     self.assertEqual(items, save_items_cmd.result)
Ejemplo n.º 4
0
    def test_save_pagseguro_data(self):
        access_data = CreateOrUpdateAccessData('*****@*****.**', 'abc1234')()
        command_with_item_forms = Mock()
        command_with_item_forms.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))
        ]
        address_form_mock = Mock()
        client_form_mock = Mock()
        command_with_item_forms.address_form = address_form_mock
        command_with_item_forms.client_form = client_form_mock
        command_with_item_forms.access_data = access_data

        save_pagseguro_data_cmd = SavePagseguroDataCmd()
        CommandSequential(command_with_item_forms,
                          save_pagseguro_data_cmd).execute()

        items = PagSegItem.query().fetch()
        self.assertEqual(2, len(items))
        self.assertEqual(set(i.key for i in items),
                         set(i.key for i in save_pagseguro_data_cmd.items))
        payment = PagSegPayment.query().get()
        self.assertIsNotNone(payment)
        self.assertEqual(payment, save_pagseguro_data_cmd.result)
        self.assertEqual(Decimal('106.95'),
                         save_pagseguro_data_cmd.result.total,
                         'Total should be the some of the total of items')
        self.assertEqual('*****@*****.**',
                         save_pagseguro_data_cmd.access_data.email)
        self.assertEqual('abc1234', save_pagseguro_data_cmd.access_data.token)

        # Data used for sequential commands
        self.assertEqual(save_pagseguro_data_cmd.address_form,
                         address_form_mock)
        self.assertEqual(save_pagseguro_data_cmd.client_form, client_form_mock)