def test_valid_environment(self, mock_request): """ Check errors are raised with no environments """ mock_request.return_value = FakeResponse(200, self.response_data) with self.assertRaises(ConfigError): CustomerToken.create_from_card_token('1234', self.user, environment='test')
def test_response_error(self, mock_request): """ Validate generic error response """ mock_request.return_value = FakeResponse(200, self.response_error) with self.assertRaises(PinError): CustomerToken.create_from_card_token('1234', self.user, environment='test')
def test_response_error(self, mock_request): """ Validate generic error response """ mock_request.return_value = FakeResponse(200, self.response_error) with self.assertRaises(PinError): CustomerToken.create_from_card_token( '1234', self.user, environment='test' )
def test_host_set(self, mock_request): """ Check errors are raised when the host is not set """ mock_request.return_value = FakeResponse(200, self.response_data) with self.assertRaises(ConfigError): CustomerToken.create_from_card_token( '1234', self.user, environment='test' )
def test_default_environment(self): """ Unset PIN_DEFAULT_ENVIRONMENT to test that the environment defaults to 'test'. """ del settings.PIN_DEFAULT_ENVIRONMENT token = CustomerToken() token.user = User.objects.create() token.environment = None token.save() self.assertEqual(token.environment, 'test')
def test_response_success(self, mock_request): mock_request.return_value = FakeResponse(200, self.response_data) customer = CustomerToken.create_from_card_token('1234', self.user, environment='test') self.assertIsInstance(customer, CustomerToken) self.assertEqual(customer.user, self.user) self.assertEqual(customer.token, '1234') self.assertEqual(customer.environment, 'test') self.assertEqual(customer.card_number, 'XXXX-XXXX-XXXX-0000') self.assertEqual(customer.card_type, 'master')
def test_response_success(self, mock_request): """ Validate successful response """ mock_request.return_value = FakeResponse(200, self.response_data) customer = CustomerToken.create_from_card_token( '1234', self.user, environment='test' ) self.assertIsInstance(customer, CustomerToken) self.assertEqual(customer.user, self.user) self.assertEqual(customer.token, '1234') self.assertEqual(customer.environment, 'test') self.assertEqual(customer.cards.all()[0].display_number, 'XXXX-XXXX-XXXX-0000') self.assertEqual(customer.cards.all()[0].scheme, 'master')
def test_default_environment(self): # Unset PIN_DEFAULT_ENVIRONMENT to test that the environment defaults # to 'test'. del settings.PIN_DEFAULT_ENVIRONMENT token = CustomerToken() token.user = User.objects.create() token.environment = None token.save() self.assertEqual(token.environment, 'test')
def test_default_environment(self, mock_request): """ return a default environment """ mock_request.return_value = FakeResponse(200, self.response_data) token = CustomerToken.create_from_card_token('1234', self.user) self.assertEqual(token.environment, 'test')
def test_secret_set(self, mock_request): mock_request.return_value = FakeResponse(200, self.response_data) with self.assertRaises(ConfigError): CustomerToken.create_from_card_token('1234', self.user, environment='test')
def test_response_not_json(self, mock_request): mock_request.return_value = FakeResponse(200, '') with self.assertRaises(PinError): CustomerToken.create_from_card_token('1234', self.user, environment='test')