Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions tests/unit/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from unittest import mock

import alembic.config
import pretend
import psycopg2.extensions
import pytest
Expand Down Expand Up @@ -85,24 +84,14 @@ def handler(config):


def test_configure_alembic(monkeypatch):
config_obj = pretend.stub(set_main_option=pretend.call_recorder(lambda *a: None))

def config_cls():
return config_obj

monkeypatch.setattr(alembic.config, "Config", config_cls)

config = pretend.stub(
registry=pretend.stub(settings={"database.url": pretend.stub()})
)
config = pretend.stub(registry=pretend.stub(settings={"database.url": "whatever"}))

alembic_config = _configure_alembic(config)

assert alembic_config is config_obj
assert alembic_config.set_main_option.calls == [
pretend.call("script_location", "warehouse:migrations"),
pretend.call("url", config.registry.settings["database.url"]),
]
configparser = alembic_config.file_config
assert configparser.get("alembic", "script_location") == "warehouse:migrations"
assert configparser.get("alembic", "url") == "whatever"
assert configparser.has_section("post_write_hooks")


@pytest.mark.parametrize("needs_reset", [True, False, None])
Expand Down
3 changes: 1 addition & 2 deletions warehouse/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ def callback(scanner, _name, wrapped):


def _configure_alembic(config):
alembic_cfg = alembic.config.Config()
alembic_cfg.set_main_option("script_location", "warehouse:migrations")
alembic_cfg = alembic.config.Config("warehouse/migrations/alembic.ini")
alembic_cfg.set_main_option("url", config.registry.settings["database.url"])
return alembic_cfg

Expand Down
8 changes: 8 additions & 0 deletions warehouse/migrations/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[alembic]
script_location = warehouse:migrations

[post_write_hooks]
hooks = black, isort

black.type = console_scripts
black.entrypoint = black