| 1 |
import uuid |
| 2 |
|
| 3 |
from django.contrib.auth.models import AbstractUser |
| 4 |
from django.db import models |
| 5 |
|
| 6 |
from allauth.account.models import EmailAddress |
| 7 |
|
| 8 |
|
| 9 |
class UUIDUser(AbstractUser): |
| 10 |
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) |
| 11 |
|
| 12 |
class Meta(AbstractUser.Meta): # type: ignore[name-defined] |
| 13 |
swappable = "AUTH_USER_MODEL" |
| 14 |
app_label = "dummy" |
| 15 |
|
| 16 |
|
| 17 |
def test_add_new_email(rf, user, settings): |
| 18 |
settings.ACCOUNT_CHANGE_EMAIL = True |
| 19 |
request = rf.get("/") |
| 20 |
assert EmailAddress.objects.filter(user=user).count() == 1 |
| 21 |
new_email = EmailAddress.objects.add_new_email( |
| 22 |
request, user, "[email protected]", send_verification=False |
| 23 |
) |
| 24 |
assert not new_email.verified |
| 25 |
assert not new_email.primary |
| 26 |
assert EmailAddress.objects.filter(user=user).count() == 2 |
| 27 |
EmailAddress.objects.add_new_email( |
| 28 |
request, user, "[email protected]", send_verification=False |
| 29 |
) |
| 30 |
assert EmailAddress.objects.filter(user=user).count() == 2 |
| 31 |
assert not EmailAddress.objects.filter(pk=new_email.pk).exists() |
| 32 |
assert EmailAddress.objects.filter(email="[email protected]", verified=False).exists() |