Example #1
0
    def test_should_return_invalid_request_code_on_requests_with_nullable_params(
            self):
        account = u"client_account"
        login = u"client_login"
        method = None
        arguments = {
            "phone": u"79999990000",
            "email": u"*****@*****.**",
            "first_name": u"Firstname",
            "last_name": u"Lastname",
            "birthday": u"01.01.1999",
            "gender": 1
        }
        request = {
            "account": account,
            "login": login,
            "method": method,
            "token": self.get_token(login, account),
            "arguments": arguments
        }
        _, code = api.online_score_handler(
            {
                "body": request,
                "headers": self.headers
            }, self.context, self.store)
        self.assertEquals(api.INVALID_REQUEST, code)

        request['arguments'] = None
        _, code = api.online_score_handler(
            {
                "body": request,
                "headers": self.headers
            }, self.context, self.store)
        self.assertEquals(api.INVALID_REQUEST, code)
Example #2
0
    def test_should_return_ok_code_on_request_with_null_params(self):
        account = None
        login = api.ADMIN_LOGIN.decode()
        arguments = {
            "phone": u"79999990000",
            "email": u"*****@*****.**",
            "first_name": u"Firstname",
            "last_name": u"Lastname",
            "birthday": u"01.01.1999",
            "gender": 1
        }

        request = {
            "account": account,
            "login": login,
            "method": u'online_score',
            "token": self.get_token(login, account),
            "arguments": arguments
        }

        _, code = api.online_score_handler(
            {
                "body": request,
                "headers": self.headers
            }, self.context, self.store)
        self.assertEquals(api.OK, code)
Example #3
0
    def test_online_score_handler_ctx(self):
        class Request:
            def __init__(self, args):
                self.arguments = args
                self.is_admin = None

        args = {
            'phone': '78889990099',
            'email': 'tt@tt',
            'gender': None,
            'first_name': ''
        }
        res = ['phone', 'email']

        with mock.patch('scoring.get_score') as gs:
            gs.return_value = None

            ctx = {}
            request = Request(args)

            api.online_score_handler(request, ctx, None)
            self.assertListEqual(sorted(res), sorted(ctx['has']))
Example #4
0
    def test_online_score_handler_admin(self):
        class Request:
            def __init__(self, args):
                self.arguments = args
                self.is_admin = True

        args = {
            'phone': '78889990099',
            'email': 'tt@tt',
            'gender': None,
            'first_name': ''
        }

        with mock.patch('scoring.get_score') as gs:
            gs.return_value = None

            request = Request(args)

            handler_res, _ = api.online_score_handler(request, {}, None)
            self.assertEqual(handler_res['score'], 42)
Example #5
0
    def test_should_return_ok_code_on_requests_with_correct_params(self):
        account = u"client_account"
        login = u"client_login"
        method = u"online_score"

        arguments = {
            "phone": u"79999990000",
            "email": u"*****@*****.**",
            "first_name": u"Firstname",
            "last_name": u"Lastname",
            "birthday": u"01.01.1999",
            "gender": 1
        }

        request = {
            "account": account,
            "login": login,
            "method": method,
            "token": self.get_token(login, account),
            "arguments": arguments
        }
        _, code = api.online_score_handler(
            {
                "body": request,
                "headers": self.headers
            }, self.context, self.store)
        self.assertEquals(api.OK, code)

        arguments = {"client_ids": [2, 3], "date": u"02.01.2017"}
        request['arguments'] = arguments
        request['method'] = u'clients_interests'
        _, code = api.clients_interests_handler(
            {
                "body": request,
                "headers": self.headers
            }, self.context, self.store)
        self.assertEquals(api.OK, code)
Example #6
0
 def test_online_score_handler_if_admin(self):
     response = api.online_score_handler('not_empty', 'admin', '')
     self.assertEqual(({'score': 42}, 200), response)