-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
196 additions
and
10 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,41 @@ | ||
# Generated by Django 4.2.6 on 2023-11-02 21:52 | ||
|
||
from django.conf import settings | ||
import django.core.validators | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import totem.utils.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("users", "0022_keeperprofile"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Feedback", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("email", models.EmailField(blank=True, max_length=254, null=True, verbose_name="Email Address")), | ||
( | ||
"message", | ||
totem.utils.fields.MaxLengthTextField( | ||
max_length=10000, | ||
validators=[django.core.validators.MaxLengthValidator(10000)], | ||
verbose_name="Feedback", | ||
), | ||
), | ||
("date_created", models.DateTimeField(auto_now_add=True)), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="feedback", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
] |
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,26 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<h1 class="h1 text-center text-4xl font-bold pt-20">Feedback</h1> | ||
<div class="max-w-[600px] m-auto pt-10 pb-20 px-5"> | ||
<p class="pb-5"> | ||
We love hearing about how we can improve Totem. If you have any feedback, please let us know! | ||
</p> | ||
<form action="{% url "users:feedback" %}" method="post"> | ||
{% csrf_token %} | ||
{{ form.non_field_errors }} | ||
{% if not request.user.is_authenticated %} | ||
<div> | ||
{{ form.email.errors }} | ||
<label for="{{ form.email.id_for_label }}">Email:</label> | ||
{{ form.email }} | ||
</div> | ||
{% endif %} | ||
<div class="pt-2"> | ||
{{ form.message.errors }} | ||
<label for="{{ form.message.id_for_label }}">Your feedback:</label> | ||
{{ form.message }} | ||
</div> | ||
<input class="btn btn-primary mt-5 w-full" type="submit" value="Submit"> | ||
</form> | ||
</div> | ||
{% endblock content %} |
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
""" | ||
Module for all Form Tests. | ||
""" | ||
from django.contrib.messages import get_messages | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from totem.users.forms import UserAdminCreationForm | ||
from totem.users.models import User | ||
from totem.users.models import Feedback, User | ||
from totem.users.tests.factories import UserFactory | ||
from totem.users.views import FeedbackForm | ||
|
||
|
||
class TestUserAdminCreationForm: | ||
|
@@ -34,3 +39,49 @@ def test_username_validation_error_msg(self, user: User): | |
assert len(form.errors) == 1 | ||
assert "email" in form.errors | ||
assert form.errors["email"][0] == _("This email has already been taken.") | ||
|
||
|
||
class TestUserFeedbackView(TestCase): | ||
def test_feedback_form_display(self): | ||
response = self.client.get(reverse("users:feedback")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIsInstance(response.context["form"], FeedbackForm) | ||
|
||
def test_feedback_form_submission_authenticated(self): | ||
user = UserFactory() | ||
self.client.force_login(user) | ||
response = self.client.post( | ||
reverse("users:feedback"), | ||
data={ | ||
"message": "value2", | ||
}, | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(Feedback.objects.count(), 1) | ||
feedback = Feedback.objects.first() | ||
assert feedback | ||
self.assertEqual(feedback.user, user) | ||
self.assertEqual(feedback.email, None) | ||
self.assertEqual(feedback.message, "value2") | ||
messages = list(get_messages(response.wsgi_request)) | ||
self.assertEqual(len(messages), 1) | ||
self.assertEqual(str(messages[0]), "Feedback successfully submitted. Thank you!") | ||
|
||
def test_feedback_form_submission_unauthenticated(self): | ||
response = self.client.post( | ||
reverse("users:feedback"), | ||
data={ | ||
"email": "[email protected]", | ||
"message": "value3", | ||
}, | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(Feedback.objects.count(), 1) | ||
feedback = Feedback.objects.first() | ||
assert feedback | ||
self.assertIsNone(feedback.user) | ||
self.assertEqual(feedback.email, "[email protected]") | ||
self.assertEqual(feedback.message, "value3") | ||
messages = list(get_messages(response.wsgi_request)) | ||
self.assertEqual(len(messages), 1) | ||
self.assertEqual(str(messages[0]), "Feedback successfully submitted. Thank you!") |
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
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,9 @@ | ||
from django.core.validators import MaxLengthValidator | ||
from django.db.models import TextField | ||
|
||
|
||
class MaxLengthTextField(TextField): | ||
def __init__(self, *args, **kwargs): | ||
kwargs["max_length"] = kwargs.get("max_length", 10000) | ||
kwargs["validators"] = kwargs.get("validators", [MaxLengthValidator(kwargs["max_length"])]) | ||
super().__init__(*args, **kwargs) |