def test_token(openbis_instance): assert openbis_instance.hostname is not None new_instance = Openbis(openbis_instance.url) new_instance.login('admin', 'any_test_password') assert new_instance.token is not None assert new_instance.is_token_valid() is True new_instance.logout() assert new_instance.is_token_valid() is False invalid_connection = Openbis(openbis_instance.url) with pytest.raises(Exception): invalid_connection.login('invalid_username', 'invalid_password') assert invalid_connection.token is None assert invalid_connection.is_token_valid() is False
def test_cached_token(openbis_instance): openbis_instance.save_token() assert openbis_instance.token_path is not None assert openbis_instance.get_cached_token() is not None another_instance = Openbis(openbis_instance.url) assert another_instance.is_token_valid() is True openbis_instance.delete_token() assert openbis_instance.get_cached_token() is None
def open_connection(username, url): "creates connection to openbis and returns session object" s = Openbis(url=url, verify_certificates=True) if not username: username = input("Enter OpenBis Username:"******"Enter password for {}: ".format(username)) s.login(username, password) assert s.token is not None assert s.is_token_valid() is True return s