Exemplo n.º 1
0
def load_config_for_tables(config_path: str) -> TablesConfig:
    """Load a config defining how tables should be imported and exported."""
    # Load YAML defining schema for validation of default config
    schema_path = SCHEMA_FILE
    schema = None
    if os.path.isfile(schema_path):
        with open(schema_path, 'r') as config_file:
            schema_config = yaml.safe_load(config_file)
            rxf = Rx.Factory({"register_core_types": True})
            schema = rxf.make_schema(schema_config)
    else:
        _log.warning(
            'Config schema description is missing (re-install recommended): {}',
            schema_path)

    # Load config
    with open(config_path, 'r') as config_file:
        yaml_config = yaml.safe_load(config_file)

    # Validate config if it's not empty
    if yaml_config is not None and schema is not None and not schema.check(
            yaml_config):
        # _log.warning("Config is invalid: '%s'" % (config_path,))
        raise ConfigInvalidException(
            "incorrect format for '{}', should match description in '{}'".
            format(config_path, schema_path))
        # return None
    return cast(TablesConfig, yaml_config)
Exemplo n.º 2
0
 def test_spore(self):
     """Test that the inputed spore is valid."""
     rx = Rx.Factory({"register_core_types": True})
     with open(os.path.join(HERE, 'spore_validation.rx')) as f:
         spore_json_schema = json.loads(f.read())
         spore_schema = rx.make_schema(spore_json_schema)
         self.assertTrue(
             spore_schema.check(requests.get(self.spore_url).json()))
    def test_rxjson_spore(self):
        rx = Rx.Factory({'register_core_types': True})
        client = Client(WSGIDispatcher([ApiApp],
                                       name='ApiApp',
                                       version='1.0',
                                       base_url='http://apiapp.com'),
                        response_wrapper=BaseResponse)
        resp = client.get("/spore/")

        with open(os.path.join(HERE, 'spore_validation.rx')) as f:
            spore_json_schema = json.loads(f.read())
            spore_schema = rx.make_schema(spore_json_schema)
            self.assertTrue(spore_schema.check(json.loads(resp.data)))
Exemplo n.º 4
0
    def test_rxjson_spore(self):
        rx = Rx.Factory({'register_core_types': True})

        coffees = Service(name='Coffees', path='/coffee')
        coffee = Service(name='coffee', path='/coffee/{bar}/{id}')

        self._define_coffee_methods(coffee)
        self._define_coffee_methods(coffees)

        services = get_services(names=('coffee', 'Coffees'))
        spore = generate_spore_description(
                services, name="oh yeah",
                base_url="http://localhost/", version="1.0")

        with open(os.path.join(HERE, 'spore_validation.rx')) as f:
            spore_json_schema = json.loads(f.read())
            spore_schema = rx.make_schema(spore_json_schema)
            self.assertTrue(spore_schema.check(spore))
Exemplo n.º 5
0
# SPDX-License-Identifier: MIT

import logging
import asyncio
import devices
import syslog
import yaml
from rxjson import Rx
logger = logging.getLogger("Dimmer")

schema = Rx.Factory({
    "register_core_types": True
}).make_schema(
    yaml.load("""
type: //rec
required:
    name : //str
    clock : //str
    output : //str
    schedule: //any
"""))
#        type : //arr
#        length: { min: 1 }
#        contents : //any


class Dimmer():
    def __init__(self, conf):
        self.update_conf(conf)

    def update_conf(self, conf):