From c0966949c393af5c4e5f1549c3b531b3945a3af2 Mon Sep 17 00:00:00 2001 From: Sam Warren Date: Thu, 7 Mar 2024 16:14:57 -0700 Subject: [PATCH] revert changes to registration number lookup --- python/common/test_splunk.py | 8 +- python/prohibition_web_svc/blueprints/icbc.py | 8 +- .../middleware/icbc_middleware.py | 4 +- .../tests/test_icbc_resources.py | 90 +++++----- .../src/api/icbcVehicleDataApi.js | 4 +- .../src/components/CommonForm/vehicleInfo.js | 155 +++++++++--------- 6 files changed, 130 insertions(+), 139 deletions(-) diff --git a/python/common/test_splunk.py b/python/common/test_splunk.py index 3b4a06c45..8b8db9113 100644 --- a/python/common/test_splunk.py +++ b/python/common/test_splunk.py @@ -67,11 +67,11 @@ def test_splunk_logs_icbc_get_driver_event(): @responses.activate def test_splunk_logs_icbc_get_vehicle_event(): username = 'someuser@bceid' - registration_number = '10006241' + plate_number = 'RXC234' expected_payload = { 'event': 'icbc_get_vehicle', 'source': 'be78d6', - 'queried_registration_number': registration_number + 'queried_plate': plate_number } responses.add(responses.GET, @@ -82,7 +82,7 @@ def test_splunk_logs_icbc_get_vehicle_event(): is_okay, args = splunk_get_vehicle(splunk_data=expected_payload, config=Config, - registration_number=registration_number, + plate_number=plate_number, username=username, user_guid='') log_to_splunk(**args) @@ -93,5 +93,5 @@ def test_splunk_logs_icbc_get_vehicle_event(): "event": 'icbc_get_vehicle', "user_guid": '', "username": "someuser@bceid", - 'queried_registration_number': registration_number + 'queried_plate': plate_number }, "source": "be78d6"} diff --git a/python/prohibition_web_svc/blueprints/icbc.py b/python/prohibition_web_svc/blueprints/icbc.py index ece63a8da..14b8aaa66 100644 --- a/python/prohibition_web_svc/blueprints/icbc.py +++ b/python/prohibition_web_svc/blueprints/icbc.py @@ -36,8 +36,8 @@ def get_driver(dl_number): return kwargs.get('response') -@bp.route('/icbc/vehicles/', methods=['GET']) -def get_vehicle(registration_number): +@bp.route('/icbc/vehicles/', methods=['GET']) +def get_vehicle(plate_number): if request.method == 'GET': kwargs = middle_logic( get_authorized_keycloak_user() + [ @@ -51,9 +51,7 @@ def get_vehicle(registration_number): {"try": splunk.log_to_splunk, "fail": []} ], required_permission='vehicle-get', - registration_number=registration_number, + plate_number=plate_number.upper(), request=request, config=Config) return kwargs.get('response') - - diff --git a/python/prohibition_web_svc/middleware/icbc_middleware.py b/python/prohibition_web_svc/middleware/icbc_middleware.py index 12a529f6d..f6be35110 100644 --- a/python/prohibition_web_svc/middleware/icbc_middleware.py +++ b/python/prohibition_web_svc/middleware/icbc_middleware.py @@ -41,7 +41,7 @@ def get_icbc_driver(**kwargs) -> tuple: def get_icbc_vehicle(**kwargs) -> tuple: url = "{}/vehicles".format(Config.ICBC_API_ROOT) url_parameters = { - "registrationNumber": kwargs.get('registraion_number'), + "plateNumber": kwargs.get('plate_number'), # TODO - removed effectiveDate for debugging purposes # "effectiveDate": datetime.now().astimezone().replace(microsecond=0).isoformat() } @@ -72,6 +72,6 @@ def splunk_get_vehicle(**kwargs) -> tuple: "event": "icbc_get_vehicle", "username": kwargs.get('username'), "user_guid": kwargs.get('user_guid'), - "queried_registration_number": kwargs.get('registration_number') + "queried_plate": kwargs.get('plate_number') } return True, kwargs diff --git a/python/prohibition_web_svc/tests/test_icbc_resources.py b/python/prohibition_web_svc/tests/test_icbc_resources.py index 4aac33fb6..eb3eda831 100644 --- a/python/prohibition_web_svc/tests/test_icbc_resources.py +++ b/python/prohibition_web_svc/tests/test_icbc_resources.py @@ -136,7 +136,7 @@ def test_authorized_user_gets_vehicle_not_found(as_guest, monkeypatch, roles): '{}/vehicles?{}'.format( Config.ICBC_API_ROOT, urllib.parse.urlencode({ - "registrationNumber": "00000000", + "plateNumber": "AAAAA", # "effectiveDate": datetime.now().astimezone().replace(microsecond=0).isoformat() }) ), @@ -146,7 +146,7 @@ def test_authorized_user_gets_vehicle_not_found(as_guest, monkeypatch, roles): responses.add(responses.POST, "{}:{}/services/collector".format( Config.SPLUNK_HOST, Config.SPLUNK_PORT), status=200) - resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/00000000", + resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/AAAAA", follow_redirects=True, content_type="application/json", headers=_get_keycloak_auth_header(_get_keycloak_access_token())) @@ -161,7 +161,7 @@ def test_authorized_user_gets_vehicle_not_found(as_guest, monkeypatch, roles): 'event': 'icbc_get_vehicle', 'username': 'larry@idir', 'user_guid': 'larry@idir', - 'queried_registration_number': '00000000', + 'queried_plate': 'AAAAA', }, 'source': 'be78d6' }) @@ -176,7 +176,7 @@ def test_authorized_user_gets_vehicle(as_guest, monkeypatch, roles): '{}/vehicles?{}'.format( Config.ICBC_API_ROOT, urllib.parse.urlencode({ - "registrationNumber": "03371224", + "plateNumber": "LD626J", # "effectiveDate": datetime.now().astimezone().replace(microsecond=0).isoformat() }) ), @@ -186,61 +186,61 @@ def test_authorized_user_gets_vehicle(as_guest, monkeypatch, roles): responses.add(responses.POST, "{}:{}/services/collector".format( Config.SPLUNK_HOST, Config.SPLUNK_PORT), status=200) - resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/03371224", + resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/LD626J", follow_redirects=True, content_type="application/json", headers=_get_keycloak_auth_header(_get_keycloak_access_token())) assert resp.status_code == 200 - assert 'registrationNumber' in resp.json[0] - assert resp.json[0]['registrationNumber'] == "03371224" + assert 'plateNumber' in resp.json[0] + assert resp.json[0]['plateNumber'] == "LD626J" assert responses.calls[0].request.headers['loginUserId'] == 'larry@idir' assert responses.calls[1].request.body.decode() == json.dumps({ 'event': { 'event': 'icbc_get_vehicle', 'username': 'larry@idir', 'user_guid': 'larry@idir', - 'queried_registration_number': '03371224', + 'queried_plate': 'LD626J', }, 'source': 'be78d6' }) -# @responses.activate -# def test_request_for_licence_plate_using_lowercase_automatically_converted_to_upper(as_guest, monkeypatch, roles): -# monkeypatch.setattr(middleware, "get_keycloak_certificates", _mock_keycloak_certificates) -# monkeypatch.setattr(middleware, "decode_keycloak_access_token", _get_authorized_user) - -# responses.add(responses.GET, -# '{}/vehicles?{}'.format( -# Config.ICBC_API_ROOT, -# urllib.parse.urlencode({ -# "plateNumber": "LD626J", -# # "effectiveDate": datetime.now().astimezone().replace(microsecond=0).isoformat() -# }) -# ), -# json=sample_vehicle_response(), -# status=200) - -# responses.add(responses.POST, "{}:{}/services/collector".format( -# Config.SPLUNK_HOST, Config.SPLUNK_PORT), status=200) - -# resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/ld626j", -# follow_redirects=True, -# content_type="application/json", -# headers=_get_keycloak_auth_header(_get_keycloak_access_token())) -# assert resp.status_code == 200 -# assert 'plateNumber' in resp.json[0] -# assert resp.json[0]['plateNumber'] == "LD626J" -# assert responses.calls[0].request.headers['loginUserId'] == 'larry@idir' -# assert responses.calls[1].request.body.decode() == json.dumps({ -# 'event': { -# 'event': 'icbc_get_vehicle', -# 'username': 'larry@idir', -# 'user_guid': 'larry@idir', -# 'queried_registration_number': 'LD626J', -# }, -# 'source': 'be78d6' -# }) +@responses.activate +def test_request_for_licence_plate_using_lowercase_automatically_converted_to_upper(as_guest, monkeypatch, roles): + monkeypatch.setattr(middleware, "get_keycloak_certificates", _mock_keycloak_certificates) + monkeypatch.setattr(middleware, "decode_keycloak_access_token", _get_authorized_user) + + responses.add(responses.GET, + '{}/vehicles?{}'.format( + Config.ICBC_API_ROOT, + urllib.parse.urlencode({ + "plateNumber": "LD626J", + # "effectiveDate": datetime.now().astimezone().replace(microsecond=0).isoformat() + }) + ), + json=sample_vehicle_response(), + status=200) + + responses.add(responses.POST, "{}:{}/services/collector".format( + Config.SPLUNK_HOST, Config.SPLUNK_PORT), status=200) + + resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/ld626j", + follow_redirects=True, + content_type="application/json", + headers=_get_keycloak_auth_header(_get_keycloak_access_token())) + assert resp.status_code == 200 + assert 'plateNumber' in resp.json[0] + assert resp.json[0]['plateNumber'] == "LD626J" + assert responses.calls[0].request.headers['loginUserId'] == 'larry@idir' + assert responses.calls[1].request.body.decode() == json.dumps({ + 'event': { + 'event': 'icbc_get_vehicle', + 'username': 'larry@idir', + 'user_guid': 'larry@idir', + 'queried_plate': 'LD626J', + }, + 'source': 'be78d6' + }) def test_unauthorized_user_cannot_get_vehicle(as_guest, monkeypatch, roles): @@ -372,7 +372,7 @@ def _vehicle_not_found() -> dict: "code": 404, "message": "Not Found", "description": "vehicle not found", - "request_uri": "/vehicles?registrationNumber=0000000", + "request_uri": "/vehicles?plateNumber=LD626J", "request_id": "716243aa-ca18-441d-aa3e-e6e8776ca825" } } diff --git a/roadside-forms-frontend/frontend_web_app/src/api/icbcVehicleDataApi.js b/roadside-forms-frontend/frontend_web_app/src/api/icbcVehicleDataApi.js index d8c917ba5..dc69695e9 100644 --- a/roadside-forms-frontend/frontend_web_app/src/api/icbcVehicleDataApi.js +++ b/roadside-forms-frontend/frontend_web_app/src/api/icbcVehicleDataApi.js @@ -2,13 +2,13 @@ import { api } from "./config/axiosConfig"; import { createRequestHeader } from "../utils/requestHeaders"; export const ICBCVehicleDataApi = { - get: async function (registrationNumber) { + get: async function (licencePlate) { const headers = { ...createRequestHeader(), }; return await api .request({ - url: `/api/v1/icbc/vehicles/${registrationNumber}`, + url: `/api/v1/icbc/vehicles/${licencePlate}`, method: "GET", headers: { ...headers }, }) diff --git a/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/vehicleInfo.js b/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/vehicleInfo.js index d93382800..60ae364d7 100644 --- a/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/vehicleInfo.js +++ b/roadside-forms-frontend/frontend_web_app/src/components/CommonForm/vehicleInfo.js @@ -45,58 +45,52 @@ export const VehicleInfo = (props) => { }, [driversLicenceJurisdiction]); const fetchICBCVehicleInfo = async () => { - if (values["vehicle_registration_no"]) { - await ICBCVehicleDataApi.get(values["vehicle_registration_no"]).then( - (resp) => { - //ICBC sends back different responses based on sucess and fail and only real way to check is if it is an array - if (resp.status === "success") { - console.log("resp: ", resp); - const vehicle = resp.data[0]; - const party = vehicle.vehicleParties[0].party; - const address = party.addresses[0]; - setFieldValue("nsc_no", vehicle.nscNumber); - setFieldValue("vehicle_plate_no", vehicle.plateNumber); - const colour = vehicleColours.filter( - (item) => item.label === vehicle.vehicleColour.toUpperCase() - )[0].value; - setFieldValue("vehicle_colour", [colour]); - setFieldValue("vehicle_mk_md", vehicle.vehicleMake + " - "); - setFieldValue("vehicle_vin_no", vehicle.vehicleIdNumber); - setFieldValue( - "vehicle_year", - years.filter((item) => item.label === vehicle.vehicleModelYear)[0] - ); - setFieldValue( - "vehicle_type", - vehicleTypes.filter( - (item) => item.label === vehicle.vehicleType.toUpperCase() - )[0] - ); - setFieldValue("vehicle_jurisdiction", { - value: "CA_BC", - label: "BRITISH COLUMBIA", - }); - setFieldValue("regist_owner_last_name", party.lastName); - setFieldValue("regist_owner_first_name", party.firstName); - setFieldValue("regist_owner_dob", new Date(party.birthDate)); - setFieldValue("regist_owner_address", address.addressLine1); - setFieldValue("regist_owner_city", address.city); - setFieldValue("regist_owner_postal", address.postalCode); - setFieldValue("regist_owner_prov_state", { - value: "CA_BC", - label: "BRITISH COLUMBIA", - }); - return; - } else { - toast.error( - "No vehicle was found using this registration number.", - { - position: toast.POSITION.TOP_RIGHT, - } - ); - } + if (values["vehicle_plate_no"]) { + await ICBCVehicleDataApi.get(values["vehicle_plate_no"]).then((resp) => { + //ICBC sends back different responses based on sucess and fail and only real way to check is if it is an array + if (resp.status === "success") { + const vehicle = resp.data[0]; + const party = vehicle.vehicleParties[0].party; + const address = party.addresses[0]; + setFieldValue("nsc_no", vehicle.nscNumber); + setFieldValue("vehicle_registration_no", vehicle.registrationNumber); + const colour = vehicleColours.filter( + (item) => item.label === vehicle.vehicleColour.toUpperCase() + )[0].value; + setFieldValue("vehicle_colour", [colour]); + setFieldValue("vehicle_mk_md", vehicle.vehicleMake + " - "); + setFieldValue("vehicle_vin_no", vehicle.vehicleIdNumber); + setFieldValue( + "vehicle_year", + years.filter((item) => item.label === vehicle.vehicleModelYear)[0] + ); + setFieldValue( + "vehicle_type", + vehicleTypes.filter( + (item) => item.label === vehicle.vehicleType.toUpperCase() + )[0] + ); + setFieldValue("vehicle_jurisdiction", { + value: "CA_BC", + label: "BRITISH COLUMBIA", + }); + setFieldValue("regist_owner_last_name", party.lastName); + setFieldValue("regist_owner_first_name", party.firstName); + setFieldValue("regist_owner_dob", new Date(party.birthDate)); + setFieldValue("regist_owner_address", address.addressLine1); + setFieldValue("regist_owner_city", address.city); + setFieldValue("regist_owner_postal", address.postalCode); + setFieldValue("regist_owner_prov_state", { + value: "CA_BC", + label: "BRITISH COLUMBIA", + }); + return; + } else { + toast.error("No vehicle was found using this plate number.", { + position: toast.POSITION.TOP_RIGHT, + }); } - ); + }); } }; @@ -115,28 +109,24 @@ export const VehicleInfo = (props) => {

Vehicle Information

- {(values["TwentyFourHour"] || values["VI"]) && ( - <> - - - - - - - - )} + + + + + + { /> + - - - + {(values["TwentyFourHour"] || values["VI"]) && ( + + + + )}