Skip to content
Open
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
27 changes: 27 additions & 0 deletions muckrock/foia/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
crowdfund_request,
raw,
)
from muckrock.foia.views.communications import FOIACommunicationDirectAgencyView
from muckrock.jurisdiction.factories import ExampleAppealFactory
from muckrock.jurisdiction.models import Appeal
from muckrock.project.forms import ProjectManagerForm
Expand Down Expand Up @@ -1256,3 +1257,29 @@ def test_composer_detail_multi_submitted(self):
)
assert response.status_code == 200
assert response.template_name == ["foia/foiacomposer_detail.html"]


class TestCommunicationViews(TestCase):
"""Tests for communication-related views"""

def setUp(self):
"""Set up tests"""
self.factory = RequestFactory()
self.comm = FOIACommunicationFactory()

def test_direct_agency_email_link_redirect(self):
"""Test that form_valid redirects with idx parameter after sending email link"""
from muckrock.foia.forms.comms import AgencyEmailLinkForm
from unittest.mock import Mock

form = Mock(spec=AgencyEmailLinkForm)
form.send_link = Mock()

view = FOIACommunicationDirectAgencyView()
view.object = self.comm

response = view.form_valid(form)

form.send_link.assert_called_once()
assert response.status_code == 302
assert response.url == f"/respond/{self.comm.pk}/"
2 changes: 1 addition & 1 deletion muckrock/foia/views/communications.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def post(self, request, *args, **kwargs):
def form_valid(self, form):
"""Send the email the login link"""
form.send_link()
return redirect("communication-direct-agency")
return redirect("communication-direct-agency", idx=self.object.pk)

def get_form_kwargs(self):
"""Pass the request to the form"""
Expand Down
Loading