Skip to content
Draft
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
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ jobs:
tox-env: py37-django{22}
- python-version: 3.8
tox-env: py38-django{22}
- python-version: 3.6
tox-env: py36-django{32}
- python-version: 3.7
tox-env: py37-django{32}
- python-version: 3.8
tox-env: py38-django{32}
- python-version: 3.8
tox-env: py38-django{40}
- python-version: 3.9
tox-env: py39-django{40}

name: Test (python ${{ matrix.python-version }})
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion django_postgres_hot_upgrade/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
default_app_config = "django_postgres_hot_upgrade.app.PostgresHotUpgradeConfig"
import django

if django.VERSION[:2] < (3, 2):
default_app_config = "django_postgres_hot_upgrade.apps.PostgresHotUpgradeConfig"
32 changes: 16 additions & 16 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import pytest
from django.db.backends import signals as django_signals

from django_postgres_hot_upgrade import app
from django_postgres_hot_upgrade import apps


@pytest.fixture(autouse=True)
def module_cache():
app._version_cache = {}
apps._version_cache = {}
yield
app._version_cache = {}
apps._version_cache = {}


@pytest.mark.parametrize(
Expand All @@ -21,7 +21,7 @@ def module_cache():
)
def test_should_run(mocker, vendor, alias, expected):
connection = mocker.Mock(vendor=vendor, alias=alias)
assert app._should_run(connection) is expected
assert apps._should_run(connection) is expected


def test_config_ready():
Expand All @@ -39,35 +39,35 @@ def fake_connection(mocker):


def test_on_connect_should_not_run(fake_connection, mocker):
clear = mocker.patch("django_postgres_hot_upgrade.app._clear")
clear = mocker.patch("django_postgres_hot_upgrade.apps._clear")
fake_connection = mocker.Mock(vendor="mysql", alias="default")
app._on_connect(connection=fake_connection)
apps._on_connect(connection=fake_connection)
clear.assert_not_called()


def test_on_connect_first_call(fake_connection, mocker):
clear = mocker.patch("django_postgres_hot_upgrade.app._clear")
clear = mocker.patch("django_postgres_hot_upgrade.apps._clear")
fake_connection.connection.server_version = 100000
app._on_connect(connection=fake_connection)
assert app._version_cache == {"default": 100000}
apps._on_connect(connection=fake_connection)
assert apps._version_cache == {"default": 100000}
clear.assert_called()


def test_on_connect_second_call_same_version(fake_connection, mocker):
clear = mocker.patch("django_postgres_hot_upgrade.app._clear")
clear = mocker.patch("django_postgres_hot_upgrade.apps._clear")
fake_connection.connection.server_version = 100000
app._on_connect(connection=fake_connection)
apps._on_connect(connection=fake_connection)
clear.reset_mock()
app._on_connect(connection=fake_connection)
apps._on_connect(connection=fake_connection)
clear.assert_not_called()


def test_on_connect_second_call_different_version(fake_connection, mocker):
clear = mocker.patch("django_postgres_hot_upgrade.app._clear")
clear = mocker.patch("django_postgres_hot_upgrade.apps._clear")
fake_connection.connection.server_version = 100000
app._on_connect(connection=fake_connection)
apps._on_connect(connection=fake_connection)
fake_connection.connection.server_version = 120000
clear.reset_mock()
app._on_connect(connection=fake_connection)
assert app._version_cache == {"default": 120000}
apps._on_connect(connection=fake_connection)
assert apps._version_cache == {"default": 120000}
clear.assert_called()
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
skipsdist = False
envlist =
linters
py{36,37,38}-django{22}
py{36,37,38}-django{22,32}
py{38,39}-django40

[testenv]
commands =
pip freeze -l
./runtests {posargs}
deps =
django22: Django~=2.2.0
django32: Django~=3.2.0
django40: Django~=4.0.0
extras =
dev
setenv =
Expand Down