Skip to content

Commit 4721909

Browse files
committed
Switch to Django-CITEXT for PG citext support
1 parent e6cab71 commit 4721909

File tree

7 files changed

+22
-30
lines changed

7 files changed

+22
-30
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ jobs:
6565
- "3.9"
6666
- "3.10"
6767
- "3.11"
68+
django-version:
69+
- "4.0"
70+
- "4.1"
71+
- "4.2"
6872
steps:
6973
- uses: actions/checkout@v4
7074
- uses: actions/setup-python@v4
@@ -102,12 +106,7 @@ jobs:
102106
runs-on: ubuntu-latest
103107
strategy:
104108
matrix:
105-
python-version: [ "3.10" ]
106-
django-version:
107-
- "4.0"
108-
- "4.1"
109-
extras:
110-
- postgres
109+
python-version: [ "3.x" ]
111110
services:
112111
postgres:
113112
image: postgres
@@ -123,7 +122,7 @@ jobs:
123122
with:
124123
python-version: ${{ matrix.python-version }}
125124
- uses: actions/checkout@v4
126-
- run: python -m pip install Django~=${{ matrix.django-version }}.0 -e ".[test,${{ matrix.extras }}]"
125+
- run: python -m pip install -e ".[test,postgres]"
127126
- run: python -m pytest
128127
env:
129128
DB_PORT: ${{ job.services.postgres.ports[5432] }}

mailauth/contrib/user/migrations/0003_ci_unique_index.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from django.db import migrations
22

33
try:
4-
from django.contrib.postgres.fields import CIEmailField
4+
from citext import CIEmailField, CITextExtension
55
except ImportError:
6+
CITextExtension = None
67
CIEmailField = None
7-
else:
8-
from django.contrib.postgres.operations import CITextExtension
98

109

1110
def _operations():
12-
if CIEmailField:
11+
if CITextExtension:
1312
yield CITextExtension()
1413
yield migrations.AlterField(
1514
model_name="emailuser",

mailauth/contrib/user/migrations/0005_emailuser_email_hash_alter_emailuser_email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.db import migrations, models
22

33
try:
4-
from django.contrib.postgres.fields import CIEmailField
4+
from citext import CIEmailField
55
except ImportError:
66
CIEmailField = models.EmailField
77

mailauth/contrib/user/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from . import signals
88

99
try:
10-
from django.contrib.postgres.fields import CIEmailField
10+
from citext import CIEmailField
1111
except ImportError:
1212
from django.db.models import EmailField as CIEmailField
1313

pyproject.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ keywords = [
1414
"otp",
1515
"email",
1616
"authentication",
17-
"login",
18-
"2fa",
1917
"passwordless",
20-
"password",
2118
]
2219
dynamic = ["version", "description"]
2320
classifiers = [
@@ -34,13 +31,20 @@ classifiers = [
3431
"Framework :: Django",
3532
"Framework :: Django :: 4.0",
3633
"Framework :: Django :: 4.1",
34+
"Framework :: Django :: 4.2",
35+
"Framework :: Wagtail",
36+
"Framework :: Wagtail :: 2",
37+
"Framework :: Wagtail :: 3",
38+
"Framework :: Wagtail :: 4",
3739
"Topic :: Internet",
3840
"Topic :: Internet :: WWW/HTTP",
3941
"Topic :: Software Development :: Quality Assurance",
4042
"Topic :: Software Development :: Testing",
4143
]
4244
requires-python = ">=3.9"
43-
dependencies = ["django>=4.0"]
45+
dependencies = [
46+
"django>=4.0"
47+
]
4448

4549
[project.optional-dependencies]
4650
test = [
@@ -55,7 +59,7 @@ wagtail = [
5559
"wagtail>=2.8",
5660
]
5761
postgres = [
58-
"psycopg2-binary",
62+
"django-citext",
5963
]
6064

6165
[project.urls]

tests/test_models.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,10 @@
33

44
from mailauth.contrib.user import models
55

6-
try:
7-
import psycopg2
8-
except ImportError:
9-
psycopg2 = None
10-
11-
12-
postgres_only = pytest.mark.skipif(
13-
psycopg2 is None, reason="at least mymodule-1.1 required"
14-
)
15-
166

177
class TestEmailUser:
18-
@postgres_only
198
def test_email__ci_unique(self, db):
9+
pytest.importorskip("psycopg")
2010
models.EmailUser.objects.create_user("IronMan@avengers.com")
2111
with pytest.raises(IntegrityError):
2212
models.EmailUser.objects.create_user("ironman@avengers.com")

tests/testapp/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"mailauth.contrib.wagtail",
5353
"wagtail.admin",
5454
"wagtail.users",
55-
"wagtail.core",
55+
"wagtail",
5656
]
5757

5858
AUTHENTICATION_BACKENDS = ("mailauth.backends.MailAuthBackend",)

0 commit comments

Comments
 (0)