From ed2dcf48a95fde684d13906e630fe555fc6d47c0 Mon Sep 17 00:00:00 2001 From: Anthony Mahanna Date: Fri, 1 Sep 2023 13:23:30 -0400 Subject: [PATCH 1/2] initial commit --- arango/database.py | 19 ++++++++++++++++++- tests/test_database.py | 8 ++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arango/database.py b/arango/database.py index 875a04e0..dd5775fc 100644 --- a/arango/database.py +++ b/arango/database.py @@ -761,7 +761,7 @@ def response_handler(resp: Response) -> Json: ####################### def databases(self) -> Result[List[str]]: - """Return the names all databases. + """Return the names of all databases. :return: Database names. :rtype: [str] @@ -777,6 +777,23 @@ def response_handler(resp: Response) -> List[str]: return self._execute(request, response_handler) + def databases_accessible_to_user(self) -> Result[List[str]]: + """Return the names of all databases accessible by the user. + + :return: Database names accesible by the current user. + :rtype: List[str] + :raise arango.exceptions.DatabaseListError: If retrieval fails. + """ + request = Request(method="get", endpoint="/_api/database/user") + + def response_handler(resp: Response) -> List[str]: + if not resp.is_success: + raise DatabaseListError(resp, request) + result: List[str] = resp.body["result"] + return result + + return self._execute(request, response_handler) + def has_database(self, name: str) -> Result[bool]: """Check if a database exists. diff --git a/tests/test_database.py b/tests/test_database.py index 60685c0f..35e27f1b 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -247,10 +247,18 @@ def test_database_management(db, sys_db, bad_db): result = sys_db.databases() assert "_system" in result + # Test list databases accessible to user + result = db.databases_accessible_to_user() + assert result == [db.name] + # Test list databases with bad database with assert_raises(DatabaseListError): bad_db.databases() + # Test list accessible databases with bad database + with assert_raises(DatabaseListError): + bad_db.databases_accessible_to_user() + # Test create database db_name = generate_db_name() assert sys_db.has_database(db_name) is False From 96c0204087aee80f82934793881f0acbfed48b68 Mon Sep 17 00:00:00 2001 From: Anthony Mahanna Date: Fri, 1 Sep 2023 13:47:01 -0400 Subject: [PATCH 2/2] update: tests --- tests/test_database.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_database.py b/tests/test_database.py index 35e27f1b..cf06b814 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -246,6 +246,12 @@ def test_database_management(db, sys_db, bad_db): # Test list databases result = sys_db.databases() assert "_system" in result + assert db.name in result + + # Test list databases accesible to root user + result = sys_db.databases_accessible_to_user() + assert "_system" in result + assert db.name in result # Test list databases accessible to user result = db.databases_accessible_to_user()