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"))
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
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'))
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
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
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
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
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
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
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
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
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
def test_serve(): with mock.patch("flask.Flask.run") as run: run_main(["serve"]) run.assert_called_with(debug=True, port=5000)
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
def test_subcommand_help(): assert 'my-subcommand' in run_main(['--help'])
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()
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)
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")'
def test_subcommand_help(): assert 'my-subcommand' in run_main(['--help'])
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)
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)
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")
def test_serve(): with mock.patch("flask.Flask.run") as run: run_main(["serve"]) run.assert_called_with(debug=True, port=5000)
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')
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)
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()
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")'
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')
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
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')
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')
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")'