def select_laboratory( self, client: TeselaGenClient, ) -> None: """A selected lab to work on.""" # available_labs = client.get_laboratories() # lab_id: int = available_labs[0]['id'] client.select_laboratory(lab_name="The Test Lab")
def discover_client( self, logged_client: TeselaGenClient, ) -> typing.Generator[DISCOVERClient, None, None]: """Get a logged in DISCOVER Client.""" # set up logged_client.select_laboratory(lab_name='The Test Lab') # yield yield logged_client.discover # tear down logged_client.logout()
def logged_build_client( self, lab_name: str, logged_client: TeselaGenClient, ) -> typing.Generator[BUILDClient, None, None]: """Get a logged in BUILD Client.""" # set up logged_client.select_laboratory(lab_name=lab_name) # yield yield logged_client.build # tear down # logged_client.logout() assert logged_client.headers == logged_client.build.headers
def test_login( self, client: TeselaGenClient, api_token_name: str, ): # Before login, the client has no tokens assert client.auth_token is None assert api_token_name not in client.headers.keys() # LOGIN expiration_time: str = '1d' client.login(expiration_time=expiration_time) # After login, the client has tokens assert isinstance(client.auth_token, str) assert api_token_name in client.headers.keys() assert isinstance(client.headers[api_token_name], str)
def test_get_api_info_deauthorized( self, client: TeselaGenClient, module_name: str, ) -> None: # The client should only be instantiated but not authorized. # with pytest.raises(AssertionError, match=r".*unauthorized.*"): api_info = client.get_api_info() assert 'unauthorized' in api_info.lower()
def test_get_server_status( self, client: TeselaGenClient, module_name: str, ) -> None: # We verify that the server is operational. server_status: str = client.get_server_status() expected_server_status: str = 'Teselagen CLI API is operational.' assert server_status == expected_server_status
def logged_client( self, client: TeselaGenClient, expiration_time: str, ) -> TeselaGenClient: """A logged TEST client instance. Returns: (TESTClient) : An instance of the TEST client. """ # Test will not run without a credential file credentials_filepath = get_credentials_path() assert credentials_filepath.is_file(), f"Can't found {credentials_filepath}" client.login( # username=credentials["test_user"], # passwd=credentials["test_password"], expiration_time=expiration_time) return client
def test_login( self, client: TeselaGenClient, expiration_time: str, api_token_name: str, ) -> None: # Before login, the client has no tokens assert client.auth_token is None assert api_token_name not in client.headers.keys() # LOGIN client.login( # username=credentials["test_user"], # passwd=credentials["test_password"], expiration_time=expiration_time) # After login, the client has tokens assert isinstance(client.auth_token, str) assert api_token_name in client.headers.keys() assert isinstance(client.headers[api_token_name], str)
def client( self, module_name: str, host_url: str, api_token_name: str, ) -> TeselaGenClient: """A TeslelaGenClient client instance. Returns: (TESTClient) : An instance of the TEST client. """ return TeselaGenClient( module_name=module_name, host_url=host_url, api_token_name=api_token_name, )
def client_with_lab( api_token_name: str, host_url: str, expiration_time: str, ) -> typing.Generator[TeselaGenClient, None, None]: """Defines a login and lab selection workflow with a "module" scope.""" # set up client = TeselaGenClient( api_token_name=api_token_name, host_url=host_url, module_name='test', ) client.login(expiration_time=expiration_time) client.select_laboratory(lab_name='The Test Lab') # yield yield client # tear down client.logout()
def test_login( self, client: TeselaGenClient, module_name: str, expiration_time: str, test_configuration, ) -> None: # LOGIN # We login the user with the CLI. client.login( # username=credentials['test_user'], # passwd=credentials['test_password'], expiration_time=expiration_time) # We verify the client is authorized. api_info = client.get_api_info() assert 'unauthorized' not in api_info.lower() # Now the token should be a string. assert isinstance(client.auth_token, str) # We verify that the API_TOKEN_NAME key has been added to the client headers assert test_configuration['api_token_name'] in client.headers.keys() assert isinstance(client.headers[test_configuration['api_token_name']], str) # We get the current user (auth) information current_user = client.get_current_user() assert isinstance(current_user['content']['username'], str) # LOGOUT # We logout the user from the CLI. client.logout( # username=credentials['test_user'], # password=credentials['test_password'] ) # We check the client is not authorized. api_info = client.get_api_info() assert 'unauthorized' in api_info.lower()