Ejemplo n.º 1
0
def test_alembic_init():
    """ When we initialize a db, make sure that the ini exists """
    dbname = "relengapi"
    settings = {"SQLALCHEMY_DATABASE_URIS": {}}
    for name in db._declarative_bases:
        settings["SQLALCHEMY_DATABASE_URIS"][name] = "sqlite:///"  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname, copy=False) as base_dir:
        run_main(["alembic", dbname, "--directory", base_dir, "init"], settings=settings)
        assert os.path.exists(os.path.join(base_dir, dbname, "alembic.ini"))
Ejemplo n.º 2
0
def test_alembic_branches():
    dbname = "relengapi"
    settings = {"SQLALCHEMY_DATABASE_URIS": {}}
    for name in db._declarative_bases:
        settings["SQLALCHEMY_DATABASE_URIS"][name] = "sqlite:///"  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname) as base_dir:
        with mock.patch("relengapi.blueprints.base.alembic_wrapper." "AlembicBranchesSubcommand.branches") as p:
            run_main(["alembic", dbname, "--directory", base_dir, "branches"], settings=settings)
            assert p.called
Ejemplo n.º 3
0
def test_alembic_init():
    """ When we initialize a db, make sure that the ini exists """
    dbname = 'relengapi'
    settings = {'SQLALCHEMY_DATABASE_URIS': {}}
    for name in db._declarative_bases:
        settings['SQLALCHEMY_DATABASE_URIS'][name] = 'sqlite:///'  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname, copy=False) as base_dir:
            run_main(["alembic", dbname, "--directory", base_dir, "init"], settings=settings)
            assert os.path.exists(os.path.join(base_dir, dbname, 'alembic.ini'))
Ejemplo n.º 4
0
def test_alembic_revision():
    """ When creating a revision, a migration script should exist with the current head"""
    dbname = "relengapi"
    settings = {"SQLALCHEMY_DATABASE_URIS": {}}
    for name in db._declarative_bases:
        settings["SQLALCHEMY_DATABASE_URIS"][name] = "sqlite:///"  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname) as base_dir:
        # create the revision
        output = run_main(["alembic", dbname, "--directory", base_dir, "revision"], settings=settings)
        assert "Generating {}".format(base_dir) in output
Ejemplo n.º 5
0
def test_invalid_database_name():
    """show an error when we specify an invalid database name """
    dbname = "relengapi"
    settings = {"SQLALCHEMY_DATABASE_URIS": {}}
    for name in db._declarative_bases:
        settings["SQLALCHEMY_DATABASE_URIS"][name] = "sqlite:///"  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname) as base_dir:
        # create the revision
        output = run_main(["alembic", "invalid_db_name", "--directory", base_dir, "revision"], settings=settings)
        assert "specify a valid database name" in output
Ejemplo n.º 6
0
def test_invalid_configuration():
    """ When specifying a valid db that hasn't been initialized, we spit out an error message"""
    dbname = "relengapi"
    uninit_db = "clobberer"
    settings = {"SQLALCHEMY_DATABASE_URIS": {}}
    for name in db._declarative_bases:
        settings["SQLALCHEMY_DATABASE_URIS"][name] = "sqlite:///"  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname) as base_dir:
        # create the revision
        output = run_main(["alembic", uninit_db, "--directory", base_dir, "revision"], settings=settings)
        assert "Configuration file does not exist" in output
Ejemplo n.º 7
0
def test_invalid_database_name():
    """show an error when we specify an invalid database name """
    dbname = 'relengapi'
    settings = {'SQLALCHEMY_DATABASE_URIS': {}}
    for name in db._declarative_bases:
        settings['SQLALCHEMY_DATABASE_URIS'][name] = 'sqlite:///'  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname) as base_dir:
        # create the revision
        output = run_main(["alembic", 'invalid_db_name', "--directory", base_dir, "revision"],
                          settings=settings)
        assert "specify a valid database name" in output
Ejemplo n.º 8
0
def test_alembic_heads():
    dbname = 'relengapi'
    settings = {'SQLALCHEMY_DATABASE_URIS': {}}
    for name in db._declarative_bases:
        settings['SQLALCHEMY_DATABASE_URIS'][name] = 'sqlite:///'  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname) as base_dir:
        with mock.patch(
                "relengapi.blueprints.base.alembic_wrapper.AlembicHeadsSubcommand.heads") as p:
            run_main(["alembic", dbname, "--directory", base_dir, "heads"],
                     settings=settings)
            assert p.called
Ejemplo n.º 9
0
def test_alembic_revision():
    """ When creating a revision, a migration script should exist with the current head"""
    dbname = 'relengapi'
    settings = {'SQLALCHEMY_DATABASE_URIS': {}}
    for name in db._declarative_bases:
        settings['SQLALCHEMY_DATABASE_URIS'][name] = 'sqlite:///'  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname) as base_dir:
        # create the revision
        output = run_main(["alembic", dbname, "--directory", base_dir, "revision"],
                          settings=settings)
        assert "Generating {}".format(base_dir) in output
Ejemplo n.º 10
0
def test_alembic_heads():
    dbname = 'relengapi'
    settings = {'SQLALCHEMY_DATABASE_URIS': {}}
    for name in db._declarative_bases:
        settings['SQLALCHEMY_DATABASE_URIS'][name] = 'sqlite:///'  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname) as base_dir:
        with mock.patch(
                "relengapi.blueprints.base.alembic_wrapper.AlembicHeadsSubcommand.heads") as p:
            run_main(["alembic", dbname, "--directory", base_dir, "heads"],
                     settings=settings)
            assert p.called
Ejemplo n.º 11
0
def test_invalid_configuration():
    """ When specifying a valid db that hasn't been initialized, we spit out an error message"""
    dbname = 'relengapi'
    uninit_db = 'clobberer'
    settings = {'SQLALCHEMY_DATABASE_URIS': {}}
    for name in db._declarative_bases:
        settings['SQLALCHEMY_DATABASE_URIS'][name] = 'sqlite:///'  # in-memory
    run_main(["createdb"], settings=settings)
    with copy_alembic_folder(dbname) as base_dir:
        # create the revision
        output = run_main(["alembic", uninit_db, "--directory", base_dir, "revision"],
                          settings=settings)
        assert "Configuration file does not exist" in output
Ejemplo n.º 12
0
def test_createdb():
    settings = {'SQLALCHEMY_DATABASE_URIS': {}}
    for dbname in db._declarative_bases:
        settings['SQLALCHEMY_DATABASE_URIS'][
            dbname] = 'sqlite:///'  # in-memory
    output = run_main(["createdb"], settings=settings)
    assert 'creating tables for database relengapi' in output
Ejemplo n.º 13
0
def test_serve():
    with mock.patch("flask.Flask.run") as run:
        run_main(["serve"])
        run.assert_called_with(debug=True, port=5000)
Ejemplo n.º 14
0
def test_createdb():
    settings = {'SQLALCHEMY_DATABASE_URIS': {}}
    for dbname in db._declarative_bases:
        settings['SQLALCHEMY_DATABASE_URIS'][dbname] = 'sqlite:///'  # in-memory
    output = run_main(["createdb"], settings=settings)
    assert 'creating tables for database relengapi' in output
Ejemplo n.º 15
0
def test_subcommand_help():
    assert 'my-subcommand' in run_main(['--help'])
Ejemplo n.º 16
0
def test_sqs_listen():
    # this doesn't do much more than see that the AWS method is called;
    # that method is tested elsewhere
    with mock.patch("relengapi.lib.aws.AWS._spawn_sqs_listeners") as p:
        run_main(["sqs-listen"], settings={})
        p.assert_called_with()
Ejemplo n.º 17
0
def test_serve_no_debug():
    with mock.patch("flask.Flask.run") as run:
        run_main(["serve", "--no-debug"])
        run.assert_called_with(debug=False, port=5000)
Ejemplo n.º 18
0
def test_repl_command():
    output = run_main(["repl", '-c', 'print(app)\nprint("hello world")'])
    assert 'relengapi.app' in output  # from 'print(app)'
    assert 'hello world' in output  # from 'print("hello world")'
Ejemplo n.º 19
0
def test_subcommand_help():
    assert 'my-subcommand' in run_main(['--help'])
Ejemplo n.º 20
0
def test_serve_no_debug():
    with mock.patch("flask.Flask.run") as run:
        run_main(["serve", "--no-debug"])
        run.assert_called_with(debug=False, port=5000)
Ejemplo n.º 21
0
def test_serve_port():
    with mock.patch("flask.Flask.run") as run:
        run_main(["serve", "-p", "8010"])
        run.assert_called_with(debug=True, port=8010)
Ejemplo n.º 22
0
def test_serve_all_interfaces():
    with mock.patch("flask.Flask.run") as run:
        run_main(["serve", "-a"])
        run.assert_called_with(debug=True, port=5000, host="0.0.0.0")
Ejemplo n.º 23
0
def test_serve():
    with mock.patch("flask.Flask.run") as run:
        run_main(["serve"])
        run.assert_called_with(debug=True, port=5000)
Ejemplo n.º 24
0
def test_serve_all_interfaces():
    with mock.patch("flask.Flask.run") as run:
        run_main(["serve", "-a"])
        run.assert_called_with(debug=True, port=5000, host='0.0.0.0')
Ejemplo n.º 25
0
def test_serve_port():
    with mock.patch("flask.Flask.run") as run:
        run_main(["serve", "-p", "8010"])
        run.assert_called_with(debug=True, port=8010)
Ejemplo n.º 26
0
def test_sqs_listen():
    # this doesn't do much more than see that the AWS method is called;
    # that method is tested elsewhere
    with mock.patch("relengapi.lib.aws.AWS._spawn_sqs_listeners") as p:
        run_main(["sqs-listen"], settings={})
        p.assert_called_with()
Ejemplo n.º 27
0
def test_repl_command():
    output = run_main(["repl", '-c', 'print(app)\nprint("hello world")'])
    assert 'relengapi.app' in output  # from 'print(app)'
    assert 'hello world' in output  # from 'print("hello world")'
Ejemplo n.º 28
0
def test_subcommand_runs():
    output = run_main(['my-subcommand', '--result=foo'])
    assert "print output" in output
    assert "info logging output" in output
    assert "warning logging output" in output
    eq_(MySubcommand.run_result, 'foo')
Ejemplo n.º 29
0
def test_createdb():
    settings = {"SQLALCHEMY_DATABASE_URIS": {}}
    for dbname in db._declarative_bases:
        settings["SQLALCHEMY_DATABASE_URIS"][dbname] = "sqlite:///"  # in-memory
    output = run_main(["createdb"], settings=settings)
    assert "creating tables for database relengapi" in output
Ejemplo n.º 30
0
def test_subcommand_quiet():
    output = run_main(['--quiet', 'my-subcommand', '--result=foo'])
    assert "print output" in output
    assert "info logging output" not in output
    assert "warning logging output" in output
    eq_(MySubcommand.run_result, 'foo')
Ejemplo n.º 31
0
def test_subcommand_quiet():
    output = run_main(['--quiet', 'my-subcommand', '--result=foo'])
    assert "print" in output
    assert "info" not in output
    assert "warning" in output
    eq_(MySubcommand.run_result, 'foo')
Ejemplo n.º 32
0
def test_repl_command():
    output = run_main(["repl", "-c", 'print(app)\nprint("hello world")'])
    assert "relengapi.app" in output  # from 'print(app)'
    assert "hello world" in output  # from 'print("hello world")'