def test_my_team_barriers_filter(self, mock_list, mock_get): mock_get.return_value = SavedSearch( data={ "name": "Team barriers", "filters": {"team": "1"}, "notify_about_additions": True, "notify_about_updates": False, } ) response = self.client.get( reverse("barriers:search"), data={"team": "1"}, ) assert response.status_code == HTTPStatus.OK mock_list.assert_called_with( ordering="-reported_on", limit=settings.API_RESULTS_LIMIT, offset=0, team="1", archived="0", ) mock_get.assert_called_with("team-barriers") assert response.context["search_title"] == "Team barriers" response = self.client.get( reverse("barriers:search"), data={"user": "******", "team": "1"}, ) assert response.status_code == HTTPStatus.OK mock_list.assert_called_with( ordering="-reported_on", limit=settings.API_RESULTS_LIMIT, offset=0, team="1", user="******", archived="0", )
def test_rename_saved_search_initial(self, mock_get): mock_get.return_value = SavedSearch(self.saved_search_data) response = self.client.get(self.get_rename_url()) assert response.status_code == HTTPStatus.OK assert "form" in response.context form = response.context["form"] assert form.initial["name"] == "Search Name"
def test_notifications_initial(self, mock_get): mock_get.return_value = SavedSearch(self.saved_search_data) response = self.client.get(self.get_url()) assert response.status_code == HTTPStatus.OK assert "form" in response.context form = response.context["form"] assert form.initial["notify_about_additions"] is True assert form.initial["notify_about_updates"] is False
def test_rename_saved_search_error(self, mock_get, mock_patch): mock_get.return_value = SavedSearch(self.saved_search_data) response = self.client.post(self.get_rename_url(), data={"name": ""}) assert response.status_code == HTTPStatus.OK assert "form" in response.context form = response.context["form"] assert form.is_valid() is False assert "name" in form.errors assert mock_patch.called is False
def test_delete_saved_search(self, mock_get, mock_delete): mock_get.return_value = SavedSearch(self.saved_search_data) response = self.client.get(self.get_delete_url()) assert response.status_code == HTTPStatus.OK response = self.client.post( self.get_delete_url(), data={"saved_search_id": self.saved_search_data["id"]}, ) assert response.status_code == HTTPStatus.FOUND mock_delete.assert_called_with(self.saved_search_data["id"])
def test_saved_search_with_changed_filters(self, mock_list, mock_get): saved_search = SavedSearch(self.saved_search_data) mock_get.return_value = saved_search response = self.client.get( reverse("barriers:search"), data={"priority": "MEDIUM", "search": "yo", "search_id": saved_search.id}, ) assert response.status_code == HTTPStatus.OK assert response.context["saved_search"].id == saved_search.id assert response.context["have_filters_changed"] is True assert response.context["search_title"] is saved_search.name
def test_readable_filters(self): saved_search = SavedSearch(self.saved_search_data) assert saved_search.readable_filters["search"] == { "label": "Search barrier title, summary, code or PID", "readable_value": "Test", "value": "Test", } assert saved_search.readable_filters["country"] == { "label": "Barrier location", "readable_value": "Australia", "value": ["9f5f66a0-5d95-e211-a939-e4115bead28a"], } assert saved_search.readable_filters["sector"] == { "label": "Sector", "readable_value": "Aerospace, Food and Drink", "value": [ "9538cecc-5f95-e211-a939-e4115bead28a", "a538cecc-5f95-e211-a939-e4115bead28a", ], } assert saved_search.readable_filters["category"] == { "label": "Category", "readable_value": "Government subsidies", "value": ["127"], } assert saved_search.readable_filters["region"] == { "label": "Overseas region", "readable_value": "Europe", "value": ["3e6809d6-89f6-4590-8458-1d0dab73ad1a"], } assert saved_search.readable_filters["priority"] == { "label": "Barrier priority", "readable_value": ("<span class='priority-marker priority-marker--high'>" "</span>High, " "<span class='priority-marker priority-marker--medium'>" "</span>Medium"), "value": ["HIGH", "MEDIUM"], } assert saved_search.readable_filters["status"] == { "label": "Barrier status", "readable_value": "Open: In progress, Resolved: In part", "value": ["2", "3"], } assert saved_search.readable_filters["show"] == { "label": "Show", "readable_value": "Barriers I have created", "value": ["1"], }
def test_notifications_text(self): saved_search = SavedSearch(self.saved_search_data) saved_search.notify_about_additions = False saved_search.notify_about_updates = False assert saved_search.notifications_text == "Off" saved_search.notify_about_additions = True assert saved_search.notifications_text == "NEW" saved_search.notify_about_updates = True assert saved_search.notifications_text == "NEW and UPDATED" saved_search.notify_about_additions = False assert saved_search.notifications_text == "UPDATED"
def test_notifications_change(self, mock_get, mock_patch): mock_get.return_value = SavedSearch(self.saved_search_data) response = self.client.post( self.get_url(), data={"notify_about_updates": "1"}, ) assert response.status_code == HTTPStatus.FOUND mock_patch.assert_called_with( id=self.saved_search_data["id"], notify_about_additions=False, notify_about_updates=True, )
def test_rename_saved_search_success(self, mock_get, mock_list, mock_patch): mock_get.return_value = SavedSearch(self.saved_search_data) mock_list.return_value = [] response = self.client.post( self.get_rename_url(), data={"name": "New Name"}, ) assert response.status_code == HTTPStatus.FOUND mock_patch.assert_called_with( id=self.saved_search_data["id"], name="New Name", )
def test_update_saved_search(self, mock_get, mock_list, mock_patch): mock_get.return_value = SavedSearch(self.saved_search_data) search_id = self.saved_search_data["id"] response = self.client.post( f"{reverse('barriers:search')}" f"?search=Test&priority=HIGH&status=2&search_id={search_id}", data={"update_search": "1"}, ) assert response.status_code == HTTPStatus.OK mock_patch.assert_called_with( id=search_id, filters={ "search": "Test", "priority": ["HIGH"], "status": ["2"], }, ) assert response.context["saved_search_updated"] is True
def test_new_saved_search_success(self, mock_list, mock_create): mock_list.return_value = [] mock_create.return_value = SavedSearch(self.saved_search_data) response = self.client.post( f"{reverse('barriers:new_saved_search')}" "?search=Test&priority=HIGH&status=2", data={"name": "New Name"}, ) assert response.status_code == HTTPStatus.FOUND mock_create.assert_called_with( name="New Name", filters={ "search": "Test", "priority": ["HIGH"], "status": ["2"], }, ) assert "saved_search_created" in self.client.session