Skip to content

Commit

Permalink
Merge pull request #27 from NHS-NGS/pyCIPAPI_client
Browse files Browse the repository at this point in the history
Update live 100K URL
  • Loading branch information
andyb3 authored Apr 15, 2020
2 parents ed9c25a + bcee0fb commit 7bb91f8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyCIPAPI/jellypy/pyCIPAPI/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def authenticate_ad(self, testing_on=False):
self.auth_expires = datetime.fromtimestamp(int(auth_response['expires_on']))
except KeyError:
self.auth_time = False
raise Exception('Authentication Error')
raise Exception(f'Authentication Error: {auth_response}')
except:
raise

Expand Down
2 changes: 1 addition & 1 deletion pyCIPAPI/jellypy/pyCIPAPI/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
beta_testing_auth_url = 'https://login.microsoftonline.com/99515578-fda0-444c-8f5a-2005038880f2/oauth2/token'

# CIP-API base URLs for live data and beta testing:
live_100k_data_base_url = 'https://cipapi.gel.zone/api/2/'
live_100k_data_base_url = 'https://cipapi.genomicsengland.nhs.uk/api/2/'
beta_testing_base_url = 'https://cipapi-beta.genomicsengland.co.uk/api/2/'
2 changes: 1 addition & 1 deletion pyCIPAPI/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='jellypy_pyCIPAPI',
version='0.2.2',
version='0.2.3',
author="NHS Bioinformatics Group",
author_email="[email protected]",
description='Python client library the Genomics England CIPAPI',
Expand Down
49 changes: 34 additions & 15 deletions pyCIPAPI/test/test_pyCIPAPI.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@

"""
Tests for jellypy-pyCIPAPI package
Tests for jellypy-pyCIPAPI package.
Ensure you have installed jellypy-pyCIPAPI from the repository:
$ pip install ./pyCIPAPI
Usage:
pytest tierup/test/test_requests.py --jpconfig=tierup/test/config.ini
pytest pyCIPAPI/test/test_pyCIPAPI.py --jpconfig=config.ini
Example config.ini format:
[pyCIPAPI]
client_id = YOUR_CLIENT_ID
client_secret = YOUR_CLIENT_SECRET
test_irid = VALID_INTERPRETATION_REQUEST_ID
test_irversion = VALID_INTERPRETATION_REQUEST_VERSION
"""
import pytest

Expand All @@ -13,29 +23,38 @@


def test_import():
"""Objects in pyCIPAPI modules can be imported from the jellypy namespace."""
"""Test jellypy-pyCIPAPI is installed and objects can be imported."""
assert bool(config.live_100k_data_base_url)

def test_config(jpconfig):
"""A jellypy config.ini file has been parsed by pytest"""
"""Test that a valid config.ini file has been parsed by pytest"""
assert jpconfig is not None, \
"ERROR: Jellypy tests require config file. Please pass --jpconfig <yourfile.ini>"
try:
assert bool(jpconfig['pyCIPAPI']['username'])
assert bool(jpconfig['pyCIPAPI']['password'])
assert bool(jpconfig['pyCIPAPI']['client_id'])
assert bool(jpconfig['pyCIPAPI']['client_secret'])
except KeyError:
raise ValueError("ERROR: Could not read expected key from jpconfig. See example in docs.")

def test_get_irjson(jpconfig):
"""Interpretation requests json files can be downloaded from the CIPAPI"""
irid = jpconfig.get('pyCIPAPI', 'test_irid')
irversion = jpconfig.get('pyCIPAPI', 'test_irversion')
@pytest.fixture()
def authenticated_session(jpconfig):
"""Create authenticated CIPAPI session using config details"""
session = auth.AuthenticatedCIPAPISession(
auth_credentials={
'username': jpconfig.get('pyCIPAPI', 'username'),
'password': jpconfig.get('pyCIPAPI', 'password')
'client_id': jpconfig.get('pyCIPAPI', 'client_id'),
'client_secret': jpconfig.get('pyCIPAPI', 'client_secret')
}
)
# Attempt to get a known interpretation request. This can be changed in the test config.
data = irs.get_interpretation_request_json(irid, irversion, reports_v6=True, session=session)
assert isinstance(data, dict)
return session

def test_authentication(authenticated_session):
"""Assert session fixture creates an authentaicated session from active directory login."""
assert authenticated_session.headers['Authorization']

def test_get_irjson(jpconfig, authenticated_session):
"""Test that the interpretation request in config can be pulled from the CIPAPI"""
irid = jpconfig.get('pyCIPAPI', 'test_irid')
irversion = jpconfig.get('pyCIPAPI', 'test_irversion')
"""Interpretation request data can be downloaded from the CIPAPI with an authenticated session"""
data = irs.get_interpretation_request_json(irid, irversion, reports_v6=True, session=authenticated_session)
assert 'interpretation_request_id' in data.keys()
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ To develop a new function or feature, please take a look at the issues raised. I
* 0.2.0 - Update pyCIPAPI to work with GeL client token/secret GMS authentication
* 0.2.1 - Support legacy authentication by allowing AD to be toggled on/off in config file
* 0.2.2 - Add sub-heading to README changelog
* 0.2.3 - Update live 100K url. Display response on API errors. Add tests for auth api calls.

0 comments on commit 7bb91f8

Please sign in to comment.