Browse Source

Added proper mocking for package tests

pull/172/head
Michael Olund 5 years ago
parent
commit
a0418a1ba4
2 changed files with 15 additions and 10 deletions
  1. +11
    -4
      edivorce/apps/core/tests/test_efiling_packaging.py
  2. +4
    -6
      edivorce/apps/core/utils/efiling_packaging.py

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

@ -1,3 +1,6 @@
import json
from unittest import mock
from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sessions.middleware import SessionMiddleware
from django.test import TransactionTestCase from django.test import TransactionTestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
@ -17,8 +20,8 @@ class EFilingPackagingTests(TransactionTestCase):
middleware.process_request(self.request) middleware.process_request(self.request)
self.request.session.save() self.request.session.save()
self.packaging = EFilingPackaging(initial_filing=True,
court_locations={"Vancouver": {"location_id": "6011"}})
self.packaging = EFilingPackaging(initial_filing=True)
# court_locations={"Vancouver": {"location_id": "6011"}}
def test_format_package(self): def test_format_package(self):
files = [] files = []
@ -46,14 +49,18 @@ class EFilingPackagingTests(TransactionTestCase):
self.assertEqual(package['filingPackage']['parties'][0]['firstName'], 'Party 0') self.assertEqual(package['filingPackage']['parties'][0]['firstName'], 'Party 0')
self.assertEqual(package['filingPackage']['parties'][1]['firstName'], 'Party 1') self.assertEqual(package['filingPackage']['parties'][1]['firstName'], 'Party 1')
def test_get_location_success(self):
@mock.patch('edivorce.apps.core.utils.efiling_court_locations.EFilingCourtLocations.courts')
def test_get_location_success(self, mock_courts):
mock_courts.return_value = {"Vancouver": {"location_id": "6011"}}
responses = { responses = {
"court_registry_for_filing": "Vancouver" "court_registry_for_filing": "Vancouver"
} }
location = self.packaging._get_location(None, responses) location = self.packaging._get_location(None, responses)
self.assertEqual(location, '6011') self.assertEqual(location, '6011')
def test_get_location_fail(self):
@mock.patch('edivorce.apps.core.utils.efiling_court_locations.EFilingCourtLocations.courts')
def test_get_location_fail(self, mock_courts):
mock_courts.return_value = {"Vancouver": {"location_id": "6011"}}
responses = { responses = {
"court_registry_for_filing": "Tokyo" "court_registry_for_filing": "Tokyo"
} }


+ 4
- 6
edivorce/apps/core/utils/efiling_packaging.py View File

@ -102,9 +102,8 @@ NJF_JSON_FORMAT = {
class EFilingPackaging: class EFilingPackaging:
def __init__(self, initial_filing, court_locations=None):
def __init__(self, initial_filing):
self.initial_filing = initial_filing self.initial_filing = initial_filing
self.court_locations = court_locations
def format_package(self, request, responses, files, documents): def format_package(self, request, responses, files, documents):
package = PACKAGE_FORMAT.copy() package = PACKAGE_FORMAT.copy()
@ -315,10 +314,9 @@ class EFilingPackaging:
def _get_location(self, request, responses): def _get_location(self, request, responses):
location_name = responses.get('court_registry_for_filing', '') location_name = responses.get('court_registry_for_filing', '')
if not self.court_locations:
self.court_locations = EFilingCourtLocations().courts(request)
return self.court_locations.get(location_name,
{'location_id': '0000'}).get('location_id')
court_locations = EFilingCourtLocations().courts(request)
return court_locations.get(location_name,
{'location_id': '0000'}).get('location_id')
def _get_file_number(self, responses): def _get_file_number(self, responses):
if not self.initial_filing: if not self.initial_filing:


Loading…
Cancel
Save