Skip to content

Commit

Permalink
Fixed a bug caused by a misplaced closing brace in the return stateme…
Browse files Browse the repository at this point in the history
…nt. (#1574)
  • Loading branch information
eve-git authored Sep 13, 2024
1 parent 25fe846 commit 4e9e272
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.6'
__version__ = '1.2.7'
29 changes: 10 additions & 19 deletions api/namex/resources/mras.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from http import HTTPStatus

import requests, xmltodict
from flask import current_app, jsonify, make_response
from flask import current_app, jsonify, make_response, current_app
from flask_restx import Namespace, Resource, cors
from lxml import etree # Don't worry about this it exists... the module is dynamically loaded

Expand Down Expand Up @@ -56,15 +56,15 @@ class MrasProfile(Resource):
def get(self, province, corp_num):
try:
# Get the jurisdiction
print('Calling MRAS Jurisdictions API using [corp_num: {corp_num}]'.format(corp_num=corp_num))
current_app.logger.debug('Calling MRAS Jurisdictions API using [corp_num: {corp_num}]'.format(corp_num=corp_num))
mras_url = f'{current_app.config.get("MRAS_SVC_URL")}/api/v1/xpr/jurisdictions/{corp_num}'
headers = {
'x-api-key': current_app.config.get('MRAS_SVC_API_KEY'),
'Accept': 'application/xml'
}

print(mras_url)
print(repr(headers))
current_app.logger.debug(mras_url)
current_app.logger.debug(repr(headers))
response = requests.get(
mras_url,
headers=headers
Expand All @@ -86,43 +86,34 @@ def get(self, province, corp_num):
if province not in jurisdiction_ids:
return make_response(jsonify(message='Invalid request, province jurisdiction is incorrect'), HTTPStatus.BAD_REQUEST)
else:
print('Valid jurisdiction IDs')
print(repr(jurisdiction_ids))
current_app.logger.debug('Valid jurisdiction IDs')
current_app.logger.debug(repr(jurisdiction_ids))

# Get the profile
print('\nCalling MRAS Profile API using [corp_num: {corp_num}], [province: {province}]'.format(corp_num=corp_num, province=province))
current_app.logger.debug('\nCalling MRAS Profile API using [corp_num: {corp_num}], [province: {province}]'.format(corp_num=corp_num, province=province))
mras_url = f'{current_app.config.get("MRAS_SVC_URL")}/api/v1/xpr/GetProfile/{corp_num}/{province}'

headers = {
'x-api-key': current_app.config.get('MRAS_SVC_API_KEY'),
'Accept': 'application/xml'
}

print(mras_url)
print(repr(headers))
current_app.logger.debug(mras_url)
current_app.logger.debug(repr(headers))
response = requests.get(
mras_url,
headers=headers
)


# Return the auth response if an error occurs
if not response.status_code == HTTPStatus.OK:
return make_response(jsonify({'error': 'No profile found for the jurisdiction, registration number pair.'}), HTTPStatus.NOT_FOUND)
# mras_errors = load_xml_response_content(response, './/mras_error')
# mras_error = {
# 'error_code': mras_errors[0].find('error_code').text,
# 'internal_error_code': mras_errors[0].find('internal_error_code').text,
# 'internal_error_message': mras_errors[0].find('internal_error_message').text
# }

# raise MrasServiceException(mras_error=mras_error)

# Just return true or false, the profile either exists or it doesn't
# Note: the response content is in xml format so we need to parse it to json format.
dict_data = xmltodict.parse(response.content)
jsonify_data = jsonify(dict_data)
return make_response(jsonify_data), HTTPStatus.OK
return make_response(jsonify_data, HTTPStatus.OK)
except MrasServiceException as err:
return handle_exception(err, err.message, err.error_code)
except Exception as err:
Expand Down

0 comments on commit 4e9e272

Please sign in to comment.