From 83ff9aa4d6cd7f15f4d68ac9868f728a61adec35 Mon Sep 17 00:00:00 2001 From: Sebastian Lobinger <sebastian.lobinger@fu-berlin.de> Date: Wed, 7 Jun 2017 12:06:19 +0200 Subject: [PATCH] update sams_hub.py to pass test_token_passthrough fixed issue #6 --- sams_classes/sams_proxy.py | 9 ++++++++- test/test_sams_proxy.py | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sams_classes/sams_proxy.py b/sams_classes/sams_proxy.py index b78c9d2..0090327 100644 --- a/sams_classes/sams_proxy.py +++ b/sams_classes/sams_proxy.py @@ -38,6 +38,7 @@ class SAMSProxy: def _pass_param(self, method, paramType, paramDict = {}): paramDict.update(self._filter_session(method, paramType)) + paramDict.update(self._filter_token(paramType)) return paramDict def _filter_session(self, method, paramType): @@ -50,7 +51,13 @@ class SAMSProxy: filteredSession[filteredParams[param]['name']] = str(session.get(param)) return filteredSession - def _get_first_dict(self, *possibleDicts)->dict: + def _filter_token(self, paramType: str) -> dict: + if paramType == self._proxySpec.get('token', {}).get('param-type'): + return { + self._proxySpec['token']['name']: self._proxySpec['token']['value']} + return {} + + def _get_first_dict(self, *possibleDicts) -> dict: for possibleDict in possibleDicts: if isinstance(possibleDict, dict): return possibleDict diff --git a/test/test_sams_proxy.py b/test/test_sams_proxy.py index 737620a..8390ccf 100644 --- a/test/test_sams_proxy.py +++ b/test/test_sams_proxy.py @@ -205,7 +205,7 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase): proxySpec = { 'in': '/proxy', 'out': 'http://localhost:4711', 'token': { - 'name': 'api-token', 'value': '53CUR34P170K3N', + 'name': 'Api-Token', 'value': '53CUR34P170K3N', 'param-type': param_type } } @@ -222,4 +222,5 @@ class TestSAMSHubWithThreadedAPI(unittest.TestCase): self.assertEqual(resDict['url']['u'], 'foo') self.assertEqual(resDict['body']['g'], 'bar') self.assertEqual(resDict['header']['Lang'], 'klingon') - self.assertEquals(resDict[param_type]['api-token'], '53CUR34P170K3N') \ No newline at end of file + eprint(resDict[param_type]) + self.assertEquals(resDict[param_type]['Api-Token'], '53CUR34P170K3N') \ No newline at end of file -- GitLab