Ejemplo n.º 1
0
    def test_url_validator_validates_float_type(self):
        class MockRequest:
            args = {'dates': '2019-02-02:2019-01-01'}

        with patch('app.utils.security.request', new_callable=MockRequest):
            response = Security.url_validator(
                ['dates|optional:float'])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(response[0].get_json()['msg'],
                         'Bad Request - dates must be float')
Ejemplo n.º 2
0
    def test_url_validator_validates_minimum_value(self):
        class MockRequest:
            args = {'age': 17}

        with patch('app.utils.security.request', new_callable=MockRequest):
            response = Security.url_validator(
                ['age|required:min-18'])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(response[0].get_json()['msg'],
                         'Bad Request - age can only have a min value of 18')
Ejemplo n.º 3
0
    def test_url_validator_validates_optional_int_request_args(self):
        class MockRequest:
            args = {'name': 'test'}

        with patch('app.utils.security.request', new_callable=MockRequest):

            response = Security.url_validator(
                ['age|optional:int'])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(response, ('test', ))
Ejemplo n.º 4
0
    def test_url_validator_validates_required_int_request_args(self):
        class MockRequest:
            method = "POST"
            args = {'age': 46}

        with patch('app.utils.security.request', new_callable=MockRequest):

            response = Security.url_validator(
                ['age|required:int'])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(response, ('test', ))
Ejemplo n.º 5
0
    def test_url_validator_validates_invalid_int_type(self):
        class MockRequest:
            args = {'age': 'test'}

        with patch('app.utils.security.request', new_callable=MockRequest):

            response = Security.url_validator(
                ['age|required:int'])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(response[0].get_json()['msg'],
                         'Bad Request - age must be integer')
Ejemplo n.º 6
0
    def test_url_validator_validates_list_int_items_are_all_int(self):
        class MockRequest:
            args = {'mealList': [1, 2, 'string']}

        with patch('app.utils.security.request', new_callable=MockRequest):
            response = Security.url_validator([
                'mealList|required:list_int'
            ])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(response[0].get_json()['msg'],
                         'Bad Request - [string] in list must be integer')
Ejemplo n.º 7
0
    def test_url_validator_validates_list_int_not_a_valid_list(self):
        class MockRequest:
            args = {'mealList': 'not a valid list'}

        with patch('app.utils.security.request', new_callable=MockRequest):
            response = Security.url_validator([
                'mealList|required:list_int'
            ])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(response[0].get_json()['msg'],
                         'Bad Request - mealList must be a list')
Ejemplo n.º 8
0
    def test_url_validator_validates_length_value(self):
        class MockRequest:
            args = {'username': '******'}

        with patch('app.utils.security.request', new_callable=MockRequest):
            response = Security.url_validator([
                'username|required:length-10'
            ])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(response[0].get_json()['msg'],
                         'Bad Request - username can only have a len of 10')
Ejemplo n.º 9
0
    def test_url_validator_validates_required_int_missing(self):
        class MockRequest:
            method = "POST"
            args = {'name': 'test'}

        with patch('app.utils.security.request', new_callable=MockRequest):

            response = Security.url_validator(
                ['age|required:int'])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(response[0].get_json()['msg'],
                         'Bad Request - age is required')
Ejemplo n.º 10
0
    def test_url_validator_validates_range(self):
        class MockRequest:
            args = {'dates': '2019-02-02:2019-01-01'}

        with patch('app.utils.security.request', new_callable=MockRequest):
            response = Security.url_validator(
                ['dates|optional:range'])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(
            response[0].get_json()['msg'],
            'Bad Request - Start Date [2019-02-02 00:00:00] must be less than End Date[2019-01-01 00:00:00]'
        )
Ejemplo n.º 11
0
    def test_validator_validates_for_non_enum_required_and_non_existing_enum(
            self):
        class MockRequest:
            args = {'action_typ': 'create'}

        with patch('app.utils.security.request', new_callable=MockRequest):
            response = Security.url_validator([
                'action_typ|enum_options'
            ])(lambda *args, **kwargs: ('test', ))()

        self.assertIn('Bad Request - Invalid search field',
                      response[0].get_json()['msg'])
Ejemplo n.º 12
0
    def test_url_validator_validates_date(self):
        class MockRequest:
            args = {'startDate': 'not a valid date'}

        with patch('app.utils.security.request', new_callable=MockRequest):
            response = Security.url_validator([
                'startDate|required:date'
            ])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(
            response[0].get_json()['msg'],
            'Bad Request - startDate should be valid date. Format: YYYY-MM-DD')
Ejemplo n.º 13
0
    def test_url_validator_validates_list_exists(self):
        class MockRequest:
            args = {'proteinItems': [1]}

        with patch('app.utils.security.request', new_callable=MockRequest):
            response = Security.url_validator([
                'proteinItems|exists|meal_item|id'
            ])(lambda *args, **kwargs: ('test', ))()

        self.assertEqual(
            response[0].get_json()['msg'],
            'Bad Request - proteinItems contains invalid id(s) for meal_item table '
        )
Ejemplo n.º 14
0
    def test_url_validator_validates_empty_request_args(self):

        response = Security.url_validator('rules')('function')()

        self.assertEqual(response[0].get_json()['msg'],
                         'Bad Request - Request Must be Properly Formatted')