-
Notifications
You must be signed in to change notification settings - Fork 2
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
RAS-939 Survey Status Change #914
Changes from 5 commits
6ba2b91
d5efbaf
291b7cd
598fd85
edb2a09
7becf4b
6d7ff73
bd66a6b
48078ba
04ab279
3b80624
926e9ab
77bf6da
a510d11
4bbf054
ca013d7
dd76891
804edb9
d854df3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,9 +67,9 @@ <h3 id="COLLECTION_EXERCISES" class="ons-u-fs-m">Collection exercises</h3> | |
{% set status_class = 'ons-status--error' %} | ||
{% endif %} | ||
|
||
{% if ce.responseStatus in ['Not started', 'In progress'] and isReportingUnitPermission %} | ||
{% if ce.responseStatus in ['Not started', 'In progress','Completed', 'Completed by phone', 'No longer required'] and isReportingUnitPermission %} | ||
{% set survey_link = ' <a href="' + url_for("case_bp.get_response_statuses", ru_ref=ru.sampleUnitRef, survey=survey.shortName, period=ce.exerciseRef) + '">Change</a>' %} | ||
{% elif ce.responseStatus in ['Completed', 'Completed by phone', 'No longer required'] and isReportingUnitPermission %} | ||
{% elif isReportingUnitPermission %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure about this since I added the permission check in the next page as well so this might be worth just being an else and then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to just make this an if else and show the view to all users as that is how it is used across the rest of the site. It just made more sense to me |
||
{% set survey_link = ' <a href="' + url_for("case_bp.get_response_statuses", ru_ref=ru.sampleUnitRef, survey=survey.shortName, period=ce.exerciseRef) + '">View</a>' %} | ||
{% else %} | ||
{% set survey_link = '' %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
from unittest import TestCase | ||
|
||
import fakeredis | ||
import jwt | ||
import requests_mock | ||
|
||
from config import TestingConfig | ||
from response_operations_ui import create_app | ||
from tests.views.test_sign_in import url_sign_in_data | ||
|
||
short_name = "BLOCKS" | ||
survey_id = "cb0711c3-0ac8-41d3-ae0e-567e5ea1ef87" | ||
|
@@ -32,8 +34,9 @@ | |
url_get_case_by_case_group_id = f"{TestingConfig.CASE_URL}/cases/casegroupid/{case_group_id}" | ||
url_get_case_events = f"{TestingConfig.CASE_URL}/cases/{case_id}/events" | ||
get_respondent_by_id_url = f"{TestingConfig.PARTY_URL}/party-api/v1/respondents/id/{party_id}" | ||
project_root = os.path.dirname(os.path.dirname(__file__)) | ||
url_permission_url = f"{TestingConfig.UAA_SERVICE_URL}/Users/test-id" | ||
|
||
project_root = os.path.dirname(os.path.dirname(__file__)) | ||
|
||
with open(f"{project_root}/test_data/survey/single_survey.json") as fp: | ||
survey = json.load(fp) | ||
|
@@ -60,12 +63,19 @@ | |
with open(f"{project_root}/test_data/case/case_groups_list_no_longer_required.json") as fp: | ||
case_groups_no_longer_required = json.load(fp) | ||
|
||
user_permission_reporting_unit_edit_json = { | ||
"id": "5902656c-c41c-4b38-a294-0359e6aabe59", | ||
"groups": [{"value": "f385f89e-928f-4a0f-96a0-4c48d9007cc3", "display": "reportingunits.edit", "type": "DIRECT"}], | ||
} | ||
|
||
|
||
class TestChangeResponseStatus(TestCase): | ||
def setUp(self): | ||
self.app = create_app("TestingConfig") | ||
payload = {"user_id": "test-id", "aud": "response_operations"} | ||
self.client = self.app.test_client() | ||
self.setup_data() | ||
self.access_token = jwt.encode(payload, TestingConfig.UAA_PRIVATE_KEY, algorithm="RS256") | ||
self.app.config["SESSION_REDIS"] = fakeredis.FakeStrictRedis( | ||
host=self.app.config["REDIS_HOST"], port=self.app.config["FAKE_REDIS_PORT"], db=self.app.config["REDIS_DB"] | ||
) | ||
|
@@ -83,7 +93,10 @@ def setup_data(self): | |
|
||
@requests_mock.mock() | ||
def test_get_available_status(self, mock_request): | ||
mock_request.post(url_sign_in_data, json={"access_token": self.access_token}, status_code=201) | ||
mock_request.get(url_get_survey_by_short_name, json=survey) | ||
mock_request.get(url_permission_url, json=user_permission_reporting_unit_edit_json, status_code=200) | ||
self.client.post("/sign-in", follow_redirects=True, data={"username": "user", "password": "pass"}) | ||
mock_request.get(url_get_collection_exercises_by_survey, json=collection_exercise_list) | ||
mock_request.get(url_get_business_by_ru_ref, json=business_reporting_unit) | ||
mock_request.get(url_get_available_case_group_statuses, json=self.statuses) | ||
|
@@ -300,13 +313,17 @@ def test_respondent_name_not_in_metadata_for_completed_case_event(self, mock_req | |
|
||
@requests_mock.mock() | ||
def test_not_started_status_is_present_for_completed_by_phone(self, mock_request): | ||
mock_request.post(url_sign_in_data, json={"access_token": self.access_token}, status_code=201) | ||
mock_request.get(url_get_survey_by_short_name, json=survey) | ||
mock_request.get(url_permission_url, json=user_permission_reporting_unit_edit_json, status_code=200) | ||
self.client.post("/sign-in", follow_redirects=True, data={"username": "user", "password": "pass"}) | ||
mock_request.get(url_get_collection_exercises_by_survey, json=collection_exercise_list) | ||
mock_request.get(url_get_business_by_ru_ref, json=business_reporting_unit) | ||
mock_request.get(url_get_available_case_group_statuses, json=self.statuses) | ||
mock_request.get(url_get_case_groups_by_business_party_id, json=case_groups_completed_by_phone) | ||
mock_request.get(url_get_case_events, json=case_events) | ||
mock_request.get(url_get_case_by_case_group_id, json=[case]) | ||
mock_request.get(url_permission_url, json=user_permission_reporting_unit_edit_json, status_code=200) | ||
|
||
response = self.client.get(f"/case/{ru_ref}/response-status?survey={short_name}&period={period}") | ||
|
||
|
@@ -317,7 +334,10 @@ def test_not_started_status_is_present_for_completed_by_phone(self, mock_request | |
|
||
@requests_mock.mock() | ||
def test_not_started_status_is_present_for_no_longer_required(self, mock_request): | ||
mock_request.post(url_sign_in_data, json={"access_token": self.access_token}, status_code=201) | ||
mock_request.get(url_get_survey_by_short_name, json=survey) | ||
mock_request.get(url_permission_url, json=user_permission_reporting_unit_edit_json, status_code=200) | ||
self.client.post("/sign-in", follow_redirects=True, data={"username": "user", "password": "pass"}) | ||
mock_request.get(url_get_collection_exercises_by_survey, json=collection_exercise_list) | ||
mock_request.get(url_get_business_by_ru_ref, json=business_reporting_unit) | ||
mock_request.get(url_get_available_case_group_statuses, json=self.statuses) | ||
|
@@ -331,3 +351,23 @@ def test_not_started_status_is_present_for_no_longer_required(self, mock_request | |
self.assertEqual(response.status_code, 200) | ||
self.assertIn(b"No longer required", data) | ||
self.assertIn(b"Not started", data) | ||
|
||
@requests_mock.mock() | ||
def test_not_started_status_is_present_for_completed(self, mock_request): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We really should try to move away from this pattern or mass mocking at the highest level as it gets messy. The functionality should in the backend which then means we can unit test the link creation combinations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll leave this in but I have moved the link creation to the backend with additional tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can, but now you have done the work to test the dict being passed, you don't need to. The idea is you should only need to test the template logic |
||
mock_request.post(url_sign_in_data, json={"access_token": self.access_token}, status_code=201) | ||
mock_request.get(url_get_survey_by_short_name, json=survey) | ||
mock_request.get(url_permission_url, json=user_permission_reporting_unit_edit_json, status_code=200) | ||
self.client.post("/sign-in", follow_redirects=True, data={"username": "user", "password": "pass"}) | ||
mock_request.get(url_get_collection_exercises_by_survey, json=collection_exercise_list) | ||
mock_request.get(url_get_business_by_ru_ref, json=business_reporting_unit) | ||
mock_request.get(url_get_available_case_group_statuses, json=self.statuses) | ||
mock_request.get(url_get_case_groups_by_business_party_id, json=case_groups_no_longer_required) | ||
mock_request.get(url_get_case_events, json=case_events) | ||
mock_request.get(url_get_case_by_case_group_id, json=[case]) | ||
|
||
response = self.client.get(f"/case/{ru_ref}/response-status?survey={short_name}&period={period}") | ||
|
||
data = response.data | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn(b"Completed", data) | ||
self.assertIn(b"Not started", data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't going to work in conjunction with eQ, QuestionnaireState which holds the answers for eQ will still be present if Completed by phone or No longer required has been used and the respondent started the survey. eQ only deletes QuestionnaireState if it's completed by them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to take the opportunity to move to this to the backend, removing the logic from the template. It only needs the check and link generation, not everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue of EQ post submission state has also been raised when changing from COMPLETED to NOT STARTED. Depending on the time-bound post submission state, and the post-submission cookie state the respondent will not necessarily be presented with a new 'blank' questionnaire as the response_id may resolve to an existing state for a period of time after submission.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't changed the functionality of the Completed by Phone and No longer required rOps users were already able to change those to Not started just that before they were clicking a link that said
View
and were then presented with options to change the status - I've also moved the logic to the backend