def test_instantiation_from_bad_file(self): raw_data = """[catapult] user_id=file_uid secret=file_secret""" with open('.bndsdkrc', 'w+') as test_file: test_file.write(raw_data) self.assertTrue(test_file.closed) get_client()
def test_instantiation_partial_env(self): """ test client initialization where environ variables are only partially set """ with patch.dict('os.environ', {'BANDWIDTH_USER_ID': 'venv_uid', 'BANDWIDTH_API_TOKEN': 'venv_token', 'BANDWIDTH_API_SECRET': 'venv_secret'}): del(os.environ['BANDWIDTH_API_TOKEN']) get_client()
def test_instantiation_from_env(self): with patch.dict('os.environ', {'BANDWIDTH_USER_ID': 'venv_uid', 'BANDWIDTH_API_TOKEN': 'venv_token', 'BANDWIDTH_API_SECRET': 'venv_secret'}): rest_client = get_client() self.assertEqual(rest_client.uid, 'venv_uid') self.assertEqual(rest_client.auth, ('venv_token', 'venv_secret'))
def test_instantiation(self): """ Basic client installation. """ client = Client('u-user', 't-token', 's-secret') restored_client = get_client() self.assertIs(client, restored_client)
def test_instantiation_from_file_default_path(self): raw_data = """[catapult] user_id=file_uid token=file_token secret=file_secret""" with open('.bndsdkrc', 'w+') as test_file: test_file.write(raw_data) self.assertTrue(test_file.closed) rest_client = get_client() self.assertEqual(rest_client.uid, 'file_uid') self.assertEqual(rest_client.auth, ('file_token', 'file_secret')) os.remove('.bndsdkrc')
def test_instantiation_from_file_with_env_path(self): raw_data = """[catapult] user_id=file_uid token=file_token secret=file_secret""" with open('./tests/fixtures/.bndsdkrc', 'w+') as test_file: test_file.write(raw_data) self.assertTrue(test_file.closed) with patch.dict('os.environ', {'BANDWIDTH_CONFIG_FILE': './tests/fixtures/.bndsdkrc'}): rest_client = get_client() self.assertEqual(rest_client.uid, 'file_uid') self.assertEqual(rest_client.auth, ('file_token', 'file_secret')) os.remove('./tests/fixtures/.bndsdkrc')
def test_404_plain_text(self): """ Bad request in plain text """ raw = "Not Found" responses.add(responses.GET, 'https://api.catapult.inetwork.com/v1/users/u-user/calls/c-call-id', body=raw, status=404, content_type='text/plain') client = get_client() with self.assertRaises(AppPlatformError) as app_error: client.build_request('get', 'calls/c-call-id') self.assertEqual(str(app_error.exception), '404 client error: Not Found')
def test_404_json(self): """ Bad request with catapult reason in json """ raw = """ {"message": "Not Found"} """ responses.add(responses.GET, 'https://api.catapult.inetwork.com/v1/users/u-user/calls/c-call-id', body=raw, status=404, content_type='application/json') client = get_client() with self.assertRaises(AppPlatformError) as app_error: client.build_request('get', 'calls/c-call-id') self.assertEqual(str(app_error.exception), '404 client error: Not Found')
def home(): try: client = get_client() except: client = None values = (BRIDGE_CALLEE, CALLER, DOMAIN, client) if all(values): return 'This app is ready to use' wrap = lambda val: 'ok' if val else 'unconfigured' status = """Improperly configured CALLER: [{}] BRIDGE_CALLEE: [{}] DOMAIN: [{}] SDK: [{}] """.format(*[wrap(val) for val in values]) return status
def test_other_errors(self): """ Other errors """ raw = """ {"message": "Not Found"} """ responses.add(responses.GET, 'https://api.catapult.inetwork.com/v1/users/u-user/calls/c-call-id', body=raw, status=404, content_type='application/json') client = get_client() with self.assertRaises(AppPlatformError) as app_error: client.build_request('get', 'calls/c') self.assertEqual(str(app_error.exception), 'Connection refused: ' 'GET https://api.catapult.inetwork.com/v1/users/u-user/calls/c')
def test_instantiation_from_file_with_wrong_path(self): with patch.dict('os.environ', {'BANDWIDTH_CONFIG_FILE': './tests/fixtures/.bndsdkrc'}): with self.assertRaises(ValueError): get_client()
def test_instantiation_without_env(self): """ Basic client installation by get_client without configuration. """ with self.assertRaises(ValueError): get_client()
def test_instantiation_without_env(self): """ Basic client installation by get_client without configuration. """ get_client()