예제 #1
0
    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()
예제 #2
0
 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()
예제 #3
0
 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'))
예제 #4
0
 def test_instantiation(self):
     """
     Basic client installation.
     """
     client = Client('u-user', 't-token', 's-secret')
     restored_client = get_client()
     self.assertIs(client, restored_client)
예제 #5
0
    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')
예제 #6
0
    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')
예제 #7
0
    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')
예제 #8
0
    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
예제 #10
0
    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')
예제 #11
0
 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()
예제 #12
0
 def test_instantiation_without_env(self):
     """
     Basic client installation by get_client without configuration.
     """
     with self.assertRaises(ValueError):
         get_client()
예제 #13
0
 def test_instantiation_without_env(self):
     """
     Basic client installation by get_client without configuration.
     """
     get_client()