Esempio n. 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)())
Esempio n. 2
0
    def test_make_params(self):
        # creating dataaccess
        email = '*****@*****.**'
        token = '4567890oiuytfgh'
        reference0 = ItemReferenceMock()
        reference1 = ItemReferenceMock()
        owner = PaymentOwner()
        ndb.put_multi([reference0, reference1, owner])
        items = [
            PagSegItem(description='Python Course',
                       price=Decimal('120'),
                       quantity=1,
                       reference=reference0.key),
            PagSegItem(description='Another Python Course',
                       price=Decimal('240'),
                       quantity=2,
                       reference=reference1.key)
        ]
        ndb.put_multi(items)
        validate_address_cmd = pagseguro_facade.validate_address_cmd(
            'Rua 1', '2', 'meu bairro', '12345678', 'São Paulo', 'SP',
            'apto 4')

        client_name = 'Jhon Doe'
        client_email = '*****@*****.**'

        redirect_url = 'https://mystore.com/pagseguro'
        payment_reference = '1234'
        dct = _make_params(email, token, redirect_url, client_name,
                           client_email, payment_reference, items,
                           validate_address_cmd.form, 'BRL')
        self.maxDiff = None
        self.assertDictEqual(
            _build_success_params(reference0.key.id(), reference1.key.id()),
            dct)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
    def test_save_item_arcs_command(self):
        command_with_item_forms = Mock()
        access_data = CreateOrUpdateAccessData('*****@*****.**', 'abc1234')()

        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

        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

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

        save_payment_to_items_arcs_cmd = SavePaymentToItemsArcs()
        CommandSequential(command_with_item_forms,
                          save_payment_to_items_arcs_cmd).execute()

        self.assertListEqual(items, SearchItems(payment)())
        self.assertListEqual(items, save_payment_to_items_arcs_cmd.items)

        # Data used for sequential commands
        self.assertEqual('*****@*****.**',
                         save_payment_to_items_arcs_cmd.access_data.email)
        self.assertEqual('abc1234',
                         save_payment_to_items_arcs_cmd.access_data.token)
        self.assertEqual(save_payment_to_items_arcs_cmd.address_form,
                         address_form_mock)
        self.assertEqual(save_payment_to_items_arcs_cmd.client_form,
                         client_form_mock)
Esempio n. 6
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)
Esempio n. 7
0
    def test_success(self, UrlFetchClassMock):
        # Mocking pagseguro Fetch
        UrlFetchClassMock.return_value = _build_mock()

        # Mocking previous command
        data_cmd_mock = Mock()
        data_cmd_mock.access_data.email = '*****@*****.**'
        data_cmd_mock.access_data.token = '4567890oiuytfgh'
        reference0 = ItemReferenceMock()
        reference1 = ItemReferenceMock()
        items = [
            PagSegItem(description='Python Course',
                       price=Decimal('120'),
                       quantity=1,
                       reference=reference0.key),
            PagSegItem(description='Another Python Course',
                       price=Decimal('240'),
                       quantity=2,
                       reference=reference1.key)
        ]
        ndb.put_multi(items)
        data_cmd_mock.items = items
        data_cmd_mock.client_form = ValidateClientCmd(email='*****@*****.**',
                                                      name='Jhon Doe').form
        data_cmd_mock.address_form = pagseguro_facade.validate_address_cmd(
            'Rua 1', '2', 'meu bairro', '12345678', 'São Paulo', 'SP',
            'apto 4').form

        payment = PagSegPayment()
        payment.put()
        data_cmd_mock.result = payment

        contact_pagseguro_cmd = ContactPagseguro('https://store.com/pagseguro')
        CommandSequential(data_cmd_mock, contact_pagseguro_cmd).execute()

        self.assertEqual(payment, contact_pagseguro_cmd.result)
        self.assertEqual(payment.status, STATUS_SENT_TO_PAGSEGURO)
        self.assertEqual(
            contact_pagseguro_cmd.checkout_code, _SUCCESS_PAGSEGURO_CODE,
            'Should have the code extracted from xml _PAGSEGURO_DETAIL_XML')
        self.assertIsNone(payment.code)
Esempio n. 8
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)
Esempio n. 9
0
 def create_item_cmd(item):
     return _SimpleSave(
         PagSegItem(description=item['description'],
                    price=Decimal(item['amount']),
                    quantity=int(item['quantity'])))