示例#1
0
def test_all_to_intermediary():
    tables, relationships = all_to_intermediary(Base)
    check_intermediary_representation_simple_table(tables, relationships)

    db_uri = create_db()
    tables, relationships = all_to_intermediary(db_uri)
    check_intermediary_representation_simple_table(tables, relationships)

    with pytest.raises(ValueError):
        tables, relationships = all_to_intermediary('plop')
示例#2
0
    def generate_dotcode():
        # get markdown
        with tempfile.NamedTemporaryFile() as tf_db:
            # is_public=False triggers the creation of tables
            CylcSuiteDAO(db_file_name=tf_db.name, is_public=False)
            schema, orphans = schema_to_markdown(db_name=tf_db.name)

        # graph prefix
        dotcode = [
            'graph {', 'node [label = "\\N", shape = plaintext];',
            'edge [color = gray50, minlen = 2, style = dashed];',
            'rankdir = "LR";'
        ]

        # the database graph
        tables, relationships = all_to_intermediary(schema)
        dotcode.extend([x.to_dot() for x in tables])
        dotcode.extend([x.to_dot() for x in relationships])

        # group orphan nodes to cut down on clutter
        dotcode.extend(group_nodes(orphans))

        # use invisible graph edges to change the graph layout
        dotcode.append(
            '"task_pool_checkpoints" -- "inheritance"[style=invis];')

        # graph suffix
        dotcode += ['}']

        return dotcode
示例#3
0
def show_er_diagram():
    er_diagram = BytesIO()
    er_diagram.name = 'er_diagram'

    table, relationships = all_to_intermediary(db.Model)
    dot_file = _intermediary_to_dot(table, relationships)
    graph = AGraph().from_string(dot_file)
    graph.draw(er_diagram, prog='dot', format='png')

    er_diagram.seek(0)
    return send_file(er_diagram, attachment_filename='er_diagram.png', mimetype='image/png')
def test_flask_sqlalchemy():
    from flask_sqlalchemy import SQLAlchemy
    from flask import Flask
    from eralchemy.main import all_to_intermediary
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    db = SQLAlchemy(app)
    model = db.Model
    model.metadata = Base.metadata
    tables, relationships = all_to_intermediary(db.Model)
    check_intermediary_representation_simple_all_table(tables, relationships)
def test_flask_sqlalchemy():
    from flask_sqlalchemy import SQLAlchemy
    from flask import Flask
    from eralchemy.main import all_to_intermediary
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    db = SQLAlchemy(app)
    model = db.Model
    model.metadata = Base.metadata
    tables, relationships = all_to_intermediary(db.Model)
    check_intermediary_representation_simple_all_table(tables, relationships)
示例#6
0
def test_all_to_intermediary_base():
    tables, relationships = all_to_intermediary(Base)
    check_intermediary_representation_simple_table(tables, relationships)
示例#7
0
def test_all_to_intermediary_fails():
    with pytest.raises(ValueError):
        all_to_intermediary('plop')
示例#8
0
def test_all_to_intermediary_markdown():
    tables, relationships = all_to_intermediary(markdown.split('\n'))
    check_intermediary_representation_simple_table(tables, relationships)
示例#9
0
def test_all_to_intermediary_db():
    db_uri = create_db()
    tables, relationships = all_to_intermediary(db_uri)
    check_intermediary_representation_simple_table(tables, relationships)
示例#10
0
def test_all_to_intermediary_db_sqlite():
    db_uri = create_db(db_uri="sqlite:///test.db", use_sqlite=True)
    tables, relationships = all_to_intermediary(db_uri)
    check_intermediary_representation_simple_table(tables, relationships)
示例#11
0
def test_all_to_intermediary_fails():
    with pytest.raises(ValueError):
        all_to_intermediary('plop')
示例#12
0
def test_all_to_intermediary_markdown():
    tables, relationships = all_to_intermediary(markdown.split('\n'))
    check_intermediary_representation_simple_table(tables, relationships)
示例#13
0
def test_all_to_intermediary_db():
    db_uri = create_db()
    tables, relationships = all_to_intermediary(db_uri)
    check_intermediary_representation_simple_table(tables, relationships)
示例#14
0
def test_all_to_intermediary_db_sqlite():
    db_uri = create_db(db_uri="sqlite:///test.db", use_sqlite=True)
    tables, relationships = all_to_intermediary(db_uri)
    check_intermediary_representation_simple_table(tables, relationships)
示例#15
0
def test_all_to_intermediary_base():
    tables, relationships = all_to_intermediary(Base)
    check_intermediary_representation_simple_all_table(tables, relationships)