Skip to content

Commit

Permalink
fixup for model tests : set upper EMAIL var name
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Jan 28, 2025
1 parent 8cab9f7 commit 6df2853
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lacommunaute/users/tests/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@
from lacommunaute.users.models import EmailLastSeen, User


email = "alex@honnold.com"
EMAIL = "alex@honnold.com"


@pytest.fixture(name="email_last_seen")
def fixture_email_last_seen(db):
return EmailLastSeenFactory(email=email)
return EmailLastSeenFactory(email=EMAIL)


class TestUserModel:
def test_create_user_without_username(self, db):
user = User.objects.create_user(email=email)
user = User.objects.create_user(email=EMAIL)
assert re.match(r"^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$", user.username)
assert user.email == email
assert user.email == EMAIL


class TestEmailLastSeenModel:
def test_email_uniqueness(self, db, email_last_seen):
with pytest.raises(IntegrityError):
EmailLastSeenFactory(email=email)
EmailLastSeenFactory(email=EMAIL)

def test_compute_hash_on_save(self, db, email_last_seen):
assert email_last_seen.email_hash == hashlib.sha256(email.encode("utf-8")).hexdigest()
assert email_last_seen.email_hash == hashlib.sha256(EMAIL.encode("utf-8")).hexdigest()

def test_email_hash(self, db):
email = "janja@garnbret.com"
hashed_email = "bb247dfe5de638e67be1f4d5414ffbef8d3c93b6dd0513598b013e59640f584b"
assert hashlib.sha256(email.encode("utf-8")).hexdigest() == hashed_email

@pytest.mark.parametrize("updated_email", [None, email])
@pytest.mark.parametrize("updated_email", [None, EMAIL])
def test_hash_remains_unchanged_on_update(self, db, email_last_seen, updated_email):
email_last_seen.email = updated_email
email_last_seen.save()
email_last_seen.refresh_from_db()
assert email_last_seen.email_hash == hashlib.sha256(email.encode("utf-8")).hexdigest()
assert email_last_seen.email_hash == hashlib.sha256(EMAIL.encode("utf-8")).hexdigest()

def test_soft_delete(self, db, email_last_seen):
email_last_seen.soft_delete()
Expand All @@ -55,20 +55,20 @@ def test_soft_delete(self, db, email_last_seen):
class TestEmailLastSeenQueryset:
@pytest.mark.parametrize("kind", [kind for kind, _ in EmailLastSeenKind.choices])
def test_seen(self, db, email_last_seen, kind):
EmailLastSeen.objects.seen(email, kind)
EmailLastSeen.objects.seen(EMAIL, kind)

email_last_seen.refresh_from_db()
assert email_last_seen.last_seen_kind == kind
assert email_last_seen.last_seen_at is not None

def test_seen_invalid_kind(self, db, email_last_seen):
with pytest.raises(ValueError):
EmailLastSeen.objects.seen(email, "invalid_kind")
EmailLastSeen.objects.seen(EMAIL, "invalid_kind")

@pytest.mark.parametrize("kind", [kind for kind, _ in EmailLastSeenKind.choices])
def test_seen_unknown_email(self, db, kind):
EmailLastSeen.objects.seen(email, kind)
EmailLastSeen.objects.seen(EMAIL, kind)

email_last_seen = EmailLastSeen.objects.get(email=email)
email_last_seen = EmailLastSeen.objects.get()
assert email_last_seen.last_seen_kind == kind
assert email_last_seen.last_seen_at is not None

0 comments on commit 6df2853

Please sign in to comment.