def get_db_settings(): settings = testing.get_settings() if annotations['testdatabase'] == 'DUMMY': return settings settings['databases']['db']['storage'] = 'postgresql' settings['databases']['db']['dsn'] = { 'scheme': 'postgres', 'dbname': 'guillotina', 'user': '******', 'host': annotations.get('pg_host', 'localhost'), 'port': annotations.get('pg_port', 5432), 'password': '', } options = dict( host=annotations.get('pg_host', 'localhost'), port=annotations.get('pg_port', 5432), ) if annotations['testdatabase'] == 'cockroachdb': configure_db(settings['databases']['db'], **options, user='******', storage='cockroach') configure_db(settings['storages']['db'], **options, user='******', storage='cockroach') else: configure_db(settings['databases']['db'], **options) configure_db(settings['storages']['db'], **options) return settings
def get_db_settings(pytest_node=None): settings = testing.get_settings() if annotations["redis"] is not None: if "redis" not in settings: settings["redis"] = {} settings["redis"]["host"] = annotations["redis"][0] settings["redis"]["port"] = annotations["redis"][1] # Inject memcached docker fixture config into settings try: memcached = annotations["memcached"] except KeyError: memcached = None if memcached is not None: if "memcached" not in settings: settings["memcached"] = {} host, port = memcached settings["memcached"]["hosts"] = [f"{host}:{port}"] if annotations["testdatabase"] == "DUMMY": return _update_from_pytest_markers(settings, pytest_node) settings["databases"]["db"]["storage"] = "postgresql" settings["databases"]["db"]["db_schema"] = annotations["test_dbschema"] settings["databases"]["db"]["dsn"] = { "scheme": "postgres", "dbname": annotations.get("pg_db", "guillotina"), "user": "******", "host": annotations.get("pg_host", "localhost"), "port": annotations.get("pg_port", 5432), "password": "", } options = dict( host=annotations.get("pg_host", "localhost"), port=annotations.get("pg_port", 5432), dbname=annotations.get("pg_db", "guillotina"), ) settings = _update_from_pytest_markers(settings, pytest_node) if annotations["testdatabase"] == "cockroachdb": configure_db(settings["databases"]["db"], **options, user="******", storage="cockroach") configure_db(settings["databases"]["db-custom"], **options, user="******", storage="cockroach") configure_db(settings["storages"]["db"], **options, user="******", storage="cockroach") else: configure_db(settings["databases"]["db"], **options) configure_db(settings["databases"]["db-custom"], **options) configure_db(settings["storages"]["db"], **options) return settings
def get_dummy_settings(): settings = testing.get_settings() settings['databases'][0]['db']['storage'] = 'DUMMY' settings['databases'][0]['db'][ 'partition'] = 'guillotina.interfaces.IResource' settings['databases'][0]['db']['dsn'] = {} return settings
def get_settings(): settings = testing.get_settings() settings['elasticsearch']['connection_settings']['endpoints'] = [ '{}:{}'.format( getattr(elasticsearch, 'host', 'localhost'), getattr(elasticsearch, 'port', '9200'), ) ] return settings
def test_gen_key_command(command_arguments): command_arguments.key_type = 'oct' command_arguments.key_size = 256 command = CryptoCommand(command_arguments) settings = testing.get_settings() f = io.StringIO() with redirect_stdout(f): command.run_command(settings=settings) out = f.getvalue() key = json.loads(out) assert 'k' in key assert 'kty' in key
def test_not_warn_about_jwt_secret(loop, caplog): settings = deepcopy(testing.get_settings()) settings.update({ "debug": True, "jwt": { "algorithm": "HS256", "secret": "secret" } }) with caplog.at_level(logging.WARNING, logger="guillotina"): globalregistry.reset() loop.run_until_complete(make_app(settings=settings, loop=loop)) assert len(caplog.records) == 0
def test_warn_about_jwt_complexity(loop, caplog): settings = deepcopy(testing.get_settings()) settings.update({ "debug": False, "jwt": { "algorithm": "HS256", "secret": "DKK@7328*!&@@" } }) with caplog.at_level(logging.WARNING, logger="guillotina"): globalregistry.reset() loop.run_until_complete(make_app(settings=settings, loop=loop)) assert len(caplog.records) == 1 assert "insecure secret" in caplog.records[0].message
def get_db_settings(pytest_node=None): settings = testing.get_settings() settings = _update_from_pytest_markers(settings, pytest_node) if annotations['redis'] is not None: if 'redis' not in settings: settings['redis'] = {} settings['redis']['host'] = annotations['redis'][0] settings['redis']['port'] = annotations['redis'][1] if annotations['testdatabase'] == 'DUMMY': return settings settings['databases']['db']['storage'] = 'postgresql' settings['databases']['db']['db_schema'] = annotations['test_dbschema'] settings['databases']['db']['dsn'] = { 'scheme': 'postgres', 'dbname': 'guillotina', 'user': '******', 'host': annotations.get('pg_host', 'localhost'), 'port': annotations.get('pg_port', 5432), 'password': '', } options = dict( host=annotations.get('pg_host', 'localhost'), port=annotations.get('pg_port', 5432), ) if annotations['testdatabase'] == 'cockroachdb': configure_db( settings['databases']['db'], **options, user='******', storage='cockroach') configure_db( settings['databases']['db-custom'], **options, user='******', storage='cockroach') configure_db( settings['storages']['db'], **options, user='******', storage='cockroach') else: configure_db(settings['databases']['db'], **options) configure_db(settings['databases']['db-custom'], **options) configure_db(settings['storages']['db'], **options) return settings
def test_warn_about_jwt_secret(loop, caplog): settings = deepcopy(testing.get_settings()) settings.update({ 'debug': False, 'jwt': { "algorithm": "HS256", 'secret': 'secret' } }) with caplog.at_level(logging.WARNING, logger='guillotina'): globalregistry.reset() loop.run_until_complete(make_app(settings=settings, loop=loop)) assert len(caplog.records) == 1 assert 'strongly advised' in caplog.records[0].message
async def test_not_warn_about_jwt_secret(event_loop, caplog): settings = deepcopy(testing.get_settings()) settings.update({ "debug": True, "jwt": { "algorithm": "HS256", "secret": "secret" } }) with caplog.at_level(logging.WARNING, logger="guillotina"): globalregistry.reset() app = make_app(settings=settings, loop=event_loop) await app.startup() assert len(caplog.records) == 0 await app.shutdown()
async def test_startup_doesnt_write_txn_contextvar_in_main_task(command_arguments): with pytest.raises(TransactionNotFound): get_current_transaction() async def run(args, settings, app): with pytest.raises(TransactionNotFound): get_current_transaction() settings = testing.get_settings() command = Command(command_arguments) command.run = run app = command.make_app(settings) await command._run_async(app, settings) with pytest.raises(TransactionNotFound): get_current_transaction()
def test_run_command(command_arguments): _, filepath = mkstemp(suffix='.py') _, filepath2 = mkstemp() with open(filepath, 'w') as fi: fi.write(f''' async def run(app): with open("{filepath2}", 'w') as fi: fi.write("foobar") ''') command_arguments.script = filepath command = RunCommand(command_arguments) settings = testing.get_settings() command.run_command(settings=settings) with open(filepath2) as fi: assert fi.read() == 'foobar'
def get_db_settings(pytest_node=None): settings = testing.get_settings() settings = _update_from_pytest_markers(settings, pytest_node) if annotations["redis"] is not None: if "redis" not in settings: settings["redis"] = {} settings["redis"]["host"] = annotations["redis"][0] settings["redis"]["port"] = annotations["redis"][1] if annotations["testdatabase"] == "DUMMY": return settings settings["databases"]["db"]["storage"] = "postgresql" settings["databases"]["db"]["db_schema"] = annotations["test_dbschema"] settings["databases"]["db"]["dsn"] = { "scheme": "postgres", "dbname": "guillotina", "user": "******", "host": annotations.get("pg_host", "localhost"), "port": annotations.get("pg_port", 5432), "password": "", } options = dict(host=annotations.get("pg_host", "localhost"), port=annotations.get("pg_port", 5432)) if annotations["testdatabase"] == "cockroachdb": configure_db(settings["databases"]["db"], **options, user="******", storage="cockroach") configure_db(settings["databases"]["db-custom"], **options, user="******", storage="cockroach") configure_db(settings["storages"]["db"], **options, user="******", storage="cockroach") else: configure_db(settings["databases"]["db"], **options) configure_db(settings["databases"]["db-custom"], **options) configure_db(settings["storages"]["db"], **options) return settings
def get_pg_settings(): settings = testing.get_settings() settings['databases'][0]['db']['storage'] = 'postgresql' settings['databases'][0]['db']['partition'] = \ 'guillotina.interfaces.IResource' settings['databases'][0]['db']['dsn'] = { 'scheme': 'postgres', 'dbname': 'guillotina', 'user': '******', 'host': getattr(get_pg_settings, 'host', 'localhost'), 'port': getattr(get_pg_settings, 'port', 5432), 'password': '', } if USE_COCKROACH: settings['databases'][0]['db']['storage'] = 'cockroach' settings['databases'][0]['db']['dsn'].update({'user': '******'}) return settings
def get_db_settings(): settings = testing.get_settings() if annotations['testdatabase'] == 'DUMMY': return settings settings['databases']['db']['storage'] = 'postgresql' settings['databases']['db']['db_schema'] = annotations['test_dbschema'] settings['databases']['db']['dsn'] = { 'scheme': 'postgres', 'dbname': 'guillotina', 'user': '******', 'host': annotations.get('pg_host', 'localhost'), 'port': annotations.get('pg_port', 5432), 'password': '', } options = dict( host=annotations.get('pg_host', 'localhost'), port=annotations.get('pg_port', 5432), ) if annotations['testdatabase'] == 'cockroachdb': configure_db( settings['databases']['db'], **options, user='******', storage='cockroach') configure_db( settings['databases']['db-custom'], **options, user='******', storage='cockroach') configure_db( settings['storages']['db'], **options, user='******', storage='cockroach') else: configure_db(settings['databases']['db'], **options) configure_db(settings['databases']['db-custom'], **options) configure_db(settings['storages']['db'], **options) return settings
def get_dummy_settings(pytest_node=None): settings = testing.get_settings() settings["databases"]["db"]["storage"] = "DUMMY" settings["databases"]["db"]["dsn"] = {} settings = _update_from_pytest_markers(settings, pytest_node) return settings
def get_dummy_settings(): settings = testing.get_settings() settings['databases']['db']['storage'] = 'DUMMY' settings['databases']['db']['dsn'] = {} return settings
def get_dummy_settings(pytest_node=None): settings = testing.get_settings() settings = _update_from_pytest_markers(settings, pytest_node) settings['databases']['db']['storage'] = 'DUMMY' settings['databases']['db']['dsn'] = {} return settings