Browse Source

Merge branch 'master' into DIV-1019

pull/172/head
ariannedee 5 years ago
parent
commit
b7e16e0149
12 changed files with 160 additions and 45 deletions
  1. +5
    -1
      edivorce/apps/core/models.py
  2. +11
    -4
      edivorce/apps/core/serializer.py
  3. +4
    -4
      edivorce/apps/core/templates/overview.html
  4. +1
    -1
      edivorce/apps/core/templates/partials/progress.html
  5. +3
    -3
      edivorce/apps/core/templates/question/12_review.html
  6. +5
    -8
      edivorce/apps/core/templatetags/step_order.py
  7. +62
    -8
      edivorce/apps/core/tests/test_api.py
  8. +23
    -0
      edivorce/apps/core/tests/test_logic.py
  9. +31
    -6
      edivorce/apps/core/tests/test_step_completeness.py
  10. +11
    -5
      edivorce/apps/core/utils/conditional_logic.py
  11. +1
    -3
      edivorce/apps/core/utils/derived.py
  12. +3
    -2
      vue/src/components/Uploader/Uploader.vue

+ 5
- 1
edivorce/apps/core/models.py View File

@ -213,7 +213,11 @@ class Document(models.Model):
content_type = content_types.get(extension)
if not content_type:
return "application/unknown"
return content_type
return content_type
@property
def is_pdf(self):
return self.filename.split('.')[-1].lower() == 'pdf'
class DontLog:


+ 11
- 4
edivorce/apps/core/serializer.py View File

@ -42,13 +42,20 @@ class CreateDocumentSerializer(serializers.ModelSerializer):
filename = validated_data['file'].name
size = validated_data['file'].size
user = self.context['request'].user
order = Document.objects.filter(bceid_user=user, doc_type=validated_data['doc_type'], party_code=validated_data['party_code']).count() + 1
response = Document(bceid_user=user, filename=filename, size=size, sort_order=order, **validated_data)
existing_docs = Document.objects.filter(bceid_user=user, doc_type=validated_data['doc_type'], party_code=validated_data['party_code'])
for other_doc in existing_docs:
if other_doc.is_pdf:
raise ValidationError("PDF documents cannot be combined with images. Only a single PDF or multiple images can be uploaded into one form.")
sort_order = existing_docs.count() + 1
document = Document(bceid_user=user, filename=filename, size=size, sort_order=sort_order, **validated_data)
if document.is_pdf and existing_docs.count() > 0:
raise ValidationError("Only one PDF is allowed per form, and PDF documents cannot be combined with images.")
try:
response.save()
document.save()
except IntegrityError:
raise ValidationError("This file appears to have already been uploaded for this document. Duplicate filename: " + filename)
return response
return document
class DocumentMetadataSerializer(serializers.ModelSerializer):


+ 4
- 4
edivorce/apps/core/templates/overview.html View File

@ -41,7 +41,7 @@
<span class="progress-content"><small>Step 5</small><br />Your separation</span>
{% include "partials/progress_icon.html" with step_status_string=step_status.your_separation with_status=True %}
</a>
{% if children_of_marriage == 'YES' or derived.has_children_of_marriage %}
{% if derived.has_children_of_marriage %}
<a href="{% url 'question_steps' 'children' 'your_children'%}" class="progress-question {% if step_status.your_children == 'Completed' %} complete {% endif %}">
<span class="progress-icon"><i class="fa fa-users" aria-hidden="true"></i></span>
<span class="progress-content"><small>Step {% step_order step="children" %}</small><br />Your children</span>
@ -49,7 +49,7 @@
</a>
{% endif %}
{% if 'Spousal support' in which_orders.0.value|load_json %}
{% if derived.wants_spousal_support %}
<a href="{% url 'question_steps' 'support' %}" class="progress-question {% if step_status.spousal_support == 'Completed' %} complete {% endif %}">
<span class="progress-icon"><i class="fa fa-life-ring" aria-hidden="true"></i></span>
<span class="progress-content"><small>Step {% step_order step="support" %}</small><br />Spousal support</span>
@ -57,7 +57,7 @@
</a>
{% endif %}
{% if 'Division of property and debts' in which_orders.0.value|load_json %}
{% if derived.wants_property_division %}
<a href="{% url 'question_steps' 'property' %}" class="progress-question {% if step_status.property_and_debt == 'Completed' %} complete {% endif %}">
<span class="progress-icon"><i class="fa fa-home" aria-hidden="true"></i></span>
<span class="progress-content"><small>Step {% step_order step="property" %}</small><br />Property and debt</span>
@ -65,7 +65,7 @@
</a>
{% endif %}
{% if 'Other orders' in which_orders.0.value|load_json %}
{% if derived.wants_other_orders %}
<a href="{% url 'question_steps' 'other_orders' %}" class="progress-question {% if step_status.other_orders == 'Completed' %} complete {% endif %}">
<span class="progress-icon"><i class="fa fa-gavel" aria-hidden="true"></i></span>
<span class="progress-content"><small>Step {% step_order step="other_orders" %}</small><br />Other orders</span>


+ 1
- 1
edivorce/apps/core/templates/partials/progress.html View File

@ -34,7 +34,7 @@
{% include "partials/progress_icon.html" with step_status_string=step_status.your_separation%}
</a>
{% if children_of_marriage == 'YES' or derived.has_children_of_marriage %}
{% if derived.has_children_of_marriage %}
<a href="{% url 'question_steps' 'children' 'your_children' %}" class="progress-question collapse-trigger {% if step_status.your_children == 'Completed' %} complete {% endif %} {% if active_page == 'children' %} active {% endif %}"
data-toggle="collapse" aria-expanded="false" data-target="#children_nav" aria-controls="children_nav">
<span class="progress-icon"><i class="fa fa-users" aria-hidden="true"></i></span>


+ 3
- 3
edivorce/apps/core/templates/question/12_review.html View File

@ -129,7 +129,7 @@
</div>
{% endif %}
{% if 'Spousal support' in which_orders.0.value|load_json %}
{% if derived.wants_spousal_support %}
<div class="question-well step-review {% if step_status.spousal_support != 'Completed' %}error{% endif %}">
<div class="collapse-trigger" data-toggle="collapse" aria-expanded="true" data-target="#review_step_7" aria-controls="collapse_changed_name">
<div>
@ -147,7 +147,7 @@
</div>
{% endif %}
{% if 'Division of property and debts' in which_orders.0.value|load_json %}
{% if derived.wants_property_division %}
<div class="question-well step-review {% if step_status.property_and_debt != 'Completed' %}error{% endif %}">
<div class="collapse-trigger" data-toggle="collapse" aria-expanded="true" data-target="#review_step_8" aria-controls="collapse_changed_name">
<div>
@ -165,7 +165,7 @@
</div>
{% endif %}
{% if 'Other orders' in which_orders.0.value|load_json %}
{% if derived.wants_other_orders %}
<div class="question-well step-review {% if step_status.other_orders != 'Completed' %}error{% endif %}">
<div class="collapse-trigger" data-toggle="collapse" aria-expanded="true" data-target="#review_step_9" aria-controls="collapse_changed_name">
<div>


+ 5
- 8
edivorce/apps/core/templatetags/step_order.py View File

@ -72,23 +72,20 @@ def _adjust_for_orders(next_item, want_which_orders, children_of_marriage=None,
@register.simple_tag(takes_context=True)
def step_order(context, step):
want_which_orders = __parse_json_which_orders_selected(context)
base_order = template_step_order[step]
order = base_order
derived_data = context.get('derived', dict())
if base_order > 5 and (
context.get('children_of_marriage', None) != 'YES' and
context.get('derived', dict()).get('has_children_of_marriage', None) is False
):
if base_order > 5 and not derived_data.get('has_children_of_marriage'):
order -= 1
if base_order > 6 and 'Spousal support' not in want_which_orders:
if base_order > 6 and not derived_data.get('wants_spousal_support'):
order -= 1
if base_order > 7 and 'Division of property and debts' not in want_which_orders:
if base_order > 7 and not derived_data.get('wants_property_division'):
order -= 1
if base_order > 8 and 'Other orders' not in want_which_orders:
if base_order > 8 and not derived_data.get('wants_other_orders'):
order -= 1
return order


+ 62
- 8
edivorce/apps/core/tests/test_api.py View File

@ -40,7 +40,8 @@ class MockRedis:
@mock.patch.object(Redis, 'get', MockRedis.get)
@mock.patch.object(Redis, 'delete', MockRedis.delete)
@mock.patch.object(Redis, 'exists', MockRedis.exists)
@modify_settings(MIDDLEWARE={'remove': 'edivorce.apps.core.middleware.bceid_middleware.BceidMiddleware', })
@modify_settings(MIDDLEWARE={'remove': 'edivorce.apps.core.middleware.bceid_middleware.BceidMiddleware'})
@override_settings(CLAMAV_ENABLED=False)
class APITest(APITestCase):
def setUp(self):
self.user = BceidUser.objects.create(user_guid='1234')
@ -73,8 +74,7 @@ class APITest(APITestCase):
}
self.client.force_authenticate(self.user)
with self.settings(CLAMAV_ENABLED=False):
response = self.client.post(url, data)
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
@ -101,21 +101,75 @@ class APITest(APITestCase):
}
self.client.force_authenticate(self.user)
with self.settings(CLAMAV_ENABLED=False):
response = self.client.post(url, data)
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(Document.objects.count(), 1)
file.seek(0) #
file.seek(0)
with self.settings(CLAMAV_ENABLED=False):
response = self.client.post(url, data)
response = self.client.post(url, data)
self.assertContains(response,
'This file appears to have already been uploaded for this document.',
status_code=status.HTTP_400_BAD_REQUEST)
def test_post_only_one_pdf(self):
url = reverse('documents')
file = _create_file()
data = {
'file': file,
'doc_type': 'AAI',
'party_code': 1
}
self.client.force_authenticate(self.user)
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(Document.objects.count(), 1)
file = _create_file(extension='pdf')
data = {
'file': file,
'doc_type': 'AAI',
'party_code': 1
}
response = self.client.post(url, data)
self.assertContains(response,
"Only one PDF is allowed per form, and PDF documents cannot be combined with images.",
status_code=status.HTTP_400_BAD_REQUEST)
self.assertEqual(Document.objects.count(), 1)
def test_post_no_existing_pdfs(self):
url = reverse('documents')
file = _create_file(extension='pdf')
data = {
'file': file,
'doc_type': 'AAI',
'party_code': 1
}
self.client.force_authenticate(self.user)
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(Document.objects.count(), 1)
file = _create_file()
data = {
'file': file,
'doc_type': 'AAI',
'party_code': 1
}
response = self.client.post(url, data)
self.assertContains(response,
"PDF documents cannot be combined with images. Only a single PDF or multiple images can be uploaded into one form.",
status_code=status.HTTP_400_BAD_REQUEST)
self.assertEqual(Document.objects.count(), 1)
def test_post_field_validation(self):
url = reverse('documents')


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

@ -57,6 +57,7 @@ class ConditionalLogicTestCase(TestCase):
# Has children, and marked YES to children of marriage in prequal
self.create_response('children_of_marriage', 'YES')
self.create_response('has_children_under_19', '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')
@ -70,12 +71,34 @@ class ConditionalLogicTestCase(TestCase):
self.assertFalse(logic.determine_shared_custody(self.questions_dict))
self.create_response('children_of_marriage', 'YES')
self.create_response('has_children_under_19', '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))
def test_has_children_of_marriage(self):
self.assertFalse(logic.determine_has_children_of_marriage(self.questions_dict))
self.create_response('children_of_marriage', 'NO')
self.assertFalse(logic.determine_has_children_of_marriage(self.questions_dict))
self.create_response('children_of_marriage', 'YES')
self.create_response('has_children_under_19', 'YES')
self.assertTrue(logic.determine_has_children_of_marriage(self.questions_dict))
self.create_response('has_children_under_19', 'NO')
self.create_response('has_children_over_19', 'NO')
self.assertFalse(logic.determine_has_children_of_marriage(self.questions_dict))
self.create_response('has_children_over_19', 'YES')
self.create_response('children_financial_support', '["NO"]')
self.assertFalse(logic.determine_has_children_of_marriage(self.questions_dict))
self.create_response('children_financial_support', '["Yes, attending post secondary institution"]')
self.assertTrue(logic.determine_has_children_of_marriage(self.questions_dict))
class ViewLogic(TestCase):
def test_content_type_from_filename(self):


+ 31
- 6
edivorce/apps/core/tests/test_step_completeness.py View File

@ -466,6 +466,7 @@ class ChildrenStepCompletenessTestCase(TestCase):
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')
self.create_response('has_children_under_19', 'YES')
def get_children_step_status(self, substep=None):
responses_dict = get_data_for_user(self.user)
@ -499,12 +500,36 @@ class ChildrenStepCompletenessTestCase(TestCase):
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')
self.assertEqual(self.get_children_step_status(), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('your_children'), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('income_expenses'), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('facts'), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('payor_medical'), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('what_for'), Status.HIDDEN)
def test_only_grown_children(self):
self.create_response('children_of_marriage', 'YES')
self.create_response('has_children_under_19', 'NO')
self.create_response('has_children_over_19', 'YES')
self.create_response('children_financial_support', '["NO"]')
self.assertEqual(self.get_children_step_status(), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('your_children'), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('income_expenses'), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('facts'), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('payor_medical'), Status.HIDDEN)
self.assertEqual(self.get_children_step_status('what_for'), Status.HIDDEN)
def test_has_children(self):
self.create_response('children_of_marriage', 'YES')
self.create_response('has_children_under_19', 'NO')
self.create_response('has_children_over_19', 'YES')
self.create_response('children_financial_support', '["Yes, other reason"]')
self.assertEqual(self.get_children_step_status(), Status.NOT_STARTED)
self.assertEqual(self.get_children_step_status('your_children'), Status.NOT_STARTED)
self.assertEqual(self.get_children_step_status('income_expenses'), Status.NOT_STARTED)
self.assertEqual(self.get_children_step_status('facts'), Status.NOT_STARTED)
self.assertEqual(self.get_children_step_status('payor_medical'), Status.NOT_STARTED)
self.assertEqual(self.get_children_step_status('what_for'), Status.NOT_STARTED)
def test_children_details(self):
substep = 'your_children'


+ 11
- 5
edivorce/apps/core/utils/conditional_logic.py View File

@ -3,21 +3,23 @@ import json
import re
def determine_has_children_of_marriage(questions_dict):
has_children = questions_dict.get('children_of_marriage', '') == 'YES'
has_under_19 = questions_dict.get('has_children_under_19', '') == 'YES'
return has_children and (has_under_19 or _children_over_19_supported(questions_dict))
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':
if not determine_has_children_of_marriage(questions_dict):
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', '[]')
@ -69,6 +71,10 @@ def determine_split_custody(questions_dict):
@if_no_children(return_val=False)
def determine_child_over_19_supported(questions_dict):
return _children_over_19_supported(questions_dict)
def _children_over_19_supported(questions_dict):
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


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

@ -117,9 +117,7 @@ def children(responses, derived):
def has_children_of_marriage(responses, derived):
""" Returns whether or not the their are children of marriage for claim"""
return responses.get('children_of_marriage', '') == 'YES'
return conditional_logic.determine_has_children_of_marriage(responses)
def wants_divorce_order(responses, derived):


+ 3
- 2
vue/src/components/Uploader/Uploader.vue View File

@ -247,8 +247,9 @@
if (newFile.file && newFile.type.substr(0, 6) === "image/") {
new Compressor(newFile.file, {
quality: 0.9,
maxWidth: 3600,
maxHeight: 3600,
maxWidth: 3300,
maxHeight: 3300,
convertSize: Infinity,
success(result) {
console.log(result);
self.$refs.upload.update(newFile, {


Loading…
Cancel
Save