<commit_before>"""
test for the Jsonval module.
"""

import unittest

from base_test import PschedTestBase


class TestJsonval(PschedTestBase):
    """
    Jsonval tests.
    """

    def test_one(self):
        """"""
        pass


if __name__ == '__main__':
    unittest.main()<commit_msg>Jsonval module testing.<commit_after>"""
test for the Jsonval module.
"""

import unittest

from base_test import PschedTestBase

from pscheduler.jsonval import json_validate


class TestJsonval(PschedTestBase):
    """
    Jsonval tests.
    """

    def test_jsonval(self):
        """"""
        sample = {
            "schema": 1,
            "when": "2015-06-12T13:48:19.234",
            "howlong": "PT10M",
            "sendto": "<EMAIL>",
            "x-factor": 3.14,
            "protocol": "udp",
            "ipv": 6,
            "ip": "fc80:dead:beef::",
            "archspec": {"name": "foo", "data": None},
        }

        schema = {
            "local": {
                "protocol": {
                    "type": "string",
                    "enum": ['icmp', 'udp', 'tcp']
                }
            },
            "type": "object",
            "properties": {
                "schema": {"$ref": "#/pScheduler/Cardinal"},
                "when": {"$ref": "#/pScheduler/Timestamp"},
                "howlong": {"$ref": "#/pScheduler/Duration"},
                "sendto": {"$ref": "#/pScheduler/Email"},
                "ipv": {"$ref": "#/pScheduler/ip-version"},
                "ip": {"$ref": "#/pScheduler/IPAddress"},
                "protocol": {"$ref": "#/local/protocol"},
                "x-factor": {"type": "number"},
                "archspec": {"$ref": "#/pScheduler/ArchiveSpecification"},

            },
            "required": ["sendto", "x-factor"]
        }

        # missing an attr
        valid, message = json_validate(sample, schema)

        self.assertFalse(valid)
        self.assertEqual(message, "At /archspec: 'archiver' is a required property")

        # add it in now
        sample['archspec']['archiver'] = 'tar'

        valid, message = json_validate(sample, schema)

        self.assertTrue(valid)
        self.assertEqual(message, 'OK')


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.17105850826261723, 'fraction_numerical': 0.011612326931665922, 'mean_word_length': 1.824716267339218, 'pattern_counts': {'":': 36, '<': 4, '<?xml version=': 0, '>': 4, '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': '4549240', 'n_tokens_mistral': 703, 'n_tokens_neox': 665, 'n_words': 143}