-
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.
add SODARUserAdditionalEmail model (#874)
- Loading branch information
Showing
4 changed files
with
228 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Generated by Django 4.2.11 on 2024-04-25 11:48 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("projectroles", "0028_populate_finder_role"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="SODARUserAdditionalEmail", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("email", models.EmailField(help_text="Email address", max_length=254)), | ||
( | ||
"verified", | ||
models.BooleanField( | ||
default=False, help_text="Email verification status" | ||
), | ||
), | ||
( | ||
"secret", | ||
models.CharField( | ||
help_text="Secret token for email verification", | ||
max_length=255, | ||
unique=True, | ||
), | ||
), | ||
( | ||
"date_created", | ||
models.DateTimeField( | ||
auto_now_add=True, help_text="DateTime of creation" | ||
), | ||
), | ||
( | ||
"date_modified", | ||
models.DateTimeField( | ||
auto_now=True, help_text="DateTime of last modification" | ||
), | ||
), | ||
( | ||
"sodar_uuid", | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
help_text="SODARUserAdditionalEmail SODAR UUID", | ||
unique=True, | ||
), | ||
), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
help_text="User for whom the email is assigned", | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="additional_emails", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"ordering": ["user__username", "email"], | ||
"unique_together": {("user", "email")}, | ||
}, | ||
), | ||
] |
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
AppSetting, | ||
RemoteSite, | ||
RemoteProject, | ||
SODARUserAdditionalEmail, | ||
SODAR_CONSTANTS, | ||
ROLE_RANKING, | ||
CAT_DELIMITER, | ||
|
@@ -45,6 +46,8 @@ | |
REMOTE_SITE_URL = 'https://sodar.example.org' | ||
REMOTE_SITE_SECRET = build_secret() | ||
REMOTE_SITE_USER_DISPLAY = True | ||
ADD_EMAIL = '[email protected]' | ||
ADD_EMAIL_SECRET = build_secret() | ||
|
||
|
||
class ProjectMixin: | ||
|
@@ -297,6 +300,21 @@ def make_sodar_user( | |
return user | ||
|
||
|
||
class SODARUserAdditionalEmailMixin: | ||
"""Helper mixin for SODARUserAdditionalEmail creation""" | ||
|
||
def make_email(self, user, email, verified, secret=build_secret()): | ||
values = { | ||
'user': user, | ||
'email': email, | ||
'verified': verified, | ||
'secret': secret, | ||
} | ||
email = SODARUserAdditionalEmail(**values) | ||
email.save() | ||
return email | ||
|
||
|
||
class TestProject(ProjectMixin, RoleMixin, RoleAssignmentMixin, TestCase): | ||
"""Tests for model.Project""" | ||
|
||
|
@@ -1547,3 +1565,47 @@ def test_update_ldap_username(self): | |
self.user.username = 'user@example' | ||
self.user.update_ldap_username() | ||
self.assertEqual(self.user.username, 'user@EXAMPLE') | ||
|
||
|
||
class TestSODARUserAdditionalEmail(SODARUserAdditionalEmailMixin, TestCase): | ||
"""Tests for SODARUserAdditionalEmail""" | ||
|
||
def setUp(self): | ||
self.user = self.make_user('user') | ||
self.email = self.make_email( | ||
user=self.user, | ||
email=ADD_EMAIL, | ||
verified=True, | ||
secret=ADD_EMAIL_SECRET, | ||
) | ||
|
||
def test_initialization(self): | ||
"""Test SODARUserAdditionalEmail initialization""" | ||
expected = { | ||
'id': self.email.pk, | ||
'user': self.user.pk, | ||
'email': ADD_EMAIL, | ||
'verified': True, | ||
'secret': ADD_EMAIL_SECRET, | ||
'sodar_uuid': self.email.sodar_uuid, | ||
} | ||
self.assertEqual(model_to_dict(self.email), expected) | ||
|
||
def test__str__(self): | ||
"""Test SODARUserAdditionalEmail __str__()""" | ||
self.assertEqual(self.email.__str__(), 'user: [email protected]') | ||
|
||
def test__repr__(self): | ||
"""Test SODARUserAdditionalEmail __repr__()""" | ||
expected = 'SODARUserAdditionalEmail(\'{}\')'.format( | ||
'\', \''.join( | ||
[ | ||
self.email.user.username, | ||
self.email.email, | ||
str(self.email.verified), | ||
self.email.secret, | ||
str(self.email.sodar_uuid), | ||
] | ||
) | ||
) | ||
self.assertEqual(self.email.__repr__(), expected) |