-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from djangonaut-space/develop
Production deployment
- Loading branch information
Showing
43 changed files
with
825 additions
and
305 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Djangonaut Space | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,23 @@ | ||
import factory | ||
from django.db.models.signals import post_save | ||
from accounts.models import CustomUser, UserProfile | ||
|
||
|
||
@factory.django.mute_signals(post_save) | ||
class ProfileFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = UserProfile | ||
|
||
user = factory.SubFactory("accounts.factories.UserFactory", profile=None) | ||
|
||
|
||
@factory.django.mute_signals(post_save) | ||
class UserFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = CustomUser | ||
|
||
username = factory.Sequence(lambda n: "user_%d" % n) | ||
first_name = "Jane" | ||
last_name = "Doe" | ||
email = "example@example.com" | ||
profile = factory.RelatedFactory(ProfileFactory, factory_related_name="user") |
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
18 changes: 18 additions & 0 deletions
18
accounts/migrations/0008_userprofile_receiving_program_updates.py
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,18 @@ | ||
# Generated by Django 4.1.13 on 2024-02-15 19:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("accounts", "0007_alter_userprofile_user"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="userprofile", | ||
name="receiving_program_updates", | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
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,57 @@ | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
from django.utils.encoding import force_bytes | ||
from django.utils.http import urlsafe_base64_encode | ||
|
||
from accounts.factories import UserFactory | ||
from accounts.tokens import account_activation_token | ||
|
||
|
||
class ActivateViewTests(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = UserFactory.create() | ||
|
||
def test_user_does_not_exist(self): | ||
activate_url = reverse( | ||
"activate_account", | ||
kwargs={ | ||
"uidb64": urlsafe_base64_encode(force_bytes("500")), | ||
"token": account_activation_token.make_token(self.user), | ||
}, | ||
) | ||
response = self.client.get(activate_url, follow=True) | ||
self.assertRedirects(response, reverse("signup")) | ||
self.assertContains(response, "Your confirmation link is invalid.") | ||
self.user.profile.refresh_from_db() | ||
self.assertFalse(self.user.profile.email_confirmed) | ||
|
||
def test_invalid_token(self): | ||
activate_url = reverse( | ||
"activate_account", | ||
kwargs={ | ||
"uidb64": urlsafe_base64_encode(force_bytes(self.user.pk)), | ||
"token": "INVALID_TOKEN", | ||
}, | ||
) | ||
response = self.client.get(activate_url, follow=True) | ||
self.assertRedirects(response, reverse("signup")) | ||
self.assertContains(response, "Your confirmation link is invalid.") | ||
self.user.profile.refresh_from_db() | ||
self.assertFalse(self.user.profile.email_confirmed) | ||
|
||
def test_activate_email(self): | ||
activate_url = reverse( | ||
"activate_account", | ||
kwargs={ | ||
"uidb64": urlsafe_base64_encode(force_bytes(self.user.pk)), | ||
"token": account_activation_token.make_token(self.user), | ||
}, | ||
) | ||
response = self.client.get(activate_url) | ||
self.assertRedirects(response, reverse("profile")) | ||
self.user.profile.refresh_from_db() | ||
self.assertTrue(self.user.profile.email_confirmed) |
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,28 @@ | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
|
||
from accounts.factories import ProfileFactory | ||
|
||
|
||
class ProfileViewTests(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
profile = ProfileFactory.create(user__username="test") | ||
cls.user = profile.user | ||
cls.profile_url = reverse("profile") | ||
|
||
def test_redirect_when_unauthenticated(self): | ||
response = self.client.get(self.profile_url, follow=True) | ||
self.assertRedirects(response, f"{reverse('login')}?next={self.profile_url}") | ||
|
||
def test_profile(self): | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.profile_url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Welcome, Jane") | ||
self.assertContains(response, "Profile Info") | ||
self.assertContains(response, "test") | ||
self.assertContains(response, "Jane Doe") |
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,59 @@ | ||
from unittest.mock import patch | ||
|
||
from django.core import mail | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
|
||
from accounts.models import CustomUser | ||
|
||
|
||
class SignUpViewTests(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
self.url = reverse("signup") | ||
|
||
def test_signup_template_renders(self): | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Registration") | ||
|
||
@patch("captcha.fields.ReCaptchaField.validate", return_value=True) | ||
def test_signup_template_post_success(self, mock_captcha): | ||
response = self.client.post( | ||
self.url, | ||
data={ | ||
"username": "janedoe", | ||
"email": "jane@whoareyou.com", | ||
"first_name": "Jane", | ||
"last_name": "Doe", | ||
"password1": "secretpassword123", | ||
"password2": "secretpassword123", | ||
"email_consent": True, | ||
"accepted_coc": True, | ||
"receive_newsletter": True, | ||
"receive_program_updates": True, | ||
"receive_event_updates": True, | ||
"g-recaptcha-response": "dummy-response", | ||
}, | ||
follow=True, | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Registration") | ||
self.assertContains( | ||
response, | ||
"Your registration was successful. Please check your email provided for a confirmation link.", | ||
) | ||
self.assertEqual(len(mail.outbox), 1) | ||
self.assertEqual( | ||
mail.outbox[0].subject, "Djangonaut Space Registration Confirmation" | ||
) | ||
self.assertIn( | ||
"Thank you for signing up to Djangonaut Space! Click the link to verify your email:", | ||
mail.outbox[0].body, | ||
) | ||
created_user = CustomUser.objects.get(username="janedoe") | ||
self.assertTrue(created_user.is_active) | ||
self.assertTrue(created_user.profile.accepted_coc) | ||
self.assertTrue(created_user.profile.receiving_newsletter) | ||
self.assertTrue(created_user.profile.receiving_program_updates) | ||
self.assertTrue(created_user.profile.receiving_event_updates) |
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,43 @@ | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
|
||
from accounts.factories import ProfileFactory | ||
|
||
|
||
class UnsubscribeViewTests(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
profile = ProfileFactory.create( | ||
receiving_newsletter=True, | ||
receiving_program_updates=True, | ||
receiving_event_updates=True, | ||
) | ||
cls.user = profile.user | ||
cls.unsubscribe_url = reverse( | ||
"unsubscribe", kwargs={"user_id": cls.user.id, "token": "dummytoken"} | ||
) | ||
|
||
def test_user_does_not_exist(self): | ||
response = self.client.get( | ||
reverse("unsubscribe", kwargs={"user_id": 500, "token": "dummytoken"}) | ||
) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_redirect_when_unauthenticated(self): | ||
response = self.client.get(self.unsubscribe_url) | ||
self.assertRedirects( | ||
response, f"{reverse('login')}?next={self.unsubscribe_url}" | ||
) | ||
|
||
def test_unsubscribe(self): | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.unsubscribe_url) | ||
self.assertEqual(response.status_code, 200) | ||
profile = self.user.profile | ||
profile.refresh_from_db() | ||
self.assertFalse(profile.receiving_newsletter) | ||
self.assertFalse(profile.receiving_program_updates) | ||
self.assertFalse(profile.receiving_event_updates) |
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
Oops, something went wrong.