Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update autoresponses with member codes #2561

Merged
merged 6 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions amy/extforms/tests/test_training_request_form.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import date, timedelta

from django.conf import settings
from django.core import mail
from django.forms import CheckboxInput, HiddenInput
from django.test import override_settings
Expand All @@ -13,6 +14,10 @@

class TestTrainingRequestForm(TestBase):
INVALID_MEMBER_CODE_ERROR = "This code is invalid."
MEMBER_CODE_OVERRIDE_LABEL = "Continue with registration code marked as invalid"
MEMBER_CODE_OVERRIDE_EMAIL_WARNING = (
"A member of our team will check the code and follow up with you"
)

def setUp(self):
self._setUpUsersAndLogin()
Expand Down Expand Up @@ -108,6 +113,8 @@ def test_request_added(self):
# Arrange
email = self.data.get("email")
self.passCaptcha(self.data)
# before tests, check if the template invalid string exists
self.assertTrue(settings.TEMPLATES[0]["OPTIONS"]["string_if_invalid"])

# Act
rv = self.client.post(reverse("training_request"), self.data, follow=True)
Expand All @@ -123,6 +130,11 @@ def test_request_added(self):
self.assertEqual(msg.to, [email])
self.assertEqual(msg.subject, TrainingRequestCreate.autoresponder_subject)
self.assertIn("A copy of your request", msg.body)
self.assertNotIn(self.MEMBER_CODE_OVERRIDE_LABEL, msg.body)
self.assertNotIn(self.MEMBER_CODE_OVERRIDE_EMAIL_WARNING, msg.body)
self.assertNotIn(
settings.TEMPLATES[0]["OPTIONS"]["string_if_invalid"], msg.body
)

def test_invalid_request_not_added(self):
# Arrange
Expand Down Expand Up @@ -409,6 +421,8 @@ def test_member_code_validation__code_valid_override_full_request(self):
self.data["member_code"] = "valid123"
self.data["member_code_override"] = True
self.passCaptcha(self.data)
# before tests, check if the template invalid string exists
self.assertTrue(settings.TEMPLATES[0]["OPTIONS"]["string_if_invalid"])

# Act
rv = self.client.post(reverse("training_request"), data=self.data, follow=True)
Expand All @@ -419,3 +433,41 @@ def test_member_code_validation__code_valid_override_full_request(self):
self.assertFalse(
TrainingRequest.objects.get(member_code="valid123").member_code_override
)

# Test that the sender was emailed with correct content
self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0]
self.assertNotIn(self.MEMBER_CODE_OVERRIDE_LABEL, msg.body)
self.assertNotIn(self.MEMBER_CODE_OVERRIDE_EMAIL_WARNING, msg.body)
self.assertNotIn(
settings.TEMPLATES[0]["OPTIONS"]["string_if_invalid"], msg.body
)

def test_member_code_validation__code_invalid_override_full_request(self):
"""Sent email should include the member_code_override field if used."""
# Arrange
self.setUpMembership()
self.data["member_code"] = "invalid"
self.data["member_code_override"] = True
self.passCaptcha(self.data)
# before tests, check if the template invalid string exists
self.assertTrue(settings.TEMPLATES[0]["OPTIONS"]["string_if_invalid"])

# Act
rv = self.client.post(reverse("training_request"), data=self.data, follow=True)

# Assert
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.resolver_match.view_name, "training_request_confirm")
self.assertTrue(
TrainingRequest.objects.get(member_code="invalid").member_code_override
)

# Test that the sender was emailed with correct content
self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0]
self.assertIn(self.MEMBER_CODE_OVERRIDE_LABEL, msg.body)
self.assertIn(self.MEMBER_CODE_OVERRIDE_EMAIL_WARNING, msg.body)
self.assertNotIn(
settings.TEMPLATES[0]["OPTIONS"]["string_if_invalid"], msg.body
)
2 changes: 2 additions & 0 deletions amy/templates/includes/trainingrequest_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
<td>{{ object.get_review_process_display|default:"&mdash;" }}</td></tr>
<tr><th>Registration Code:</th>
<td>{{ object.member_code|default:"&mdash;" }}</td></tr>
{% if admin or object.member_code_override %}
<tr><th>Continue with registration code marked as invalid:</th>
<td>{{ object.member_code_override|yesno }}</td></tr>
{% endif %}
<tr><th>Personal name:</th>
<td>{{ object.personal }}</td></tr>
<tr><th>Middle name:</th>
Expand Down
11 changes: 10 additions & 1 deletion amy/templates/mailing/training_request.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


<p>
We receive hundreds of applications, and we cannot provide no-cost training for every applicant. Please, don't let that discourage you! We'd like to help you bring workshops and instructor training to your organisation. In the meantime, please get involved!
We receive hundreds of applications, and we cannot provide no-cost training for every applicant. Please, don't let that discourage you! We'd like to help you bring workshops and instructor training to your organisation.
</p>

In the meantime, please get involved!
Expand Down Expand Up @@ -50,5 +50,14 @@
The Carpentries Instructor Training Team
</p>

<hr>

A copy of your request is included below for your reference.

{% if object.member_code_override %}
<p>
<strong>Warning:</strong> Your registration code "{{object.member_code}}" seems to be invalid. This may be due to a typo, an expired code, a code that has not yet been activated, or a code with no training seats remaining. A member of our team will check the code and follow up with you if there are any problems that require your attention.
</p>
{% endif %}

{% include "includes/trainingrequest_details.html" with admin=False object=object %}
9 changes: 8 additions & 1 deletion amy/templates/mailing/training_request.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Open Training applications are placed in an application queue to be considered f

If you have a specific need to be trained sooner (e.g. an upcoming workshop) please let us know. Multiple applicants from a single institution generally will not be invited at once, but may be accepted individually over time. To more rapidly build an Instructor community at your institution, consider becoming a Member. For more information see: https://carpentries.org/membership/ or get in touch with memberships@carpentries.org to learn more about how we can help you make the case at your organisation.

We receive hundreds of applications, and we cannot provide no-cost training for every applicant. Please, don't let that discourage you! We'd like to help you bring workshops and instructor training to your organisation. In the meantime, please get involved!
We receive hundreds of applications, and we cannot provide no-cost training for every applicant. Please, don't let that discourage you! We'd like to help you bring workshops and instructor training to your organisation.

In the meantime, please get involved!
Join our discussion email list: https://carpentries.topicbox.com/groups/discuss
Expand All @@ -27,9 +27,16 @@ The Carpentries Instructor Training Team

A copy of your request is included below for your reference.

{% if object.member_code_override %}
**Warning:** Your registration code "{{object.member_code}}" seems to be invalid. This may be due to a typo, an expired code, a code that has not yet been activated, or a code with no training seats remaining. A member of our team will check the code and follow up with you if there are any problems that require your attention.
{% endif %}

Submission date: {{ object.created_at }}
Application Type: {{ object.get_review_process_display|default:"---" }}
Registration Code: {{ object.member_code|default:"&mdash;" }}
{% if object.member_code_override %}
Continue with registration code marked as invalid: {{object.member_code_override|yesno}}
{% endif %}
Person: {{object.personal}} {{object.middle}} {{object.family}} &lt;{{object.email}}&gt;
Github: {{ object.github|default:"---" }}
Occupation: {{ object.get_occupation_display }} {{ object.occupation_other }}
Expand Down
1 change: 1 addition & 0 deletions amy/templates/mailing/workshoprequest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ instructors in such short time.
Submission date: {{ object.created_at }}
Person: {{ object.personal }} {{ object.family }} &lt;{{ object.email }}&gt;
Institution: {% if object.institution %}{{ object.institution }}{% else %}{{ object.institution_other_name }}{% endif %}{% if object.institution_department %}, {{ object.institution_department }}{% endif %}
Member registration code: {{ object.member_code|default:"&mdash;" }}
Workshop location: {{ object.location }}
Country: {{ object.country.name }}
Requested workshop types: {% for type in object.requested_workshop_types.all %}{{ type }}{% if not forloop.last %}, {% endif %}{% endfor %}
Expand Down