def test_invalid_call(self): data = {'dividend': "a", 'divisor': 2} response = self.client.post(self.divide_url, data) self.assertEqual(response.status_code, 400) response_data = json.loads(smart_u(response.content)) dividend_error = response_data['errors']['dividend'] self.assertEqual(dividend_error[0], smart_u(IntegerField().error_messages['invalid'])) self.assertGreater(len(response_data['errors']), 0) self.assertFalse(response_data['success']) self.assertFalse(response_data['data'])
def test_valid_auth(self): response = self.send_request(self.authenticate_url, {'username': self.user.username, 'password': '******'}) self.assertEqual(response.status_code, 200) response_data = json.loads(smart_u(response.content)) self.assertEqual(response_data['errors'], {}) self.assertTrue(response_data['success']) self.assertIsNotNone(response_data['data'])
def test_invalid_password(self): data = {'username': self.user.username, 'password': '******'} response = self.send_request(self.authenticate_url, data) self.assertEqual(response.status_code, 400) response_data = json.loads(smart_u(response.content)) self.assertGreater(len(response_data['errors']), 0) self.assertFalse(response_data['success']) self.assertFalse(response_data['data'])
def test_invalid_password(self): data = {'username': self.user.username, 'password': '******'} response = self.send_request(self.authenticate_url, data) self.assertEqual(response.status_code, 400) print(repr(response.content)) response_data = json.loads(smart_u(response.content)) self.assertGreater(len(response_data['errors']), 0) self.assertFalse(response_data['success']) self.assertFalse(response_data['data'])
def test_valid_auth(self): response = self.send_request(self.authenticate_url, { 'username': self.user.username, 'password': '******' }) self.assertEqual(response.status_code, 200) response_data = json.loads(smart_u(response.content)) self.assertEqual(response_data['errors'], {}) self.assertTrue(response_data['success']) self.assertIsNotNone(response_data['data'])
def test_api_key(self): smart_u(self.api_key)
def test_error_call(self): data = {'dividend': "42", 'divisor': 0} response = self.client.post(self.divide_url, data) response_data = json.loads(smart_u(response.content)) self.assertFalse(response_data['success'])
def test_ok_call(self): data = {'dividend': 7, 'divisor': 2} response = self.client.post(self.divide_url, data) self.assertEqual(response.status_code, 200) response_data = json.loads(smart_u(response.content)) self.assertEqual(response_data['data'], 3.5)