def list_farms(): """ List all farms you can manage. If you have selected a farm already, the name of that farm will be prefixed with an asterisk in the returned list. """ utils.check_for_cloud_server() utils.check_for_cloud_user() server = Server(config["cloud_server"]["url"]) server.log_in(config["cloud_server"]["username"], config["cloud_server"]["password"]) farms_list = server.get_user_info().get("farms", []) if not len(farms_list): raise click.ClickException( "No farms exist. Run `openag cloud create_farm` to create one") active_farm_name = config["cloud_server"]["farm_name"] for farm_name in farms_list: if farm_name == active_farm_name: click.echo("*" + farm_name) else: click.echo(farm_name)
def list_farms(): """ List all farms you can manage. If you have selected a farm already, the name of that farm will be prefixed with an asterisk in the returned list. """ utils.check_for_cloud_server() utils.check_for_cloud_user() server = Server(config["cloud_server"]["url"]) server.log_in( config["cloud_server"]["username"], config["cloud_server"]["password"] ) farms_list = server.get_user_info().get("farms", []) if not len(farms_list): raise click.ClickException( "No farms exist. Run `openag cloud create_farm` to create one" ) active_farm_name = config["cloud_server"]["farm_name"] for farm_name in farms_list: if farm_name == active_farm_name: click.echo("*"+farm_name) else: click.echo(farm_name)
def test_get_user_info(): server = Server("http://test.test:5984") # Try to get user info -- Should fail try: server.get_user_info() assert False, "Server.get_user_info should fail when not logged in" except RuntimeError as e: pass def on_get_session(request, uri, headers): credentials = request.headers.getheader("Authorization") if credentials.startswith("Basic "): username, password = b64decode(credentials[6:]).split(":") if username == "test" and password == "test": return 200, headers, '{"test": "test"}' return 401, headers, '{"test": "test"}' httpretty.register_uri(httpretty.GET, "http://test.test:5984/_session", body=on_get_session, content_type="application/json") server.log_in("test", "test") httpretty.register_uri(httpretty.HEAD, "http://test.test:5984/_users") httpretty.register_uri( httpretty.GET, "http://test.test:5984/_users/org.couchdb.user%3Atest", body='{"test": "test"}', content_type="application/json") res = server.get_user_info() assert server.get_user_info() == {"test": "test"} server.log_out() try: server.get_user_info() assert False, "Shouldn't be able to access the user's info when not logged in" except RuntimeError: pass
def test_get_user_info(): server = Server("http://test.test:5984") # Try to get user info -- Should fail try: server.get_user_info() assert False, "Server.get_user_info should fail when not logged in" except RuntimeError as e: pass def on_get_session(request, uri, headers): credentials = request.headers.getheader("Authorization") if credentials.startswith("Basic "): username, password = b64decode(credentials[6:]).split(":") if username == "test" and password == "test": return 200, headers, '{"test": "test"}' return 401, headers, '{"test": "test"}' httpretty.register_uri( httpretty.GET, "http://test.test:5984/_session", body=on_get_session, content_type="application/json" ) server.log_in("test", "test") httpretty.register_uri( httpretty.HEAD, "http://test.test:5984/_users" ) httpretty.register_uri( httpretty.GET, "http://test.test:5984/_users/org.couchdb.user%3Atest", body='{"test": "test"}', content_type="application/json" ) res = server.get_user_info() assert server.get_user_info() == {"test": "test"} server.log_out() try: server.get_user_info() assert False, "Shouldn't be able to access the user's info when not logged in" except RuntimeError: pass