Ejemplo n.º 1
0
def show_stored_queries():
    """Show the current stored query names loaded from the spec."""
    name = flask.request.args.get('name')
    if name:
        return flask.jsonify(
            {'stored_query': spec_loader.get_schema('stored_query', name)})
    return flask.jsonify(spec_loader.get_names('stored_query'))
Ejemplo n.º 2
0
def show_collections():
    """Show the names of the (document) collections (edges and vertices) loaded from the spec."""
    name = flask.request.args.get('name')
    doc_id = flask.request.args.get('doc_id')
    if name:
        return flask.jsonify(spec_loader.get_schema('collection', name))
    elif doc_id:
        return flask.jsonify(spec_loader.get_schema_for_doc(doc_id))
    else:
        return flask.jsonify(spec_loader.get_names('collection'))
Ejemplo n.º 3
0
    def test_get_names(self, schema_type_names=[], expected=[]):
        """test getting the names of all the schemas of a given type"""

        # this method should only be run from another test method
        if len(schema_type_names) == 0:
            self.assertTrue(True)
            return

        schema_type_singular = schema_type_names[0]
        schema_type_plural = schema_type_names[1]
        method = getattr(spec_loader, 'get_' + schema_type_singular + '_names')

        # save the original value
        original_config_dir = self.config['spec_paths'][schema_type_plural]
        # set the config to the test directory
        self.config['spec_paths'][schema_type_plural] = os_path.join(
            self.test_dir, 'data', schema_type_plural)

        got_names_method = method()
        got_names_singular = spec_loader.get_names(schema_type_singular)
        got_names_plural = spec_loader.get_names(schema_type_plural)

        self.config['spec_paths'][schema_type_plural] = os_path.join(
            self.test_dir, 'data', 'empty')
        got_names_method_empty = method()
        got_names_empty = spec_loader.get_names(schema_type_singular)

        # restore the original value before running tests
        self.config['spec_paths'][schema_type_plural] = original_config_dir

        # ensure the results are as expected
        # get_collection_names
        self.assertEqual(set(expected), set(got_names_method))
        # get_names('collection')
        self.assertEqual(set(expected), set(got_names_singular))
        # get_names('collections')
        self.assertEqual(set(expected), set(got_names_plural))

        # empty collections dir
        self.assertEqual(got_names_method_empty, [])
        self.assertEqual(got_names_empty, [])
Ejemplo n.º 4
0
def show_data_sources():
    """Show the current data sources loaded from the spec."""
    name = flask.request.args.get('name')
    if name:
        return flask.jsonify(spec_loader.get_schema('data_source', name))
    return flask.jsonify(spec_loader.get_names('data_sources'))
Ejemplo n.º 5
0
def list_data_sources():
    # note the custom response format is used by the frontend, so this endpoint is provided
    # in addition to the /specs/data_sources endpoint

    data_sources = spec_loader.get_names('data_sources')
    return flask.jsonify({'data_sources': data_sources})
Ejemplo n.º 6
0
    def test_non_existent_schema(self):

        err_msg = 'Reality does not exist'
        with self.assertRaisesRegex(SchemaNonexistent, err_msg):
            spec_loader.get_names('Reality')