Skip to content

Commit

Permalink
FIx: process lower/mixed case data types
Browse files Browse the repository at this point in the history
  • Loading branch information
f-idiris committed Oct 20, 2023
1 parent 26bd94c commit 0712c30
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions chem_spectra/controller/refresh_token_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

refresh_token_api = Blueprint('refresh_token_api', __name__)

@refresh_token_api.route("/login", methods=["POST"])
@refresh_token_api.route("/api/v1/chemspectra/login", methods=["POST"])
def login():
access_token = create_access_token(identity="user")
refresh_token = create_refresh_token(identity="user")
return jsonify(access_token=access_token, refresh_token=refresh_token)


@refresh_token_api.route("/refresh", methods=["POST"])
@refresh_token_api.route("/api/v1/chemspectra/refresh", methods=["POST"])
@jwt_required(refresh=True)
def refresh():
identity = get_jwt_identity()
Expand Down
4 changes: 3 additions & 1 deletion chem_spectra/lib/converter/jcamp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __set_datatype(self):
with open(data_type_json, 'r') as mapping_file:
data_type_mappings = json.load(mapping_file)["datatypes"]
for key, values in data_type_mappings.items():
values = [value.upper() for value in values]
for dt in dts:
if dt in values and key in dt_dict:
return dt_dict[key]
Expand All @@ -73,7 +74,8 @@ def __typ(self):
data_type_mappings = json.load(mapping_file)["datatypes"]

for key, values in data_type_mappings.items():
if dt in values:
values = [value.upper() for value in values]
if dt.upper() in values:
return key
return ''

Expand Down
2 changes: 1 addition & 1 deletion chem_spectra/lib/converter/jcamp/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __thres(self):
def __index_target(self):
with open(data_type_json, 'r') as mapping_file:
target = json.load(mapping_file).get("datatypes").values()
target_topics = [value for values in target for value in values]
target_topics = [value.upper() for values in target for value in values]

for tp in target_topics:
if tp in self.datatypes:
Expand Down
8 changes: 4 additions & 4 deletions tests/controller/test_refresh_token_api.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
def test_login(client):
response = client.post('/login')
response = client.post('/api/v1/chemspectra/login')
data = response.json
assert response.status_code == 200
assert "access_token" in data
assert "refresh_token" in data

def test_refresh(client):
# get refresh token
response = client.post('/login')
response = client.post('/api/v1/chemspectra/login')
data = response.json
refresh_token = data.get('refresh_token')

refresh_response = client.post('/refresh', headers={'Authorization': f'Bearer {refresh_token}'})
refresh_response = client.post('/api/v1/chemspectra/refresh', headers={'Authorization': f'Bearer {refresh_token}'})
data = refresh_response.json
assert "access_token" in data
assert refresh_response.status_code == 200

def test_refresh_without_refresh_token(client):
response = client.post('/refresh')
response = client.post('/api/v1/chemspectra/refresh')
assert response.status_code == 401
2 changes: 1 addition & 1 deletion tests/controller/test_spectra_layout_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
orig_json_path = 'chem_spectra.controller.spectra_layout_api.data_type_json_path'

def fetch_access_token(client):
response = client.post('/login')
response = client.post('/api/v1/chemspectra/login')
data = response.json
access_token = data.get('access_token')
return access_token
Expand Down

0 comments on commit 0712c30

Please sign in to comment.