Skip to content

Commit

Permalink
MHR API bug fix search note remarks, legacy location type (#1612)
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Lovett <[email protected]>
  • Loading branch information
doug-lovett authored Nov 3, 2023
1 parent c5bb07b commit 9bbb2a1
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<tr>
<td class="section-sub-title">Remarks:</td>
<td>{% if note.remarks is defined and note.remarks != '' %}
{{note.remarks}}
{{note.remarks|safe}}
{% else %}
N/A
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<tr>
<td class="section-sub-title">Remarks:</td>
<td>{% if note.remarks is defined and note.remarks != '' %}
{{note.remarks}}
{{note.remarks|safe}}
{% else %}
N/A
{% endif %}
Expand Down
17 changes: 16 additions & 1 deletion mhr_api/src/mhr_api/models/db2/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def registration_json(self):
location['taxExpiryDate'] = tax_date
if self.ltsa:
location['legalDescription'] = self.ltsa.ltsa_description
return location
return self.derive_location_type(location)

@property
def new_registration_json(self):
Expand Down Expand Up @@ -307,6 +307,21 @@ def new_registration_json(self):
tax_date = model_utils.format_local_date(self.tax_certificate_date)
if tax_date:
location['taxExpiryDate'] = tax_date
return self.derive_location_type(location)

def derive_location_type(self, location: dict) -> dict:
"""Add the locationType using the same logic as data migration."""
if self.dealer_name:
location['locationType'] = MhrLocationTypes.MANUFACTURER
elif self.park_name:
location['locationType'] = MhrLocationTypes.MH_PARK
elif self.additional_description and \
(self.additional_description.find('BAND') > -1 or
self.additional_description.find('RESERVE') > -1 or
self.additional_description.find('INDIAN') > -1):
location['locationType'] = MhrLocationTypes.RESERVE
else:
location['locationType'] = MhrLocationTypes.OTHER
return location

@staticmethod
Expand Down
139 changes: 139 additions & 0 deletions mhr_api/tests/unit/models/db2/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from registry_schemas.example_data.mhr import REGISTRATION

from mhr_api.models import Db2Location, MhrRegistration, utils as model_utils
from mhr_api.models.type_tables import MhrLocationTypes


TEST_LOCATION = Db2Location(location_id=1,
Expand Down Expand Up @@ -56,6 +57,126 @@
except_plan='except',
dealer_name='dealer',
additional_description='additional')
TEST_LOCATION_MANUFACTURER = Db2Location(location_id=1,
status='A',
reg_document_id='1234',
can_document_id='5678',
street_number='1234',
street_name='street name',
town_city='town',
province='BC',
area='',
jurisdiction='',
roll_number='',
park_name='',
park_pad='',
pid_number='',
lot='',
parcel='',
block='',
district_lot='',
part_of='',
section='',
township='',
range='',
meridian='',
land_district='',
plan='',
tax_certificate='Y',
leave_bc='N',
except_plan='',
dealer_name='DEALER',
additional_description='additional')
TEST_LOCATION_PARK = Db2Location(location_id=1,
status='A',
reg_document_id='1234',
can_document_id='5678',
street_number='1234',
street_name='street name',
town_city='town',
province='BC',
area='',
jurisdiction='',
roll_number='',
park_name='LAZY WHEEL MOBILE HOME PARK',
park_pad='37',
pid_number='',
lot='',
parcel='',
block='',
district_lot='',
part_of='',
section='',
township='',
range='',
meridian='',
land_district='',
plan='',
tax_certificate='Y',
leave_bc='N',
except_plan='',
dealer_name='',
additional_description='additional')
TEST_LOCATION_RESERVE = Db2Location(location_id=1,
status='A',
reg_document_id='1234',
can_document_id='5678',
street_number='1234',
street_name='street name',
town_city='town',
province='BC',
area='',
jurisdiction='',
roll_number='',
park_name='',
park_pad='',
pid_number='',
lot='',
parcel='',
block='',
district_lot='',
part_of='',
section='',
township='',
range='',
meridian='',
land_district='',
plan='',
tax_certificate='Y',
leave_bc='N',
except_plan='',
dealer_name='',
additional_description='additional INDIAN RESERVE XXXX')
TEST_LOCATION_OTHER = Db2Location(location_id=1,
status='A',
reg_document_id='1234',
can_document_id='5678',
street_number='1234',
street_name='street name',
town_city='town',
province='BC',
area='',
jurisdiction='',
roll_number='',
park_name='',
park_pad='',
pid_number='012777846',
lot='',
parcel='',
block='',
district_lot='',
part_of='',
section='',
township='',
range='',
meridian='',
land_district='',
plan='',
tax_certificate='Y',
leave_bc='N',
except_plan='',
dealer_name='',
additional_description='additional')
# testdata pattern is ({exists}, {manuhome_id}, {park_name}, {pad}, {street_num}, {street}, {city}. {count})
TEST_DATA = [
(True, 1, '', '', '4004', 'POPLAR AVENUE', 'FORT NELSON', 2),
Expand All @@ -82,6 +203,13 @@
(26, '3120 NORTH ISLAND HIGHWAY', 'CAMPBELL RIVER', 'BC', 'CA'),
(87950, '13455 FORT ROAD', 'EDMONTON', 'AB', 'CA')
]
# testdata pattern is ({location}, {location_type})
TEST_TYPE_DATA = [
(TEST_LOCATION_MANUFACTURER, MhrLocationTypes.MANUFACTURER.value),
(TEST_LOCATION_PARK, MhrLocationTypes.MH_PARK.value),
(TEST_LOCATION_RESERVE, MhrLocationTypes.RESERVE.value),
(TEST_LOCATION_OTHER, MhrLocationTypes.OTHER.value)
]


@pytest.mark.parametrize('exists,manuhome_id,park_name,pad,street_num,street,city,count', TEST_DATA)
Expand Down Expand Up @@ -257,6 +385,7 @@ def test_registration_json(session, street_num, street_name, street_json):
json_data = location.registration_json
assert json_data.get('address')
assert json_data['address']['street'] == street_json
assert json_data['locationType'] == MhrLocationTypes.MANUFACTURER


@pytest.mark.parametrize('street_num,street_name,street_json', TEST_ADDRESS_DATA)
Expand All @@ -268,6 +397,7 @@ def test_new_registration_json(session, street_num, street_name, street_json):
json_data = location.new_registration_json
assert json_data.get('address')
assert json_data['address']['street'] == street_json
assert json_data['locationType'] == MhrLocationTypes.MANUFACTURER


def test_location_json(session):
Expand Down Expand Up @@ -306,3 +436,12 @@ def test_location_json(session):
'additionalDescription': location.additional_description
}
assert location.json == test_json


@pytest.mark.parametrize('location,location_type', TEST_TYPE_DATA)
def test_location_type(session, location, location_type):
"""Assert that creating location json location type is as expected."""
json_data = location.new_registration_json
assert json_data['locationType'] == location_type
json_data = location.registration_json
assert json_data['locationType'] == location_type

0 comments on commit 9bbb2a1

Please sign in to comment.