<commit_before>from ckan.tests import helpers, factories
from ckan import plugins, logic
import unittest
from ckanext.requestdata.logic.validators import *


class ActionBase(unittest.TestCase):
    @classmethod
    def setup_class(self):
        self.app = helpers._get_test_app()
        if not plugins.plugin_loaded('requestdata'):
            plugins.load('requestdata')

    def setup(self):
        helpers.reset_db()

    @classmethod
    def teardown_class(self):
        if plugins.plugin_loaded('requestdata'):
            plugins.unload('requestdata')


class TestAuth(ActionBase):
    def test_email_validator_validate_is_true(self):
        key = ('state')
        data = {('state'): '<EMAIL>'}
        errors = {key: []}
        email_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

    def test_email_validator_validate_is_false(self):
        key = ('state')
        data = {('state'): 'aleksandar.ristovkeitaro.com'}
        errors = {key: []}
        email_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert False
        else:
            assert True

    def test_state_validator_not_in_possible_state(self):
        key = ('state')
        data = {('state'): 'test'}
        errors = {key: []}
        state_validator(key, data, errors, None)
        if len(errors[key]) != 0:
            assert True
        else:
            assert False

    def test_state_validator_in_possible_state(self):
        key = ('state')
        data = {('state'): 'new'}
        errors = {key: []}
        state_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

        data = {('state'): 'open'}
        errors = {key: []}
        state_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

        data = {('state'): 'archive'}
        errors = {key: []}
        state_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

    def test_boolean_validator_is_not_instance(self):
        key = ('state')
        data = {('state'): 'True'}
        errors = {key: []}
        boolean_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

        data = {('state'): 'False'}
        errors = {key: []}
        boolean_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

    def test_boolean_validator_is_instance(self):
        key = ('state')
        data = {('state'): 'Test'}
        errors = {key: []}
        try:
            boolean_validator(key, data, errors, None)
            assert False
        except ValueError:
            assert True
<commit_msg>Add tests for boolean validator<commit_after>from ckan.tests import helpers, factories
from ckan import plugins, logic
import unittest
from ckanext.requestdata.logic.validators import *


class ActionBase(unittest.TestCase):
    @classmethod
    def setup_class(self):
        self.app = helpers._get_test_app()
        if not plugins.plugin_loaded('requestdata'):
            plugins.load('requestdata')

    def setup(self):
        helpers.reset_db()

    @classmethod
    def teardown_class(self):
        if plugins.plugin_loaded('requestdata'):
            plugins.unload('requestdata')


class TestAuth(ActionBase):
    def test_email_validator_validate_is_true(self):
        key = ('state')
        data = {('state'): '<EMAIL>'}
        errors = {key: []}
        email_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

    def test_email_validator_validate_is_false(self):
        key = ('state')
        data = {('state'): 'aleksandar.<EMAIL>'}
        errors = {key: []}
        email_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert False
        else:
            assert True

    def test_state_validator_not_in_possible_state(self):
        key = ('state')
        data = {('state'): 'test'}
        errors = {key: []}
        state_validator(key, data, errors, None)
        if len(errors[key]) != 0:
            assert True
        else:
            assert False

    def test_state_validator_in_possible_state(self):
        key = ('state')
        data = {('state'): 'new'}
        errors = {key: []}
        state_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

        data = {('state'): 'open'}
        errors = {key: []}
        state_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

        data = {('state'): 'archive'}
        errors = {key: []}
        state_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

    def test_boolean_validator_is_not_instance(self):
        key = ('state')
        data = {('state'): 'True'}
        errors = {key: []}
        boolean_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

        data = {('state'): 'False'}
        errors = {key: []}
        boolean_validator(key, data, errors, None)
        if len(errors[key]) == 0:
            assert True
        else:
            assert False

    def test_boolean_validator_wrong_value(self):
        key = 'state'
        data = {'state': '3'}
        errors = {key: []}
        error_msg = "String is not true/false"
        try:
            boolean_validator(key, data, errors, None)
            assert False
        except ValueError as e:
            assert error_msg in e.message

    def test_boolean_validator_string_value(self):
        key = ('state')
        data = {('state'): 'Test'}
        errors = {key: []}
        try:
            boolean_validator(key, data, errors, None)
            assert False
        except ValueError:
            assert True

{'fraction_non_alphanumeric': 0.12070874861572536, 'fraction_numerical': 0.0026894478721721246, 'mean_word_length': 1.9363678588016722, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '4545000', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1818, 'n_words': 459}