def rest_client(api_info):
    rest_client = tetration.RestClient(
        api_info['endpoint'],
        api_key=api_info['api_key'],
        api_secret=api_info['api_secret'],
        verify=True)

    yield rest_client
    def test_rest_client_get_users(self, api_info):
        endpoint = api_info['endpoint']
        api_key = api_info['api_key']
        api_secret = api_info['api_secret']

        rest_client = tetration.RestClient(
            endpoint, api_key=api_key, api_secret=api_secret, verify=True)
        resp = rest_client.get(tetration_constants.TETRATION_API_USER)

        assert isinstance(resp.json(), list)
        assert resp.status_code == 200
        assert "openapi/v1/users" in str(resp.url)
    def test_read_invalid_credentials_file_missing_key(self, api_info, tmp_path):
        endpoint = api_info['endpoint']

        data = {}

        d = tmp_path
        p = d / "test_creds.json"
        p.write_text(json.dumps(data))
        cred_file = str(p)
        with pytest.raises(KeyError) as e:
            tetration.RestClient(
                endpoint, credentials_file=cred_file, verify=True)
        assert "api_key missing" in str(e.value)
    def test_api_secret_is_empty(self, api_info, tmp_path):
        endpoint = api_info['endpoint']

        data = {
            'api_key': 'fakekey',
            'api_secret': ''
        }

        d = tmp_path
        p = d / "test_creds.json"
        p.write_text(json.dumps(data))
        cred_file = str(p)
        rest_client = tetration.RestClient(
            endpoint, credentials_file=cred_file, verify=True)
        resp = rest_client.get(tetration_constants.TETRATION_API_USER)

        assert resp is None
    def test_rest_client_load_from_credentials_file(self, tmp_path, api_info):
        endpoint = api_info['endpoint']

        data = {
            'api_key': api_info['api_key'],
            'api_secret': api_info['api_secret']
        }

        d = tmp_path
        p = d / "test_creds.json"
        p.write_text(json.dumps(data))
        cred_file = str(p)

        rest_client = tetration.RestClient(
            endpoint, credentials_file=cred_file, verify=True)
        resp = rest_client.get(tetration_constants.TETRATION_API_USER)

        assert isinstance(resp.json(), list)
        assert resp.status_code == 200
        assert "openapi/v1/users" in str(resp.url)
 def test_create_class_instance(self):
     server_endpoint = "https://www.google.com"
     rest_client_obj = tetration.RestClient
     obj = tetration.RestClient(server_endpoint)
     assert isinstance(obj, rest_client_obj)