Browse Source

DIV-1179: fix next/prev step logic and add tests

pull/172/head
ariannedee 5 years ago
parent
commit
147ad0479f
2 changed files with 87 additions and 15 deletions
  1. +13
    -15
      edivorce/apps/core/templatetags/step_order.py
  2. +74
    -0
      edivorce/apps/core/tests/test_logic.py

+ 13
- 15
edivorce/apps/core/templatetags/step_order.py View File

@ -11,7 +11,7 @@ register = template.Library()
def _get_next_step(context, step, sub_step, direction):
want_which_orders = json.loads(context.get('want_which_orders', '[]'))
children_of_marriage = context.get('children_of_marriage', None)
children_of_marriage = context.get('derived', {}).get('has_children_of_marriage')
sub_step_name = _get_next_sub_step(step, sub_step, want_which_orders,
children_of_marriage=children_of_marriage,
direction=direction)
@ -48,25 +48,23 @@ def _get_next_sub_step(step, sub_step, want_which_orders, children_of_marriage,
return None
def _adjust_for_orders(next_item, want_which_orders, children_of_marriage=None, direction=None):
def _adjust_for_orders(next_item, want_which_orders, children_of_marriage, direction):
print(children_of_marriage)
tests = [
lambda next_item: next_item == 6 and not children_of_marriage,
lambda next_item: next_item == 7 and 'Spousal support' not in want_which_orders,
lambda next_item: next_item == 8 and 'Division of property and debts' not in want_which_orders,
lambda next_item: next_item == 9 and 'Other orders' not in want_which_orders
]
addend = 1
if direction != 'next':
addend = -1
tests.reverse()
next_item += addend
if next_item == 6 and 'YES' != children_of_marriage:
next_item += addend
if next_item == 7 and 'Spousal support' not in want_which_orders:
next_item += addend
if next_item == 8 and 'Division of property and debts' not in want_which_orders:
next_item += addend
if next_item == 9 and 'Other orders' not in want_which_orders:
next_item += addend
for test in tests:
if test(next_item):
next_item += addend
return next_item


+ 74
- 0
edivorce/apps/core/tests/test_logic.py View File

@ -3,7 +3,9 @@ import json
from django.test import TestCase
from edivorce.apps.core.models import BceidUser, UserResponse
from edivorce.apps.core.templatetags.step_order import next_step, prev_step
from edivorce.apps.core.utils import conditional_logic as logic
from edivorce.apps.core.utils.derived import get_derived_data
from edivorce.apps.core.utils.user_response import get_data_for_user
from edivorce.apps.core.models import Document
@ -116,3 +118,75 @@ class ViewLogic(TestCase):
self.assertEqual(Document.content_type_from_filename('redis_key_testfile_6_jpeg'), 'image/jpeg')
self.assertEqual(Document.content_type_from_filename('test_file7.HEIC'), 'application/unknown')
self.assertEqual(Document.content_type_from_filename('redis_key_testfile_7_svgg'), 'application/unknown')
class TemplateTagLogic(TestCase):
fixtures = ['Question.json']
def setUp(self):
self.user = BceidUser.objects.create(user_guid='1234')
def create_response(self, question, value):
response, _ = UserResponse.objects.get_or_create(bceid_user=self.user, question_id=question)
response.value = value
response.save()
@property
def context(self):
responses_dict = get_data_for_user(self.user)
derived = get_derived_data(responses_dict)
responses_dict['derived'] = derived
return responses_dict
def test_next(self):
self.assertEqual(next_step(self.context, 'orders'), 'claimant')
self.assertEqual(next_step(self.context, 'claimant'), 'respondent')
self.assertEqual(next_step(self.context, 'respondent'), 'marriage')
self.assertEqual(next_step(self.context, 'marriage'), 'separation')
self.assertEqual(next_step(self.context, 'separation'), 'other_questions')
self.assertEqual(next_step(self.context, 'other_questions'), 'location')
self.create_response('want_which_orders', '["Other orders"]')
self.assertEqual(next_step(self.context, 'separation'), 'other_orders')
self.create_response('want_which_orders', '["Spousal support"]')
self.assertEqual(next_step(self.context, 'separation'), 'support')
self.create_response('want_which_orders', '["Division of property and debts"]')
self.assertEqual(next_step(self.context, 'separation'), 'property')
self.create_response('want_which_orders', '[]')
self.create_response('children_of_marriage', 'YES')
self.create_response('has_children_under_19', 'YES')
self.assertEqual(next_step(self.context, 'separation'), 'children/your_children/')
self.assertEqual(next_step(self.context, 'children', sub_step='your_children'), '/question/children/income_expenses/')
self.assertEqual(next_step(self.context, 'children', sub_step='income_expenses'), '/question/children/facts/')
self.assertEqual(next_step(self.context, 'children', sub_step='facts'), '/question/children/payor_medical/')
self.assertEqual(next_step(self.context, 'children', sub_step='payor_medical'), '/question/children/what_for/')
self.assertEqual(next_step(self.context, 'children', sub_step='what_for'), '/question/other_questions')
def test_previous(self):
self.assertEqual(prev_step(self.context, 'location'), 'other_questions')
self.assertEqual(prev_step(self.context, 'other_questions'), 'separation')
self.assertEqual(prev_step(self.context, 'separation'), 'marriage')
self.assertEqual(prev_step(self.context, 'marriage'), 'respondent')
self.assertEqual(prev_step(self.context, 'respondent'), 'claimant')
self.assertEqual(prev_step(self.context, 'claimant'), 'orders')
self.create_response('want_which_orders', '["Other orders"]')
self.assertEqual(prev_step(self.context, 'other_questions'), 'other_orders')
self.create_response('want_which_orders', '["Spousal support"]')
self.assertEqual(prev_step(self.context, 'other_questions'), 'support')
self.create_response('want_which_orders', '["Division of property and debts"]')
self.assertEqual(prev_step(self.context, 'other_questions'), 'property')
self.create_response('want_which_orders', '[]')
self.create_response('children_of_marriage', 'YES')
self.create_response('has_children_under_19', 'YES')
self.assertEqual(prev_step(self.context, 'other_questions'), 'children/what_for/')
self.assertEqual(prev_step(self.context, 'children', sub_step='what_for'), '/question/children/payor_medical/')
self.assertEqual(prev_step(self.context, 'children', sub_step='payor_medical'), '/question/children/facts/')
self.assertEqual(prev_step(self.context, 'children', sub_step='facts'), '/question/children/income_expenses/')
self.assertEqual(prev_step(self.context, 'children', sub_step='income_expenses'), '/question/children/your_children/')
self.assertEqual(prev_step(self.context, 'children', sub_step='your_children'), '/question/separation')

Loading…
Cancel
Save