8000 Switch to Django-CITEXT for PG citext support by codingjoe · Pull Request #106 · codingjoe/django-mail-auth · GitHub
[go: up one dir, main page]

Skip to content

Switch to Django-CITEXT for PG citext support #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
django-version:
- "4.0"
- "4.1"
- "4.2"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
Expand Down Expand Up @@ -102,12 +106,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10" ]
django-version:
- "4.0"
- "4.1"
extras:
- postgres
python-version: [ "3.x" ]
services:
postgres:
image: postgres
Expand All @@ -123,7 +122,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v4
- run: python -m pip install Django~=${{ matrix.django-version }}.0 -e ".[test,${{ matrix.extras }}]"
- run: python -m pip install -e ".[test,postgres]"
- run: python -m pytest
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}
Expand Down
7 changes: 3 additions & 4 deletions mailauth/contrib/user/migrations/0003_ci_unique_index.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from django.db import migrations

try:
from django.contrib.postgres.fields import CIEmailField
from citext import CIEmailField, CITextExtension
except ImportError:
CITextExtension = None
CIEmailField = None
else:
from django.contrib.postgres.operations import CITextExtension


def _operations():
if CIEmailField:
if CITextExtension:
yield CITextExtension()
yield migrations.AlterField(
model_name="emailuser",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import migrations, models

try:
from django.contrib.postgres.fields import CIEmailField
from citext import CIEmailField
except ImportError:
CIEmailField = models.EmailField

Expand Down
2 changes: 1 addition & 1 deletion mailauth/contrib/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from . import signals

try:
from django.contrib.postgres.fields import CIEmailField
from citext import CIEmailField
except ImportError:
from django.db.models import EmailField as CIEmailField

Expand Down
14 changes: 9 additions & 5 deletions pyproject.toml
EDBE
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ keywords = [
"otp",
"email",
"authentication",
"login",
"2fa",
"passwordless",
"password",
]
dynamic = ["version", "description"]
classifiers = [
Expand All @@ -34,13 +31,20 @@ classifiers = [
"Framework :: Django",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Wagtail",
"Framework :: Wagtail :: 2",
"Framework :: Wagtail :: 3",
"Framework :: Wagtail :: 4",
"Topic :: Internet",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
]
requires-python = ">=3.9"
dependencies = ["django>=4.0"]
dependencies = [
"django>=4.0"
]

[project.optional-dependencies]
test = [
Expand All @@ -55,7 +59,7 @@ wagtail = [
"wagtail>=2.8",
]
postgres = [
"psycopg2-binary",
"django-citext",
]

[project.urls]
Expand Down
12 changes: 1 addition & 11 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@

from mailauth.contrib.user import models

try:
import psycopg2
except ImportError:
psycopg2 = None


postgres_only = pytest.mark.skipif(
psycopg2 is None, reason="at least mymodule-1.1 required"
)


class TestEmailUser:
@postgres_only
def test_email__ci_unique(self, db):
pytest.importorskip("psycopg")
models.EmailUser.objects.create_user("IronMan@avengers.com")
with pytest.raises(IntegrityError):
models.EmailUser.objects.create_user("ironman@avengers.com")
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"mailauth.contrib.wagtail",
"wagtail.admin",
"wagtail.users",
"wagtail.core",
"wagtail",
]

AUTHENTICATION_BACKENDS = ("mailauth.backends.MailAuthBackend",)
Expand Down
0