def test_get_button(self): account = Account(Client(api_key, api_secret)) account.id = 'fakeaccountid' button_code = 'fakebuttoncode' def server_response(request, uri, headers): self.assertEqual(request.body.decode(), '') return (200, headers, json.dumps(data)) hp.register_uri(hp.GET, re.compile('.*'), body=server_response) data = {'button': 'not-the-right-type'} with self.assertRaises(UnexpectedDataFormatError): account.get_button(button_code) data = {'missing-button-key': True} with self.assertRaises(UnexpectedDataFormatError): account.get_button(button_code) data = {'button': {'code': button_code}} button = account.get_button(button_code) self.assertIsInstance(button, Button) data = {'badkey': 'bar', 'success': True} with self.assertRaises(UnexpectedDataFormatError): account.get_address() data = { 'address': 'a', 'callback_url': None, 'label': None, 'success': True } address = account.get_address() self.assertIsInstance(address, Address)
def test_get_button(self): account = Account(Client(api_key, api_secret)) account.id = 'fakeaccountid' button_code = 'fakebuttoncode' def server_response(request, uri, headers): self.assertEqual(request.body.decode(), '') return (200, headers, json.dumps(data)) hp.register_uri(hp.GET, re.compile('.*'), body=server_response) data = {'button': 'not-the-right-type'} with self.assertRaises(UnexpectedDataFormatError): account.get_button(button_code) data = {'missing-button-key': True} with self.assertRaises(UnexpectedDataFormatError): account.get_button(button_code) data = {'button': {'code': button_code}} button = account.get_button(button_code) self.assertIsInstance(button, Button) data = {'badkey': 'bar', 'success': True} with self.assertRaises(UnexpectedDataFormatError): account.get_address() data = {'address': 'a', 'callback_url': None, 'label': None, 'success': True} address = account.get_address() self.assertIsInstance(address, Address)
def test_get_address(self): account = Account(Client(api_key, api_secret)) account.id = 'fakeaccountid' def server_response(request, uri, headers): self.assertTrue(uri.endswith('%s/address' % account.id)) self.assertEqual(request.body.decode(), '') return (200, headers, json.dumps(data)) hp.register_uri(hp.GET, re.compile('.*'), body=server_response) data = { 'address': 'a', 'callback_url': None, 'label': None, 'success': False } with self.assertRaises(APIError): account.get_address() data = {'badkey': 'bar', 'success': True} with self.assertRaises(UnexpectedDataFormatError): account.get_address() data = { 'address': 'a', 'callback_url': None, 'label': None, 'success': True } address = account.get_address() self.assertIsInstance(address, Address)
def test_get_address(self): account = Account(Client(api_key, api_secret)) account.id = 'fakeaccountid' def server_response(request, uri, headers): self.assertTrue(uri.endswith('%s/address' % account.id)) self.assertEqual(request.body.decode(), '') return (200, headers, json.dumps(data)) hp.register_uri(hp.GET, re.compile('.*'), body=server_response) data = {'address': 'a', 'callback_url': None, 'label': None, 'success': False} with self.assertRaises(APIError): account.get_address() data = {'badkey': 'bar', 'success': True} with self.assertRaises(UnexpectedDataFormatError): account.get_address() data = {'address': 'a', 'callback_url': None, 'label': None, 'success': True} address = account.get_address() self.assertIsInstance(address, Address)