Example #1
0
    def setUp(self):
        self.SCHEMA_DIR = SCHEMA_DIR

        self.schema_version_fp = os.path.join(self.SCHEMA_DIR,
                                              'schema_version.txt')

        self.values_csv_fp = os.path.join(self.SCHEMA_DIR, 'values.csv')
        self.values_json_fp = os.path.join(self.SCHEMA_DIR, 'values.json')
        self.values_profile = get_values_profile()

        self.master_csv_schema_fp = os.path.join(self.SCHEMA_DIR,
                                                 'master_def.csv')
        self.master_json_schema_fp = os.path.join(self.SCHEMA_DIR,
                                                  'master_schema.json')
        self.master_schema = get_schema()

        self.loc_csv_schema_fp = os.path.join(self.SCHEMA_DIR, 'loc_def.csv')
        self.loc_json_schema_fp = os.path.join(self.SCHEMA_DIR,
                                               'loc_schema.json')
        self.loc_schema = get_schema('loc')

        self.acc_csv_schema_fp = os.path.join(self.SCHEMA_DIR, 'acc_def.csv')
        self.acc_json_schema_fp = os.path.join(self.SCHEMA_DIR,
                                               'acc_schema.json')
        self.acc_schema = get_schema('acc')

        self.reinsinfo_csv_schema_fp = os.path.join(self.SCHEMA_DIR,
                                                    'reinsinfo_def.csv')
        self.reinsinfo_json_schema_fp = os.path.join(self.SCHEMA_DIR,
                                                     'reinsinfo_schema.json')
        self.reinsinfo_schema = get_schema('reinsinfo')

        self.reinsscope_csv_schema_fp = os.path.join(self.SCHEMA_DIR,
                                                     'reinsscope_def.csv')
        self.reinsscope_json_schema_fp = os.path.join(
            self.SCHEMA_DIR, 'reinsscope_schema.json')
        self.reinsscope_schema = get_schema('reinsscope')

        self.csv_to_json_col_map = {
            'backend_db_field_name': 'oed_db_field_name',
            'backend_table': 'oed_db_table',
            'blank': 'blank',
            'default': 'default',
            'desc': 'desc',
            'entity': 'entity',
            'field_name': 'field_name',
            'required': 'required',
            'secmod': 'secmod',
            'type': 'sql_dtype'
        }

        self.json_to_csv_type_col_map = {
            'unsigned bit': '0 or 1',
            'unsigned tinyint': 'tinyint',
            'unsigned smallint': 'smallint',
            'unsigned int': 'int',
            'unsigned bigint': 'bigint'
        }

        self.json_to_csv_blank_col_map = {False: 'NO', True: 'YES'}
Example #2
0
    def test_get_schema__reinsscope(self):
        with io.open(self.reinsscope_json_schema_fp, 'r', encoding='utf-8') as f:
            exp_schema = OrderedDict({
                literal_eval(k): (
                    v if not v['dtype_range']
                    else {_k: (
                        _v if not _k == 'dtype_range'
                        else (
                            range(_v['start'], _v['stop']) if v['py_dtype'] == 'int' and isinstance(_v, dict) and 'start' in _v and 'stop' in _v
                            else _v
                        )
                    ) for _k, _v in v.items()
                    }
                )
                for k, v in json.load(f).items()
            })
        exp_schema = OrderedDict({
            k: (
                v if not isinstance(v.get('column_validation'), dict) or 'start' not in v['column_validation']
                else {**v, **{'column_validation': v['dtype_range']}}
            )
            for k, v in exp_schema.items()
        })
        
        res_schema = get_schema('reinsscope')

        self.assertEqual(exp_schema, res_schema)
Example #3
0
    floats,
    integers,
    lists,
    text,
)

from oedtools.schema import (
    get_column_schema,
    get_grouped_master_schema,
    get_schema,
    SCHEMA_DIR,
)
from oedtools.values import (
    get_values_profile, )

MASTER_SCHEMA = get_schema()

GROUPED_SCHEMA = get_grouped_master_schema()

SCHEMA_TYPES = list(GROUPED_SCHEMA)
SCHEMA_TYPES_EX_MASTER = list(set(SCHEMA_TYPES).difference(['master']))

VALUE_GROUPS = sorted(get_values_profile())

ALL = sorted(MASTER_SCHEMA)
REQUIRED_TYPES = ['R', 'CR', 'O']
REQUIRED = sorted(k for k, v in MASTER_SCHEMA.items() if v['required'] == 'R')
OPTIONAL = sorted(set(ALL).difference(REQUIRED))
NONNULL = sorted(k for k, v in MASTER_SCHEMA.items() if not v['blank'])
REQUIRED_NONNULL = set(REQUIRED).intersection(NONNULL)
NUMERIC = sorted(k for k, v in MASTER_SCHEMA.items()