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)
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)
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)
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)
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']])