diff --git a/edivorce/apps/core/templates/overview.html b/edivorce/apps/core/templates/overview.html index 0b218bab..e3f52b15 100644 --- a/edivorce/apps/core/templates/overview.html +++ b/edivorce/apps/core/templates/overview.html @@ -15,65 +15,65 @@ Qualifying Questions - + Step 1
What Are You Asking For?
- {% if step_status.which_orders == 'Started' %} {% endif %} + {% if step_status.which_orders == 'Started' %} + {% elif step_status.which_orders == 'Complete' %} {% endif %}
- + Step 2
Your information
- {% if step_status.your_information == 'Started' %} {% endif %} + {% if step_status.your_information == 'Started' %} + {% elif step_status.your_information == 'Complete' %} {% endif %}
- + Step 3
Your spouse
- {% if step_status.your_spouse == 'Started' %} {% endif %} + {% if step_status.your_spouse == 'Started' %} + {% elif step_status.your_spouse == 'Complete' %} {% endif %}
- + Step 4
Your marriage
- {% if step_status.your_marriage == 'Started' %} {% endif %} + {% if step_status.your_marriage == 'Started' %} + {% elif step_status.your_marriage == 'Complete' %} {% endif %}
- + Step 5
Your separation
- {% if step_status.your_separation == 'Started' %} {% endif %} + {% if step_status.your_separation == 'Started' %} + {% elif step_status.your_separation == 'Complete' %} {% endif %}
- - {% if 'Spousal support' in want_which_orders|load_json %} - + Step 6
Spousal support
- {% if step_status.spousal_support == 'Started' %} {% endif %} + {% if step_status.spousal_support == 'Started' %} + {% elif step_status.spousal_support == 'Complete' %} {% endif %}
- {% endif %} - - {% if 'Division of property and debts' in want_which_orders|load_json %} - + - Step {% step_order step="property" %}
Property and debt
- {% if step_status.property_and_debt == 'Started' %} {% endif %} + Step 7
Property and debt
+ {% if step_status.property_and_debt == 'Started' %} + {% elif step_status.property_and_debt == 'Complete' %} {% endif %}
- {% endif %} - - {% if 'Other orders' in want_which_orders|load_json %} - + - Step {% step_order step="other_orders" %}
Other orders
- {% if step_status.other_orders == 'Started' %} {% endif %} + Step 8
Other orders
+ {% if step_status.other_orders == 'Started' %} + {% elif step_status.other_orders == 'Complete' %} {% endif %}
- {% endif %} - - + - Step {% step_order step="other_questions" %}
Other questions
- {% if step_status.other_questions == 'Started' %} {% endif %} + Step 9
Other questions
+ {% if step_status.other_questions == 'Started' %} + {% elif step_status.other_questions == 'Complete' %} {% endif %}
- + - Step {% step_order step="location" %}
Filing location
- {% if step_status.filing_locations == 'Started' %} {% endif %} + Step 10
Filing locations
+ {% if step_status.filing_locations == 'Started' %} + {% elif step_status.filing_locations == 'Complete' %} {% endif %}
diff --git a/edivorce/apps/core/templates/partials/review_user_responses.html b/edivorce/apps/core/templates/partials/review_user_responses.html index d90b9d53..e7bf50a5 100644 --- a/edivorce/apps/core/templates/partials/review_user_responses.html +++ b/edivorce/apps/core/templates/partials/review_user_responses.html @@ -5,8 +5,9 @@ User response {% for question in questions %} + {{question.question}} - {{question.question.name}} + {{question.question__name}} {{question.value}} {% endfor %} diff --git a/edivorce/apps/core/templates/progress.html b/edivorce/apps/core/templates/progress.html index 4d876177..62710a79 100644 --- a/edivorce/apps/core/templates/progress.html +++ b/edivorce/apps/core/templates/progress.html @@ -8,65 +8,76 @@ Qualifying Questions - + Step 1
What Are You Asking For?
- {% if step_status.which_orders == 'Started' %} {% endif %} + {% if step_status.which_orders == 'Started' %} + {% elif step_status.which_orders == 'Complete' %} {% endif %}
- + Step 2
Your information
- {% if step_status.your_information == 'Started' %} {% endif %} + {% if step_status.your_information == 'Started' %} + {% elif step_status.your_information == 'Complete' %} {% endif %}
- + Step 3
Your spouse
- {% if step_status.your_spouse == 'Started' %} {% endif %} + {% if step_status.your_spouse == 'Started' %} + {% elif step_status.your_spouse == 'Complete' %} {% endif %}
- + Step 4
Your marriage
- {% if step_status.your_marriage == 'Started' %} {% endif %} + {% if step_status.your_marriage == 'Started' %} + {% elif step_status.your_marriage == 'Complete' %} {% endif %}
- + Step 5
Your separation
- {% if step_status.your_separation == 'Started' %} {% endif %} + {% if step_status.your_separation == 'Started' %} + {% elif step_status.your_separation == 'Complete' %} {% endif %}
+ {% if 'Spousal support' in want_which_orders|load_json %} Step 6
Spousal support
- {% if step_status.spousal_support == 'Started' %} {% endif %} + {% if step_status.spousal_support == 'Started' %} + {% elif step_status.spousal_support == 'Complete' %} {% endif %}
{% endif %} {% if 'Division of property and debts' in want_which_orders|load_json %} - + Step {% step_order step="property" %}
Property and debt
- {% if step_status.property_and_debt == 'Started' %} {% endif %} + {% if step_status.property_and_debt == 'Started' %} + {% elif step_status.property_and_debt == 'Complete' %} {% endif %}
{% endif %} {% if 'Other orders' in want_which_orders|load_json %} - + Step {% step_order step="other_orders" %}
Other orders
- {% if step_status.other_orders == 'Started' %} {% endif %} + {% if step_status.other_orders == 'Started' %} + {% elif step_status.other_orders == 'Complete' %} {% endif %}
{% endif %} - + Step {% step_order step="other_questions" %}
Other questions
- {% if step_status.other_questions == 'Started' %} {% endif %} + {% if step_status.other_questions == 'Started' %} + {% elif step_status.other_questions == 'Complete' %} {% endif %}
- + Step {% step_order step="location" %}
Filing location
- {% if step_status.filing_locations == 'Started' %} {% endif %} + {% if step_status.filing_locations == 'Started' %} + {% elif step_status.filing_locations == 'Complete' %} {% endif %}
diff --git a/edivorce/apps/core/tests.py b/edivorce/apps/core/tests.py index 7ce503c2..c6160214 100644 --- a/edivorce/apps/core/tests.py +++ b/edivorce/apps/core/tests.py @@ -1,3 +1,258 @@ from django.test import TestCase +from edivorce.apps.core.models import UserResponse, Question, BceidUser +from edivorce.apps.core.utils.user_response import is_complete +from edivorce.apps.core.utils.question_step_mapping import question_step_mapping + # Create your tests here. +class UserResponseTestCase(TestCase): + fixtures = ['Question.json'] + + def setUp(self): + BceidUser.objects.create(user_guid='1234') + Question.objects.create(key='test', name='this is test') + + def test_which_order(self): + step = 'which_orders' + questions = question_step_mapping[step] + user = BceidUser.objects.get(user_guid='1234') + + # No response should be False + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required question + create_response(user, 'want_which_orders', '["nothing"]') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + def test_your_info(self): + step = 'your_information' + questions = question_step_mapping[step] + user = BceidUser.objects.get(user_guid='1234') + + # No response should be False + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # Testing required questions + # Missing few required questions + create_response(user, 'name_you', 'John Doe') + create_response(user, 'last_name_before_married_you', 'Jackson') + create_response(user, 'birthday_you', '11/11/1111') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # Few required questions with one checking question with hidden question not shown + create_response(user, 'lived_in_bc_you', '11/11/1111') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with one checking question with hidden question not shown + create_response(user, 'last_name_born_you', 'Jackson') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with one checking question with hidden question missing + UserResponse.objects.filter(question_id='lived_in_bc_you').update(value="Moved to British Columbia on") + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with one checking question with hidden question + create_response(user, 'moved_to_bc_date_you', '12/12/1212') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with two checking question with one hidden and one shown + create_response(user, 'any_other_name_you', 'NO') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + # All required questions with two checking question with one hidden question missing + UserResponse.objects.filter(question_id='any_other_name_you').update(value="YES") + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with all checking question with all hidden questions + create_response(user, 'other_name_you', 'Smith') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + def test_your_spouse(self): + step = 'your_spouse' + questions = question_step_mapping[step] + user = BceidUser.objects.get(user_guid='1234') + + # No response should be False + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # Testing required questions + # Missing few required questions + create_response(user, 'name_spouse', 'John Doe') + create_response(user, 'last_name_before_married_spouse', 'Jackson') + create_response(user, 'birthday_spouse', '11/11/1111') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # Few required questions with one checking question with hidden question not shown + create_response(user, 'any_other_name_spouse', 'NO') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with one checking question with hidden question not shown + create_response(user, 'last_name_born_spouse', 'Jackson') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with one checking question with hidden question missing + UserResponse.objects.filter(question_id='any_other_name_spouse').update(value="YES") + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with one checking question with hidden question + create_response(user, 'lived_in_bc_spouse', '11/11/1111') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with two checking question with one hidden and one shown + create_response(user, 'other_name_spouse', 'Smith') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + # All required questions with two checking question with one hidden question missing + UserResponse.objects.filter(question_id='lived_in_bc_spouse').update(value="Moved to British Columbia on") + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required questions with all checking question with all hidden questions + create_response(user, 'moved_to_bc_date_spouse', '12/12/1212') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + def test_your_marriage(self): + pass + + def test_your_separation(self): + step = 'your_separation' + questions = question_step_mapping[step] + user = BceidUser.objects.get(user_guid='1234') + + # No response should be False + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required question + create_response(user, 'no_reconciliation_possible', 'I agree') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + def test_spousal_support(self): + step = 'spousal_support' + questions = question_step_mapping[step] + user = BceidUser.objects.get(user_guid='1234') + + # No response should be False + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # One required question + create_response(user, 'spouse_support_details', 'I will support you') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # Two required questions + create_response(user, 'spouse_support_act', 'Family Law') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + # Remove first added required response to test the second required question + UserResponse.objects.get(question_id='spouse_support_details').delete() + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + def test_property_and_debt(self): + step = 'property_and_debt' + questions = question_step_mapping[step] + user = BceidUser.objects.get(user_guid='1234') + + # No response should be False + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required question with no hidden shown + create_response(user, 'deal_with_property_debt', 'equal division') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + # All required question with hidden shown but no response + UserResponse.objects.filter(question_id='deal_with_property_debt').update(value="unequal division") + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required question with hidden shown and answered + create_response(user, 'how_to_divide_property_debt', 'Do not divide them') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + def test_other_orders(self): + step = 'other_orders' + questions = question_step_mapping[step] + user = BceidUser.objects.get(user_guid='1234') + + # No response should be False + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required question + create_response(user, 'other_orders_detail', 'I want more orders') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + def test_other_questions(self): + pass + + def test_filing_locations(self): + step = 'filing_locations' + questions = question_step_mapping[step] + user = BceidUser.objects.get(user_guid='1234') + + # No response should be False + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), False) + + # All required question + create_response(user, 'court_registry_for_filing', 'Vancouver') + + lst = UserResponse.objects.filter(question_id__in=questions).values('question_id', 'value') + self.assertEqual(is_complete(step, lst), True) + + +# Helper functions +def create_response(user, question, value): + UserResponse.objects.create(bceid_user=user, question=Question.objects.get(key=question), value=value) \ No newline at end of file diff --git a/edivorce/apps/core/utils/question_step_mapping.py b/edivorce/apps/core/utils/question_step_mapping.py index faf62953..a7ce2bdd 100644 --- a/edivorce/apps/core/utils/question_step_mapping.py +++ b/edivorce/apps/core/utils/question_step_mapping.py @@ -46,3 +46,35 @@ list_of_registries = ['Fort St. John', 'Dawson Creek', 'Prince Rupert', 'Terrace 'Williams Lake', 'Campbell River', 'Powell River', 'Courtenay', 'Port Alberni', 'Duncan', 'Nanaimo', 'Victoria', 'Golden', 'Kamloops', 'Salmon Arm', 'Vernon', 'Kelowna', 'Penticton', 'Nelson', 'Rossland', 'Cranbrook', 'Chilliwack', 'New Westminster', 'Vancouver', 'Fort Nelson', 'Revelstoke',] + + +complete_state_for_step = {'which_orders': {'required': ['want_which_orders']}, + 'your_information': {'required': ['name_you', 'last_name_born_you', + 'last_name_before_married_you', 'birthday_you'], + 'conditional': {'any_other_name_you': ['YES', 'other_name_you'], + 'lived_in_bc_you': ['Moved to British Columbia on', 'moved_to_bc_date_you']},}, + 'your_spouse': {'required': ['name_spouse', 'last_name_born_spouse', + 'last_name_before_married_spouse', 'birthday_spouse'], + 'conditional': {'any_other_name_spouse': ['YES', 'other_name_spouse'], + 'lived_in_bc_spouse': ['Moved to British Columbia on', 'moved_to_bc_date_spouse']},}, + 'your_marriage': {'required': ['']}, + 'your_separation': {'required': ['no_reconciliation_possible']}, + 'spousal_support': {'required': ['spouse_support_details', 'spouse_support_act']}, + 'property_and_debt': {'required': [], + 'conditional': {'deal_with_property_debt': ['unequal division', 'how_to_divide_property_debt']}}, + 'other_orders': {'required': ['other_orders_detail']}, + 'other_questions': {'required': ['address_to_send_official_document_street_you', + 'address_to_send_official_document_city_you', + 'address_to_send_official_document_prov_you', + 'address_to_send_official_document_country_you', + 'address_to_send_official_document_other_country_you', + 'address_to_send_official_document_postal_code_you', + 'address_to_send_official_document_street_spouse', + 'address_to_send_official_document_city_spouse', + 'address_to_send_official_document_prov_spouse', + 'address_to_send_official_document_country_spouse', + 'address_to_send_official_document_other_country_spouse', + 'address_to_send_official_document_postal_code_spouse', + 'divorce_take_effect_on_specific_date']}, + 'filing_locations': {'required': ['court_registry_for_filing']}, + } \ No newline at end of file diff --git a/edivorce/apps/core/utils/user_response.py b/edivorce/apps/core/utils/user_response.py index 1c4d25be..acca4872 100644 --- a/edivorce/apps/core/utils/user_response.py +++ b/edivorce/apps/core/utils/user_response.py @@ -1,5 +1,6 @@ from edivorce.apps.core.models import UserResponse, Question -from edivorce.apps.core.utils.question_step_mapping import question_step_mapping +from edivorce.apps.core.utils.question_step_mapping import question_step_mapping, complete_state_for_step +from copy import deepcopy def get_responses_from_db(bceid_user): @@ -15,7 +16,7 @@ def get_responses_from_db_grouped_by_steps(bceid_user): responses = UserResponse.objects.filter(bceid_user=bceid_user) responses_dict = {} for step, questions in question_step_mapping.items(): - responses_dict[step] = responses.filter(question_id__in=questions) + responses_dict[step] = responses.filter(question_id__in=questions).values('question_id', 'value', 'question__name') return responses_dict @@ -25,7 +26,11 @@ def get_step_status(responses_by_step): if not lst: status_dict[step] = "Not started" else: - status_dict[step] = "Started" + if step != 'prequalification': + if is_complete(step, lst): + status_dict[step] = "Complete" + else: + status_dict[step] = "Started" return status_dict @@ -65,3 +70,34 @@ def copy_session_to_db(request, bceid_user): # clear the response from the session request.session[q.key] = None + + +def is_complete(step, lst): + if not lst: + return False + required_dict = deepcopy(complete_state_for_step) + if step in required_dict: + required_list = required_dict[step]['required'] + conditional_list = required_dict[step]['conditional'] if 'conditional' in required_dict[step] else [] + + for question in lst: + q_id = question['question_id'] + + if q_id in required_list: + required_list.remove(q_id) + elif q_id in conditional_list: + value = question['value'] + if q_id in conditional_list and value == conditional_list[q_id][0]: + key_in_list = False + for key in lst: + if key['question_id'] == conditional_list[q_id][1]: + key_in_list = True + break + if key_in_list is False: + return False + conditional_list.pop(q_id, None) + else: + conditional_list.pop(q_id, None) + if not required_list and not conditional_list: + return True + return False diff --git a/edivorce/settings/local.py b/edivorce/settings/local.py index 103b78d8..1640df34 100644 --- a/edivorce/settings/local.py +++ b/edivorce/settings/local.py @@ -20,3 +20,6 @@ WEASYPRINT_CSS_LOOPBACK = 'http://10.200.10.1:8000' DEPLOYMENT_TYPE = 'localdev' REGISTER_URL = '#' +FIXTURE_DIRS = FIXTURE_DIRS = ( + os.path.join(PROJECT_ROOT, 'edivorce', 'fixtures'), + )