<commit_before>import pytest

from kitten.validation import Validator
from jsonschema.exceptions import ValidationError

from mock import MagicMock


class TestValidatorGetMethod(object):
    def setup_method(self, method):
        self.validator = Validator()

    def test_get_method_no_paradigm(self):
        request = {'method': 'hehe'}
        with pytest.raises(ValidationError) as exc:
            self.validator.get_method(request)

        assert 'paradigm' in exc.value.message
        assert 'method' not in exc.value.message

    def test_get_method_no_method(self):
        request = {'paradigm': 'hehe'}
        with pytest.raises(ValidationError) as exc:
            self.validator.get_method(request)

        assert 'paradigm' not in exc.value.message
        assert 'method' in exc.value.message

    def test_get_method(self):
        p = 'wow'
        m = 'doge'
        request = {'paradigm': p, 'method': m}
        paradigm, method = self.validator.get_method(request)

        assert paradigm == p
        assert method == m


class TestValidatorRequest(object):
    def setup_method(self, method):
        self.validator = Validator()
        self.request = {
            'paradigm': 'paradigm',
            'method': 'method',
        }
        self.paradigm = MagicMock()
        self.paradigms = {'paradigm': self.paradigm}

    def test_no_paradigm(self):
        self.request['paradigm '] = "404"
        self.paradigms = {'hehe': True}

        with pytest.raises(ValidationError) as exc:
            self.validator.request(self.request, self.paradigms)

        assert 'hehe' in exc.value.message

    def test_no_method(self):
        method = 'fail'
        self.request['method'] = method
        self.paradigm.validator.fail_request = None

        with pytest.raises(ValidationError) as exc:
            self.validator.request(self.request, self.paradigms)

        assert method in exc.value.message

    def test_working_example(self):
        def inner():
            return {'field': {'type': 'number'}}

        self.request['field'] = 1000
        self.paradigm.validator.method_request = inner

        self.validator.request(self.request, self.paradigms)<commit_msg>Add failing validation test<commit_after>import pytest

from kitten.validation import Validator
from jsonschema.exceptions import ValidationError

from mock import MagicMock


class TestValidatorGetMethod(object):
    def setup_method(self, method):
        self.validator = Validator()

    def test_get_method_no_paradigm(self):
        request = {'method': 'hehe'}
        with pytest.raises(ValidationError) as exc:
            self.validator.get_method(request)

        assert 'paradigm' in exc.value.message
        assert 'method' not in exc.value.message

    def test_get_method_no_method(self):
        request = {'paradigm': 'hehe'}
        with pytest.raises(ValidationError) as exc:
            self.validator.get_method(request)

        assert 'paradigm' not in exc.value.message
        assert 'method' in exc.value.message

    def test_get_method(self):
        p = 'wow'
        m = 'doge'
        request = {'paradigm': p, 'method': m}
        paradigm, method = self.validator.get_method(request)

        assert paradigm == p
        assert method == m


class TestValidatorRequest(object):
    def setup_method(self, method):
        self.validator = Validator()
        self.request = {
            'paradigm': 'paradigm',
            'method': 'method',
        }
        self.paradigm = MagicMock()
        self.paradigms = {'paradigm': self.paradigm}

    def test_no_paradigm(self):
        self.request['paradigm '] = "404"
        self.paradigms = {'hehe': True}

        with pytest.raises(ValidationError) as exc:
            self.validator.request(self.request, self.paradigms)

        assert 'hehe' in exc.value.message

    def test_no_method(self):
        method = 'fail'
        self.request['method'] = method
        self.paradigm.validator.fail_request = None

        with pytest.raises(ValidationError) as exc:
            self.validator.request(self.request, self.paradigms)

        assert method in exc.value.message

    def test_working_example(self):
        def inner():
            return {'field': {'type': 'number'}}

        self.request['field'] = 1000
        self.paradigm.validator.method_request = inner

        self.validator.request(self.request, self.paradigms)

    def test_failing_example(self):
        def inner():
            return {'field': {'type': 'number'}}

        self.request['field'] = 'helo i am string not number'
        self.paradigm.validator.method_request = inner

        with pytest.raises(ValidationError):
            self.validator.request(self.request, self.paradigms)
{'fraction_non_alphanumeric': 0.10703812316715543, 'fraction_numerical': 0.002932551319648094, 'mean_word_length': 2.5660941000746824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2228707', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1423, 'n_words': 313}