-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Testsuite updates and some tests (#3)
* 📦 Updates dev reqs * ⚙️ Updates test settings * 🚜 Refactor test settings * 💚 Adds a simple model test This is what we were working towards and why we made the other changes. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * 💚 Adds router tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ⚙️ 🔨 mypy fixes? * 📝 commits blank file to make mypy happy * 🚜 Adds/updates lint+mypy tasks * ⚙️ Fixes coverage ignore migrations * ⚙️ Sets coverage to 33% (we will increase this) * ⚙️ ⬇️ Drop coverage * ⚙️ Configures pytest-coverage support * 💚 Adds test_runrelay cmd * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add intro to README * adjust formatting * adjust wording * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add docker publish job to release workflow * add if checks to release workflow * add correct DATABASES settings for PgBouncer (#7) * add default email settings to service (#9) * fix router name in README * move version to pyproject.toml * add changelog * add py.typed file, aspirationally * fix backend name in README * change test workflow trigger (#14) * move version back to package (#13) * remove Django 4.0 (#12) * add support for user settings from environ (#15) * add support for user settings from environ * make mypy happy * add more logging to relay (#19) * 🤖 Bump docker/build-push-action from 4 to 5 (#16) Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 4 to 5. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](docker/build-push-action@v4...v5) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * 🤖 Bump docker/login-action from 2 to 3 (#17) Bumps [docker/login-action](https://github.com/docker/login-action) from 2 to 3. - [Release notes](https://github.com/docker/login-action/releases) - [Commits](docker/login-action@v2...v3) --- updated-dependencies: - dependency-name: docker/login-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * 🤖 Bump docker/setup-buildx-action from 2 to 3 (#18) Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2 to 3. - [Release notes](https://github.com/docker/setup-buildx-action/releases) - [Commits](docker/setup-buildx-action@v2...v3) --- updated-dependencies: - dependency-name: docker/setup-buildx-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * 🤖 [pre-commit.ci] pre-commit autoupdate (#20) updates: - [github.com/adamchainz/django-upgrade: 1.14.1 → 1.15.0](adamchainz/django-upgrade@1.14.1...1.15.0) - [github.com/astral-sh/ruff-pre-commit: v0.0.290 → v0.0.291](astral-sh/ruff-pre-commit@v0.0.290...v0.0.291) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * 🚜 Run pytest-cov * ⬆️ Bumps coverage to check to >50% * ⚙️ Run normal pytest * 🚜 Adds python -m to all the things * 🚜 Updates nox entrypoint too --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Josh <josh@joshthomas.dev> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b9fd73d
commit 60f5cef
Showing
10 changed files
with
160 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from django.conf import settings | ||
|
||
from email_relay.conf import EMAIL_RELAY_DATABASE_ALIAS | ||
|
||
pytest_plugins = [] # type: ignore | ||
|
||
|
||
# Settings fixtures to bootstrap our tests | ||
def pytest_configure(config): | ||
logging.disable(logging.CRITICAL) | ||
|
||
settings.configure( | ||
ALLOWED_HOSTS=["*"], | ||
CACHES={ | ||
"default": { | ||
"BACKEND": "django.core.cache.backends.dummy.DummyCache", | ||
} | ||
}, | ||
DATABASES={ | ||
"default": { | ||
"ENGINE": "django.db.backends.sqlite3", | ||
"NAME": ":memory:", | ||
}, | ||
EMAIL_RELAY_DATABASE_ALIAS: { | ||
"ENGINE": "django.db.backends.sqlite3", | ||
"NAME": ":memory:", | ||
}, | ||
}, | ||
DATABASE_ROUTERS=[ | ||
"email_relay.db.EmailDatabaseRouter", | ||
], | ||
EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend", | ||
INSTALLED_APPS=[ | ||
"django.contrib.contenttypes", | ||
"email_relay", | ||
], | ||
LOGGING_CONFIG=None, | ||
PASSWORD_HASHERS=["django.contrib.auth.hashers.MD5PasswordHasher"], | ||
SECRET_KEY="NOTASECRET", | ||
USE_TZ=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +0,0 @@ | ||
from __future__ import annotations | ||
|
||
from email_relay.conf import EMAIL_RELAY_DATABASE_ALIAS | ||
|
||
ALLOWED_HOSTS = ["*"] | ||
|
||
DATABASES = { | ||
"default": { | ||
"ENGINE": "django.db.backends.sqlite3", | ||
"NAME": ":memory:", | ||
}, | ||
EMAIL_RELAY_DATABASE_ALIAS: { | ||
"ENGINE": "django.db.backends.sqlite3", | ||
"NAME": ":memory:", | ||
}, | ||
} | ||
|
||
DATABASE_ROUTERS = [ | ||
"email_relay.db.EmailRelayDatabaseRouter", | ||
] | ||
|
||
|
||
EMAIL_BACKEND = "email_relay.backend.DatabaseEmailBackend" | ||
|
||
INSTALLED_APPS = [ | ||
"email_relay", | ||
] | ||
|
||
SECRET_KEY = "NOTASECRET" | ||
|
||
USE_TZ = True | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
from model_bakery import baker | ||
|
||
from email_relay.models import Message | ||
|
||
|
||
@pytest.mark.django_db(databases=["default", "email_relay_db"]) | ||
def test_message(): | ||
baker.make("email_relay.Message") | ||
assert Message.objects.all().count() == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from email_relay.conf import app_settings | ||
from email_relay.db import EmailDatabaseRouter | ||
|
||
|
||
# Mock model with app_label "email_relay" | ||
class MockModel: | ||
class _meta: | ||
app_label = "email_relay" | ||
|
||
|
||
# Mock model with app_label "some_other_app" | ||
class MockModelOther: | ||
class _meta: | ||
app_label = "some_other_app" | ||
|
||
|
||
@pytest.fixture | ||
def router(): | ||
return EmailDatabaseRouter() | ||
|
||
|
||
def test_db_for_read(router): | ||
assert router.db_for_read(MockModel) == app_settings.DATABASE_ALIAS | ||
assert router.db_for_read(MockModelOther) == "default" | ||
|
||
|
||
def test_db_for_write(router): | ||
assert router.db_for_write(MockModel) == app_settings.DATABASE_ALIAS | ||
assert router.db_for_write(MockModelOther) == "default" | ||
|
||
|
||
def test_allow_relation(router): | ||
assert router.allow_relation(None, None) | ||
|
||
|
||
def test_allow_migrate(router): | ||
assert router.allow_migrate("some_db", "some_app_label") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
from django.core.management import call_command | ||
|
||
|
||
def test_runrelay_help(): | ||
# We'll capture the output of the command | ||
with pytest.raises(SystemExit) as exec_info: | ||
# call_command will execute our command as if we ran it from the command line | ||
# the 'stdout' argument captures the command output | ||
call_command("runrelay", "--help") | ||
|
||
# Asserting that the command exits with a successful exit code (0 for help command) | ||
assert exec_info.value.code == 0 |