Skip to content

Commit

Permalink
fix: improve when Message objects are created (#5836)
Browse files Browse the repository at this point in the history
* fix: improve when Message objects are created

* test: further improve feedback test

* fix: improve and test another form

* test: Restructure test infrastructure
  • Loading branch information
rjsparks committed Jun 16, 2023
1 parent 4179d08 commit ac65232
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions ietf/nomcom/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def save(self, commit=True):
'year': self.nomcom.year(),
}
path = nomcom_template_path + NOMINATION_RECEIPT_TEMPLATE
send_mail(None, to_email, from_email, subject, path, context, cc=cc)
send_mail(None, to_email, from_email, subject, path, context, cc=cc, copy=False, save=False)

return nomination

Expand Down Expand Up @@ -458,7 +458,7 @@ def save(self, commit=True):
'year': self.nomcom.year(),
}
path = nomcom_template_path + NOMINATION_RECEIPT_TEMPLATE
send_mail(None, to_email, from_email, subject, path, context, cc=cc)
send_mail(None, to_email, from_email, subject, path, context, cc=cc, copy=False, save=False)

return nomination

Expand Down Expand Up @@ -551,7 +551,7 @@ def save(self, commit=True):
}
path = nomcom_template_path + FEEDBACK_RECEIPT_TEMPLATE
# TODO - make the thing above more generic
send_mail(None, to_email, from_email, subject, path, context, cc=cc, copy=False)
send_mail(None, to_email, from_email, subject, path, context, cc=cc, copy=False, save=False)

class Meta:
model = Feedback
Expand Down
22 changes: 12 additions & 10 deletions ietf/nomcom/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def access_member_url(self, url):
self.check_url_status(url, 200)
self.client.logout()
login_testing_unauthorized(self, MEMBER_USER, url)
return self.check_url_status(url, 200)
self.check_url_status(url, 200)

def access_chair_url(self, url):
login_testing_unauthorized(self, COMMUNITY_USER, url)
Expand All @@ -134,7 +134,7 @@ def access_secretariat_url(self, url):
login_testing_unauthorized(self, COMMUNITY_USER, url)
login_testing_unauthorized(self, CHAIR_USER, url)
login_testing_unauthorized(self, SECRETARIAT_USER, url)
return self.check_url_status(url, 200)
self.check_url_status(url, 200)

def test_private_index_view(self):
"""Verify private home view"""
Expand Down Expand Up @@ -599,6 +599,8 @@ def test_public_nominate(self):
self.nominate_view(public=True,confirmation=True)

self.assertEqual(len(outbox), messages_before + 3)
self.assertEqual(Message.objects.count(), 2)
self.assertFalse(Message.objects.filter(subject="Nomination receipt").exists())

self.assertEqual('IETF Nomination Information', outbox[-3]['Subject'])
self.assertEqual(self.email_from, outbox[-3]['From'])
Expand All @@ -625,8 +627,7 @@ def test_public_nominate(self):

def test_private_nominate(self):
self.access_member_url(self.private_nominate_url)
return self.nominate_view(public=False)
self.client.logout()
self.nominate_view(public=False)

def test_public_nominate_newperson(self):
login_testing_unauthorized(self, COMMUNITY_USER, self.public_nominate_url)
Expand Down Expand Up @@ -666,13 +667,13 @@ def test_public_nominate_newperson(self):

def test_private_nominate_newperson(self):
self.access_member_url(self.private_nominate_url)
return self.nominate_newperson_view(public=False)
self.client.logout()
self.nominate_newperson_view(public=False, confirmation=True)
self.assertFalse(Message.objects.filter(subject="Nomination receipt").exists())

def test_private_nominate_newperson_who_already_exists(self):
EmailFactory(address='[email protected]')
self.access_member_url(self.private_nominate_newperson_url)
return self.nominate_newperson_view(public=False)
self.nominate_newperson_view(public=False)

def test_public_nominate_with_automatic_questionnaire(self):
nomcom = get_nomcom_by_year(self.year)
Expand Down Expand Up @@ -844,8 +845,7 @@ def nominate_newperson_view(self, *args, **kwargs):

def test_add_questionnaire(self):
self.access_chair_url(self.add_questionnaire_url)
return self.add_questionnaire()
self.client.logout()
self.add_questionnaire()

def add_questionnaire(self, *args, **kwargs):
public = kwargs.pop('public', False)
Expand Down Expand Up @@ -906,6 +906,8 @@ def test_public_feedback(self):
# We're interested in the confirmation receipt here
self.assertEqual(len(outbox),3)
self.assertEqual('NomCom comment confirmation', outbox[2]['Subject'])
self.assertEqual(Message.objects.count(), 2)
self.assertFalse(Message.objects.filter(subject="NomCom comment confirmation").exists())
email_body = get_payload_text(outbox[2])
self.assertIn(position, email_body)
self.assertNotIn('$', email_body)
Expand All @@ -920,7 +922,7 @@ def test_public_feedback(self):

def test_private_feedback(self):
self.access_member_url(self.private_feedback_url)
return self.feedback_view(public=False)
self.feedback_view(public=False)

def feedback_view(self, *args, **kwargs):
public = kwargs.pop('public', True)
Expand Down

0 comments on commit ac65232

Please sign in to comment.