def test_online_score_valid_with_trouble_cache(self): arguments = { "gender": 1, "birthday": "01.01.2000", "first_name": "a", "last_name": "b" } request = { "account": "horns&hoofs", "login": "******", "method": "online_score", "arguments": arguments } set_valid_auth(request) code, response = self.make_request(request) self.assertEqual(code, api.OK) score_1 = response['response']['score'] # stop cache self.redis.kill() code, response = self.make_request(request) self.assertEqual(code, api.OK) score_2 = response['response']['score'] self.assertAlmostEqual(score_1, score_2) # start cache self.restart_redis() code, response = self.make_request(request) self.assertEqual(code, api.OK) score_3 = response['response']['score'] self.assertAlmostEqual(score_2, score_3)
def test_method_client_interests(self, arguments): request = { "account": "horns&hoofs", "login": "******", "method": "clients_interests", "arguments": arguments } set_valid_auth(request) response, code = self.get_response(request) self.assertEqual(api.OK, code)
def test_method_online_score(self, arguments): request = { "account": "horns&hoofs", "login": "******", "method": "online_score", "arguments": arguments } set_valid_auth(request) _, code = self.get_response(request) self.assertEqual(code, api.OK)
def test_ok_score_admin_request(self): arguments = {"phone": "79995008811", "email": "tt@tt"} request = { "account": "horns&hoofs", "login": "******", "method": "online_score", "arguments": arguments } set_valid_auth(request) response, code = self.get_response(request) self.assertEqual(api.OK, code) score = response.get("score") self.assertEqual(score, 42)
def test_client_interests_valid(self): interests = {1: ['ball', 'uveball', 'noneball'], 2: ['teststring']} for key, value in interests.items(): self.store.set('i:{}'.format(key), json.dumps(value)) ids = list(interests.keys()) arguments = {"client_ids": ids, "date": "19.07.2017"} request = { "account": "horns&hoofs", "login": "******", "method": "clients_interests", "arguments": arguments } set_valid_auth(request) code, response = self.make_request(request) self.assertEqual(api.OK, code)
def test_online_score_validation_error(self): arguments = { "gender": 1, "birthday": "01.01.2000", "first_name": "a", "last_name": "b" } request = { "account": "horns&hoofs", "login": "******", "method": "online_score", "arguments": arguments } arguments['gender'] = 4 arguments['birthday'] = '01.01.1910' set_valid_auth(request) code, _ = self.make_request(request) self.assertEqual(code, api.INVALID_REQUEST)
def test_method_fail_method(self, request): set_valid_auth(request) _, code = self.get_response(request) self.assertEqual(api.NOT_FOUND, code)
def test_auth_admin_valid(self, args): set_valid_auth(args) request = api.MethodRequest(args) self.assertTrue(api.check_auth(request))