Browse Source

Merge pull request #120 from bcgov/DIV-1170

DIV-1170: Fix question requirements
pull/172/head
Arianne 5 years ago
committed by GitHub
parent
commit
79f21b160f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 503 additions and 247 deletions
  1. +35
    -0
      edivorce/apps/core/management/commands/questions_to_csv.py
  2. +40
    -0
      edivorce/apps/core/management/commands/questions_to_json.py
  3. +40
    -17
      edivorce/apps/core/tests/test_logic.py
  4. +78
    -17
      edivorce/apps/core/tests/test_step_completeness.py
  5. +50
    -4
      edivorce/apps/core/utils/conditional_logic.py
  6. +1
    -2
      edivorce/apps/core/utils/derived.py
  7. +19
    -5
      edivorce/apps/core/utils/step_completeness.py
  8. +1
    -1
      edivorce/apps/core/utils/user_response.py
  9. +239
    -201
      edivorce/fixtures/Question.json

+ 35
- 0
edivorce/apps/core/management/commands/questions_to_csv.py View File

@ -0,0 +1,35 @@
import csv
import json
import os
from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Export Questions.json as Questions.csv'
def handle(self, *args, **options):
json_path = os.path.join(settings.PROJECT_ROOT, 'edivorce/fixtures/Question.json')
with open(json_path, 'r') as file:
all_lines = [line for line in file.readlines()]
questions = json.loads('\n'.join(all_lines))
print(questions)
csv_path = os.path.join(settings.PROJECT_ROOT.parent, 'Question.csv')
with open(csv_path, 'w') as file:
field_names = ['description', 'key', 'name', 'summary_order', 'required', 'conditional_target', 'reveal_response']
writer = csv.DictWriter(file, field_names)
writer.writeheader()
dicts = []
for question in questions:
dicts.append({
'description': question['fields']['description'],
'key': question['pk'],
'name': question['fields']['name'],
'summary_order': question['fields']['summary_order'],
'required': question['fields'].get('required', ''),
'conditional_target': question['fields'].get('conditional_target', ''),
'reveal_response': question['fields'].get('reveal_response', ''),
})
writer.writerows(dicts)

+ 40
- 0
edivorce/apps/core/management/commands/questions_to_json.py View File

@ -0,0 +1,40 @@
import csv
import json
import os
from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Export Questions.csv as Questions.json'
def handle(self, *args, **options):
csv_path = os.path.join(settings.PROJECT_ROOT.parent, 'Question.csv')
with open(csv_path, 'r') as file:
reader = csv.DictReader(file)
dicts = [line for line in reader]
json_path = os.path.join(settings.PROJECT_ROOT, 'edivorce/fixtures/Question.json')
with open(json_path, 'w') as file:
json_questions = []
for line in dicts:
question_dict = {
"fields": {
"name": line['name'],
"description": line['description'],
"summary_order": int(line['summary_order']),
"required": line['required'],
},
"model": "core.question",
"pk": line['key']
}
if line['conditional_target']:
question_dict["fields"]["conditional_target"] = line['conditional_target']
reveal_response = line['reveal_response']
if reveal_response.lower() == 'true':
reveal_response = reveal_response.capitalize()
question_dict["fields"]["reveal_response"] = reveal_response
json_questions.append(question_dict)
file.write(json.dumps(json_questions, indent=4))
file.write('\n')

+ 40
- 17
edivorce/apps/core/tests/test_logic.py View File

@ -3,7 +3,7 @@ import json
from django.test import TestCase
from edivorce.apps.core.models import BceidUser, UserResponse
from edivorce.apps.core.utils.conditional_logic import get_cleaned_response_value, get_num_children_living_with
from edivorce.apps.core.utils import conditional_logic as logic
from edivorce.apps.core.utils.user_response import get_data_for_user
from edivorce.apps.core.models import Document
@ -27,31 +27,54 @@ class ConditionalLogicTestCase(TestCase):
return get_data_for_user(self.user)
def test_get_cleaned_response_no_value(self):
self.assertIsNone(get_cleaned_response_value(None))
self.assertIsNone(get_cleaned_response_value(''))
self.assertIsNone(get_cleaned_response_value(' '))
self.assertIsNone(get_cleaned_response_value('[]'))
self.assertIsNone(get_cleaned_response_value('[[""," "]]'))
self.assertIsNone(get_cleaned_response_value('[["also known as",""]]'))
self.assertIsNone(get_cleaned_response_value('[["also known as",""],["also known as",""]]'))
self.assertIsNone(logic.get_cleaned_response_value(None))
self.assertIsNone(logic.get_cleaned_response_value(''))
self.assertIsNone(logic.get_cleaned_response_value(' '))
self.assertIsNone(logic.get_cleaned_response_value('[]'))
self.assertIsNone(logic.get_cleaned_response_value('[[""," "]]'))
self.assertIsNone(logic.get_cleaned_response_value('[["also known as",""]]'))
self.assertIsNone(logic.get_cleaned_response_value('[["also known as",""],["also known as",""]]'))
def test_get_cleaned_response_with_value(self):
self.assertIsNotNone(get_cleaned_response_value('0'))
self.assertIsNotNone(get_cleaned_response_value('["hi"]'))
self.assertIsNotNone(get_cleaned_response_value('[["also known as","a"]]'))
self.assertIsNotNone(logic.get_cleaned_response_value('0'))
self.assertIsNotNone(logic.get_cleaned_response_value('["hi"]'))
self.assertIsNotNone(logic.get_cleaned_response_value('[["also known as","a"]]'))
def test_num_children(self):
self.assertEqual(get_num_children_living_with(self.questions_dict, 'Lives with you'), '0')
self.assertEqual(get_num_children_living_with(self.questions_dict, 'Lives with spouse'), '0')
self.assertEqual(get_num_children_living_with(self.questions_dict, 'Lives with both'), '0')
# No children
self.assertEqual(logic.get_num_children_living_with(self.questions_dict, 'Lives with you'), '0')
self.assertEqual(logic.get_num_children_living_with(self.questions_dict, 'Lives with spouse'), '0')
self.assertEqual(logic.get_num_children_living_with(self.questions_dict, 'Lives with both'), '0')
children = [self.child_live_with_you, self.child_live_with_spouse, self.child_live_with_spouse,
self.child_live_with_both, self.child_live_with_both, self.child_live_with_both]
self.create_response('claimant_children', json.dumps(children))
self.assertEqual(get_num_children_living_with(self.questions_dict, 'Lives with you'), '1')
self.assertEqual(get_num_children_living_with(self.questions_dict, 'Lives with spouse'), '2')
self.assertEqual(get_num_children_living_with(self.questions_dict, 'Lives with both'), '3')
# Has children, but marked no children of marriage in prequal
self.assertEqual(logic.get_num_children_living_with(self.questions_dict, 'Lives with you'), '0')
self.assertEqual(logic.get_num_children_living_with(self.questions_dict, 'Lives with spouse'), '0')
self.assertEqual(logic.get_num_children_living_with(self.questions_dict, 'Lives with both'), '0')
# Has children, and marked YES to children of marriage in prequal
self.create_response('children_of_marriage', 'YES')
self.assertEqual(logic.get_num_children_living_with(self.questions_dict, 'Lives with you'), '1')
self.assertEqual(logic.get_num_children_living_with(self.questions_dict, 'Lives with spouse'), '2')
self.assertEqual(logic.get_num_children_living_with(self.questions_dict, 'Lives with both'), '3')
def test_shared_custody(self):
self.create_response('children_of_marriage', 'NO')
self.assertFalse(logic.determine_shared_custody(self.questions_dict))
children = [self.child_live_with_both, self.child_live_with_you]
self.create_response('claimant_children', json.dumps(children))
self.assertFalse(logic.determine_shared_custody(self.questions_dict))
self.create_response('children_of_marriage', 'YES')
self.assertTrue(logic.determine_shared_custody(self.questions_dict))
children = [self.child_live_with_spouse, self.child_live_with_you]
self.create_response('claimant_children', json.dumps(children))
self.assertFalse(logic.determine_shared_custody(self.questions_dict))
class ViewLogic(TestCase):


+ 78
- 17
edivorce/apps/core/tests/test_step_completeness.py View File

@ -3,7 +3,7 @@ import json
from django.test import TestCase
from edivorce.apps.core.models import UserResponse, Question, BceidUser
from edivorce.apps.core.utils.derived import get_derived_data
from edivorce.apps.core.utils.step_completeness import get_error_dict, get_step_completeness, is_complete
from edivorce.apps.core.utils.step_completeness import Status, get_error_dict, get_step_completeness, is_complete
from edivorce.apps.core.utils.user_response import get_data_for_user, get_step_responses
@ -19,6 +19,12 @@ class StepCompletenessTestCase(TestCase):
responses_dict_by_step = get_step_responses(responses_dict)
return is_complete(responses_dict_by_step[step])
def check_step_status(self, step):
responses_dict = get_data_for_user(self.user)
responses_dict_by_step = get_step_responses(responses_dict)
step_completeness = get_step_completeness(responses_dict_by_step)
return step_completeness[step]
def create_response(self, question, value):
UserResponse.objects.create(bceid_user=self.user, question=Question.objects.get(key=question), value=value)
@ -27,6 +33,7 @@ class StepCompletenessTestCase(TestCase):
# No response should be False
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# Testing required questions
# Missing few required questions
@ -40,10 +47,12 @@ class StepCompletenessTestCase(TestCase):
self.create_response('marriage_certificate_in_english', 'YES')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.STARTED)
# All required questions with one checking question with hidden question not shown
self.create_response('divorce_reason', 'live separate')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
# Reconciliation
UserResponse.objects.filter(question_id='try_reconcile_after_separated').update(value="YES")
@ -86,10 +95,12 @@ class StepCompletenessTestCase(TestCase):
# No response should be False
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# All required question
self.create_response('want_which_orders', '["nothing"]')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
# Put empty response
UserResponse.objects.filter(question_id='want_which_orders').update(value="[]")
@ -100,6 +111,7 @@ class StepCompletenessTestCase(TestCase):
# No response should be False
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# Testing required questions
# Missing few required questions
@ -107,6 +119,7 @@ class StepCompletenessTestCase(TestCase):
self.create_response('last_name_before_married_you', 'Jackson')
self.create_response('birthday_you', '11/11/1111')
self.create_response('occupation_you', 'Plumber')
self.assertEqual(self.check_step_status(step), Status.STARTED)
self.assertEqual(self.check_completeness(step), False)
@ -128,6 +141,7 @@ class StepCompletenessTestCase(TestCase):
# All required questions with two checking question with one hidden and one shown
self.create_response('any_other_name_you', 'NO')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
# All required questions with two checking question with one hidden question missing
UserResponse.objects.filter(question_id='any_other_name_you').update(value="YES")
@ -146,6 +160,7 @@ class StepCompletenessTestCase(TestCase):
# No response should be False
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# Testing required questions
# Missing few required questions
@ -155,6 +170,7 @@ class StepCompletenessTestCase(TestCase):
self.create_response('occupation_spouse', 'Electrician')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.STARTED)
# Few required questions with one checking question with hidden question not shown
self.create_response('any_other_name_spouse', 'NO')
@ -175,6 +191,7 @@ class StepCompletenessTestCase(TestCase):
# All required questions with two checking question with one hidden and one shown
self.create_response('other_name_spouse', '[["also known as","Smith"]]')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
# 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 B.C. on")
@ -197,10 +214,12 @@ class StepCompletenessTestCase(TestCase):
# No response should be False
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# Some required questions
self.create_response('when_were_you_live_married_like', '12/12/2007')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.STARTED)
self.create_response('when_were_you_married', '12/12/2008')
self.assertEqual(self.check_completeness(step), False)
@ -228,15 +247,23 @@ class StepCompletenessTestCase(TestCase):
# All required questions
self.create_response('where_were_you_married_other_country', 'Peru')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
def test_your_separation(self):
step = 'your_separation'
# No response should be False
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# All required question
# One required question
self.create_response('no_reconciliation_possible', 'I agree')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.STARTED)
# All required question
self.create_response('no_collusion', 'I agree')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
# Put empty response
UserResponse.objects.filter(question_id='no_reconciliation_possible').update(value="")
@ -245,61 +272,79 @@ class StepCompletenessTestCase(TestCase):
def test_spousal_support(self):
step = 'spousal_support'
# Step not required if spousal support not wanted
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.HIDDEN)
# No response should be False
self.create_response('want_which_orders', '["Spousal support"]')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# One required question
self.create_response('spouse_support_details', 'I will support you')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.STARTED)
# Two required questions
self.create_response('spouse_support_act', 'Family Law')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
# Remove first added required response to test the second required question
UserResponse.objects.get(question_id='spouse_support_details').delete()
self.assertEqual(self.check_completeness(step), False)
# Put empty response
# Empty response doesn't count as answered
UserResponse.objects.filter(question_id='spouse_support_details').update(value="")
self.assertEqual(self.check_completeness(step), False)
def test_property_and_debt(self):
step = 'property_and_debt'
# Step not required if property and debt orders not wanted
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.HIDDEN)
# No response should be False
self.create_response('want_which_orders', '["Division of property and debts"]')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# All required question with no hidden shown
self.create_response('deal_with_property_debt', 'Equal division')
self.assertEqual(self.check_completeness(step), True)
# All required question with hidden shown but no response
UserResponse.objects.filter(question_id='deal_with_property_debt').update(value="Unequal division")
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.STARTED)
# Only one required question with hidden shown and answered
self.create_response('how_to_divide_property_debt', 'Do not divide them')
self.assertEqual(self.check_completeness(step), True)
# All required question with optional fields
self.create_response('other_property_claims', 'Want these property claims')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
def test_other_orders(self):
step = 'other_orders'
# Step not required if other orders not wanted
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.HIDDEN)
# No response should be False
self.create_response('want_which_orders', '["Other orders"]')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# All required question
self.create_response('name_change_you', 'NO')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.STARTED)
self.create_response('name_change_spouse', 'NO')
self.create_response('other_orders_detail', 'I want more orders')
@ -316,16 +361,19 @@ class StepCompletenessTestCase(TestCase):
# Put empty response
UserResponse.objects.filter(question_id='other_orders_detail').update(value="")
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
def test_other_questions(self):
step = 'other_questions'
# No response should be False
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# Some required question
self.create_response('address_to_send_official_document_street_you', '123 Cambie st')
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.STARTED)
self.create_response('address_to_send_official_document_city_you', 'Vancouver')
self.assertEqual(self.check_completeness(step), False)
@ -384,6 +432,7 @@ class StepCompletenessTestCase(TestCase):
# All required questions
self.create_response('address_to_send_official_document_other_country_spouse', 'Mexico')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
# Set Specific date on to empty
UserResponse.objects.filter(question_id='divorce_take_effect_on_specific_date').update(value="")
@ -394,10 +443,12 @@ class StepCompletenessTestCase(TestCase):
# No response should be False
self.assertEqual(self.check_completeness(step), False)
self.assertEqual(self.check_step_status(step), Status.NOT_STARTED)
# All required question
self.create_response('court_registry_for_filing', 'Vancouver')
self.assertEqual(self.check_completeness(step), True)
self.assertEqual(self.check_step_status(step), Status.COMPLETED)
# Put empty response
UserResponse.objects.filter(question_id='court_registry_for_filing').update(value="")
@ -412,8 +463,9 @@ class ChildrenStepCompletenessTestCase(TestCase):
self.child_live_with_you = {"child_name": "Child with you", "child_birth_date": "Dec 30, 2018", "child_live_with": "Lives with you", "child_relationship_to_you": "Natural child", "child_relationship_to_spouse": "Natural child", "child_live_with_other_details": ""}
self.child_live_with_spouse = {"child_name": "Child with spouse", "child_birth_date": "Jan 4, 2009", "child_live_with": "Lives with spouse", "child_relationship_to_you": "Adopted child", "child_relationship_to_spouse": "Adopted child", "child_live_with_other_details": ""}
self.child_live_with_both = {"child_name": "Child with both", "child_birth_date": "Jan 4, 2009", "child_live_with": "Lives with both", "child_relationship_to_you": "Adopted child", "child_relationship_to_spouse": "Adopted child", "child_live_with_other_details": ""}
self.create_response('children_of_marriage', 'YES')
def get_children_step_status(self, substep):
def get_children_step_status(self, substep=None):
responses_dict = get_data_for_user(self.user)
responses_dict_by_step = get_step_responses(responses_dict)
step_completeness = get_step_completeness(responses_dict_by_step)
@ -424,7 +476,7 @@ class ChildrenStepCompletenessTestCase(TestCase):
return step_completeness[key]
def is_step_complete(self, substep):
return self.get_children_step_status(substep) == 'Completed'
return self.get_children_step_status(substep) == Status.COMPLETED
def create_response(self, question, value):
response, _ = UserResponse.objects.get_or_create(bceid_user=self.user, question_id=question)
@ -443,12 +495,21 @@ class ChildrenStepCompletenessTestCase(TestCase):
derived_data = get_derived_data(responses_dict)
return derived_data[derived_key]
def test_no_children(self):
self.create_response('children_of_marriage', 'NO')
self.assertEqual(self.get_children_step_status(), 'Hidden')
self.assertEqual(self.get_children_step_status('your_children'), 'Hidden')
self.assertEqual(self.get_children_step_status('income_expenses'), 'Hidden')
self.assertEqual(self.get_children_step_status('facts'), 'Hidden')
self.assertEqual(self.get_children_step_status('payor_medical'), 'Hidden')
self.assertEqual(self.get_children_step_status('what_for'), 'Hidden')
def test_children_details(self):
substep = 'your_children'
# No response status is Not Started
self.assertFalse(self.is_step_complete(substep))
self.assertEqual(self.get_children_step_status(substep), 'Not started')
self.assertEqual(self.get_children_step_status(substep), Status.NOT_STARTED)
# Empty list doesn't count as answered
self.create_response('claimant_children', '[]')
@ -456,7 +517,7 @@ class ChildrenStepCompletenessTestCase(TestCase):
# Future question answered means status is Skipped
self.create_response('have_separation_agreement', 'YES')
self.assertEqual(self.get_children_step_status(substep), 'Skipped')
self.assertEqual(self.get_children_step_status(substep), Status.SKIPPED)
# Has valid value
children = [self.child_live_with_you]
@ -468,12 +529,12 @@ class ChildrenStepCompletenessTestCase(TestCase):
children = [self.child_live_with_you, self.child_live_with_spouse]
self.create_response('claimant_children', json.dumps(children))
self.assertEqual(self.get_children_step_status(substep), 'Not started')
self.assertEqual(self.get_children_step_status(substep), Status.NOT_STARTED)
self.assertFalse(self.is_step_complete(substep))
# All basic required fields
self.create_response('how_will_calculate_income', 'entered agreement')
self.assertEqual(self.get_children_step_status(substep), 'Started')
self.assertEqual(self.get_children_step_status(substep), Status.STARTED)
self.create_response('annual_gross_income', '100')
self.create_response('spouse_annual_gross_income', '100')
self.create_response('special_extraordinary_expenses', 'NO')
@ -500,7 +561,7 @@ class ChildrenStepCompletenessTestCase(TestCase):
children = [self.child_live_with_you]
self.create_response('claimant_children', json.dumps(children))
self.create_response('annual_gross_income', '0')
self.assertEqual(self.get_children_step_status(substep), 'Not started')
self.assertEqual(self.get_children_step_status(substep), Status.NOT_STARTED)
self.assertFalse(self.is_step_complete(substep))
# All basic required fields if there is only sole custody of children and payor makes less than $150,000
@ -645,7 +706,7 @@ class ChildrenStepCompletenessTestCase(TestCase):
substep = 'payor_medical'
self.assertFalse(self.is_step_complete(substep))
self.assertEqual(self.get_children_step_status(substep), 'Not started')
self.assertEqual(self.get_children_step_status(substep), Status.NOT_STARTED)
# All basic required fields
self.create_response('medical_coverage_available', 'NO')
@ -665,7 +726,7 @@ class ChildrenStepCompletenessTestCase(TestCase):
substep = 'what_for'
self.assertFalse(self.is_step_complete(substep))
self.assertEqual(self.get_children_step_status(substep), 'Not started')
self.assertEqual(self.get_children_step_status(substep), Status.NOT_STARTED)
# All basic required fields
self.create_response('child_support_in_order', 'MATCH')


+ 50
- 4
edivorce/apps/core/utils/conditional_logic.py View File

@ -1,7 +1,24 @@
import functools
import json
import re
def if_no_children(return_val):
def decorator_no_children(func):
@functools.wraps(func)
def inner(questions_dict, *args, **kwargs):
if questions_dict.get('children_of_marriage', '') != 'YES':
return return_val
return func(questions_dict, *args, **kwargs)
return inner
return decorator_no_children
def determine_has_children_of_marriage(questions_dict):
return questions_dict.get('children_of_marriage', '') == 'YES'
@if_no_children(return_val=[])
def get_children(questions_dict):
children_json = questions_dict.get('claimant_children', '[]')
if isinstance(children_json, dict):
@ -9,25 +26,32 @@ def get_children(questions_dict):
return json.loads(children_json)
@if_no_children(return_val='0')
def get_num_children_living_with(questions_dict, living_arrangement):
assert living_arrangement in ['Lives with you', 'Lives with spouse', 'Lives with both']
children = get_children(questions_dict)
return str(len([child for child in children if child['child_live_with'] == living_arrangement]))
@if_no_children(return_val=False)
def determine_sole_custody(questions_dict):
""" Return True if all children live with one parent """
child_list = get_children(questions_dict)
return (all([child['child_live_with'] == 'Lives with you' for child in child_list]) or
all([child['child_live_with'] == 'Lives with spouse' for child in child_list]))
@if_no_children(return_val=False)
def determine_shared_custody(questions_dict):
""" Return True if any children live with both parents """
child_list = get_children(questions_dict)
return any([child['child_live_with'] == 'Lives with both'
for child in child_list])
@if_no_children(return_val=False)
def determine_split_custody(questions_dict):
""" Return True if at least one child lives with one parent and at least one lives with the other (or both) """
child_list = get_children(questions_dict)
with_you = 0
with_spouse = 0
@ -43,14 +67,15 @@ def determine_split_custody(questions_dict):
with_spouse > 0 and (with_you + with_both > 0))
@if_no_children(return_val=False)
def determine_child_over_19_supported(questions_dict):
has_children_of_marriage = questions_dict.get('children_of_marriage', '') == 'YES'
has_children_over_19 = questions_dict.get('has_children_over_19', '') == 'YES'
support = json.loads(questions_dict.get('children_financial_support', '[]'))
supporting_children = len(support) > 0 and 'NO' not in support
return has_children_of_marriage and has_children_over_19 and supporting_children
return has_children_over_19 and supporting_children
@if_no_children(return_val=False)
def determine_missing_undue_hardship_reasons(questions_dict):
claiming_undue_hardship = questions_dict.get('claiming_undue_hardship', '') == 'YES'
if claiming_undue_hardship:
@ -73,6 +98,7 @@ def determine_missing_undue_hardship_reasons(questions_dict):
return False
@if_no_children(return_val='')
def determine_child_support_payor(questions_dict):
payor = questions_dict.get('child_support_payor', '')
if payor == 'Myself (Claimant 1)':
@ -84,6 +110,7 @@ def determine_child_support_payor(questions_dict):
return ''
@if_no_children(return_val=False)
def determine_show_fact_sheet_f_you(questions_dict):
"""
If claimant 1 (you) is a payor and makes over $150,000/year, show fact sheet F for claimant 1
@ -96,6 +123,7 @@ def determine_show_fact_sheet_f_you(questions_dict):
return (payor == 'Claimant 1' or payor == 'both Claimant 1 and Claimant 2') and annual > 150000
@if_no_children(return_val=False)
def determine_show_fact_sheet_f_spouse(questions_dict):
"""
If claimant 2 (spouse) is a payor and makes over $150,000/year, show fact sheet F for claimant 2
@ -110,11 +138,13 @@ def determine_show_fact_sheet_f_spouse(questions_dict):
return (payor == 'Claimant 2' or payor == 'both Claimant 1 and Claimant 2') and annual > 150000
@if_no_children(return_val=False)
def determine_child_support_act_requirement(questions_dict):
orders_wanted = json.loads(questions_dict.get('want_which_orders', '[]'))
return 'Child support' in orders_wanted
@if_no_children(return_val=False)
def determine_missing_extraordinary_expenses(questions_dict):
special_expenses_keys = ["child_care_expenses",
"children_healthcare_premiums",
@ -137,11 +167,27 @@ def determine_missing_extraordinary_expenses(questions_dict):
return False
@if_no_children(return_val=False)
def determine_show_children_live_with_others(questions_dict):
has_children_of_marriage = questions_dict.get('children_of_marriage', '') == 'YES'
has_children_under_19 = questions_dict.get('has_children_under_19', '') == 'YES'
child_over_19_supported = determine_child_over_19_supported(questions_dict)
return has_children_of_marriage and (has_children_under_19 or child_over_19_supported)
return has_children_under_19 or child_over_19_supported
def orders_wanted(questions_dict):
return json.loads(questions_dict.get('want_which_orders', '[]'))
def determine_spousal_support_orders_wanted(questions_dict):
return 'Spousal support' in orders_wanted(questions_dict)
def determine_property_debt_orders_wanted(questions_dict):
return 'Division of property and debts' in orders_wanted(questions_dict)
def determine_other_orders_wanted(questions_dict):
return 'Other orders' in orders_wanted(questions_dict)
def get_cleaned_response_value(response):


+ 1
- 2
edivorce/apps/core/utils/derived.py View File

@ -106,8 +106,7 @@ def get_derived_data(responses):
def orders_wanted(responses, derived):
""" Return a list of orders the user has indicated """
return json.loads(responses.get('want_which_orders', '[]'))
return conditional_logic.orders_wanted(responses)
def children(responses, derived):


+ 19
- 5
edivorce/apps/core/utils/step_completeness.py View File

@ -5,6 +5,14 @@ from edivorce.apps.core.utils.question_step_mapping import children_substep_ques
from edivorce.apps.core.utils.conditional_logic import get_cleaned_response_value
class Status:
STARTED = "Started"
COMPLETED = "Completed"
SKIPPED = "Skipped"
NOT_STARTED = "Not started"
HIDDEN = "Hidden"
def evaluate_numeric_condition(target, reveal_response):
"""
Tests whether the reveal_response contains a numeric condition. If so, it will
@ -56,19 +64,25 @@ def get_step_completeness(questions_by_step):
return status_dict
def has_required_questions(question_dicts):
return any([question for question in question_dicts if question['question__required'] != ''])
def _get_step_status(question_dicts, has_responses):
if not step_started(question_dicts):
if not has_responses:
status = "Not started"
if not has_required_questions(question_dicts):
status = Status.HIDDEN
elif not has_responses:
status = Status.NOT_STARTED
else:
status = "Skipped"
status = Status.SKIPPED
else:
has_responses = True
complete = is_complete(question_dicts)
if complete:
status = "Completed"
status = Status.COMPLETED
else:
status = "Started"
status = Status.STARTED
return status, has_responses


+ 1
- 1
edivorce/apps/core/utils/user_response.py View File

@ -73,7 +73,7 @@ def _condition_met(target_response, reveal_response):
if reveal_response.startswith('!'):
if target_response == "" or target_response.lower() == reveal_response[1:].lower():
return False
elif str(target_response) != reveal_response:
elif str(target_response).lower() != reveal_response.lower():
return False
elif numeric_condition_met is False:
return False


+ 239
- 201
edivorce/fixtures/Question.json
File diff suppressed because it is too large
View File


Loading…
Cancel
Save