Example #1
0
def regenerate(filters=None, args=None):

    template = Template(INDEX)
    elements = list()

    if settings_module.parse_boolean(os.environ.get('MAKETESTS', '0')):
        DESTDIR = tempfile.mkdtemp()
    else:
        DESTDIR = os.path.join(PARENT, 'schemas')

    for fname, schema in jsonschemas.get_all_schemas(filters).items():
        destpath = os.path.join(DESTDIR, fname + '.json')

        logger.info('Regenerating %s', fname)

        if os.environ.get('MAKETESTS', None) is None:
            if compare_schemas(
                    load_schema_file(destpath), load_schema_string(schema)):
                with open(destpath, 'w+') as j:
                    j.write(schema)
            else:
                logger.debug('%s did not change', fname + '.json')
        else:
            with open(destpath, 'w+') as j:
                j.write(schema)

        # Populate the index file even if the schema was not updated
        # TODO - Display the title and comment from each schema
        elements.append({'href': fname + '.json', 'caption': fname + '.json'})

    logger.info('Building index %s', INDEX_FILENAME)
    elements = sorted(elements, key=lambda k: k['caption'])
    template.render(navigation=elements)
    idxdestpath = os.path.join(DESTDIR, INDEX_FILENAME)
    with open(idxdestpath, 'w+') as i:
        i.write(template.render(navigation=elements))

    return True
def test_formats_get_schemas():
    schemas = jsonschemas.get_all_schemas(filters=['formats'])
    assert isinstance(schemas, dict)
    # the object and document schemas
    assert len(list(schemas.keys())) > 0
def test_get_allschemas_filter_one():
    schemas = jsonschemas.get_all_schemas(filters=['linkedstores.basestore'])
    assert isinstance(schemas, dict)
    # the object and document schemas
    assert len(list(schemas.keys())) == 2
def test_get_allschemas():
    schemas = jsonschemas.get_all_schemas()
    assert isinstance(schemas, dict)
    assert len(list(schemas.keys())) > 0
def test_get_allschemas_filter_all():
    schemas = jsonschemas.get_all_schemas(filters=['will-never-be-valid'])
    assert isinstance(schemas, dict)
    assert len(list(schemas.keys())) == 0