MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / test_list_databases

Method test_list_databases

test/test_client.py:1008–1031  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1006 wait_until(lambda: client_context.nodes == self.client.nodes, "find all nodes")
1007
1008 def test_list_databases(self):
1009 cmd_docs = (self.client.admin.command("listDatabases"))["databases"]
1010 cursor = self.client.list_databases()
1011 self.assertIsInstance(cursor, CommandCursor)
1012 helper_docs = cursor.to_list()
1013 self.assertGreater(len(helper_docs), 0)
1014 self.assertEqual(len(helper_docs), len(cmd_docs))
1015 # PYTHON-3529 Some fields may change between calls, just compare names.
1016 for helper_doc, cmd_doc in zip(helper_docs, cmd_docs):
1017 self.assertIs(type(helper_doc), dict)
1018 self.assertEqual(helper_doc.keys(), cmd_doc.keys())
1019 client = self.rs_or_single_client(document_class=SON)
1020 for doc in client.list_databases():
1021 self.assertIs(type(doc), dict)
1022
1023 self.client.pymongo_test.test.insert_one({})
1024 cursor = self.client.list_databases(filter={"name": "admin"})
1025 docs = cursor.to_list()
1026 self.assertEqual(1, len(docs))
1027 self.assertEqual(docs[0]["name"], "admin")
1028
1029 cursor = self.client.list_databases(nameOnly=True)
1030 for doc in cursor:
1031 self.assertEqual(["name"], list(doc))
1032
1033 def test_list_database_names(self):
1034 self.client.pymongo_test.test.insert_one({"dummy": "object"})

Callers

nothing calls this directly

Calls 6

keysMethod · 0.80
rs_or_single_clientMethod · 0.80
commandMethod · 0.45
list_databasesMethod · 0.45
to_listMethod · 0.45
insert_oneMethod · 0.45

Tested by

no test coverage detected