PYTHON-783 Silence copy_database DeprecationWarnings in tests.

This commit is contained in:
A. Jesse Jiryu Davis 2014-12-20 23:16:30 -06:00
parent 31b83bc0e0
commit 61f526a2c5
3 changed files with 47 additions and 33 deletions

View File

@ -520,7 +520,9 @@ class TestClientAuth(unittest.TestCase):
c.drop_database("pymongo_test1")
c.pymongo_test.test.insert({"foo": "bar"})
ctx = catch_warnings()
try:
warnings.simplefilter("ignore", DeprecationWarning)
c.pymongo_test.add_user("mike", "password")
self.assertRaises(OperationFailure, c.copy_database,
@ -539,6 +541,7 @@ class TestClientAuth(unittest.TestCase):
self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
finally:
# Cleanup
ctx.exit()
remove_all_users(c.pymongo_test)
c.admin.remove_user("admin")
c.disconnect()

View File

@ -262,33 +262,38 @@ class TestClient(unittest.TestCase, TestRequestMixin):
if server_is_master_with_slave(c):
raise SkipTest("SERVER-2329")
self.assertRaises(TypeError, c.copy_database, 4, "foo")
self.assertRaises(TypeError, c.copy_database, "foo", 4)
self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")
ctx = catch_warnings()
try:
warnings.simplefilter("ignore", DeprecationWarning)
self.assertRaises(TypeError, c.copy_database, 4, "foo")
self.assertRaises(TypeError, c.copy_database, "foo", 4)
self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")
c.pymongo_test.test.drop()
c.pymongo_test.test.insert({"foo": "bar"})
c.pymongo_test.test.drop()
c.pymongo_test.test.insert({"foo": "bar"})
c.drop_database("pymongo_test1")
self.assertFalse("pymongo_test1" in c.database_names())
c.copy_database("pymongo_test", "pymongo_test1")
self.assertTrue("pymongo_test1" in c.database_names())
self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
c.drop_database("pymongo_test1")
# XXX - SERVER-15318
if not (version.at_least(c, (2, 6, 4)) and is_mongos(c)):
self.assertFalse(c.in_request())
c.copy_database("pymongo_test", "pymongo_test1",
"%s:%d" % (host, port))
# copy_database() didn't accidentally restart the request
self.assertFalse(c.in_request())
c.drop_database("pymongo_test1")
self.assertFalse("pymongo_test1" in c.database_names())
c.copy_database("pymongo_test", "pymongo_test1")
self.assertTrue("pymongo_test1" in c.database_names())
self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
c.drop_database("pymongo_test1")
c.drop_database("pymongo_test1")
# XXX - SERVER-15318
if not (version.at_least(c, (2, 6, 4)) and is_mongos(c)):
self.assertFalse(c.in_request())
c.copy_database("pymongo_test", "pymongo_test1",
"%s:%d" % (host, port))
# copy_database() didn't accidentally restart the request
self.assertFalse(c.in_request())
self.assertTrue("pymongo_test1" in c.database_names())
self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
c.drop_database("pymongo_test1")
finally:
ctx.exit()
def test_iteration(self):
client = MongoClient(host, port)

View File

@ -26,6 +26,7 @@ import thread
import threading
import traceback
import unittest
import warnings
sys.path[0:0] = [""]
@ -50,7 +51,7 @@ from test.pymongo_mocks import MockReplicaSetClient
from test.utils import (
delay, assertReadFrom, assertReadFromAll, read_from_which_host,
assertRaisesExactly, TestRequestMixin, one, pools_from_rs_client, get_pool,
_TestLazyConnectMixin, _TestExhaustCursorMixin)
_TestLazyConnectMixin, _TestExhaustCursorMixin, catch_warnings)
setUpModule = skip_restricted_localhost
@ -417,20 +418,25 @@ class TestReplicaSetClient(TestReplicaSetClientBase, TestRequestMixin):
def test_copy_db(self):
c = self._get_client()
self.assertRaises(TypeError, c.copy_database, 4, "foo")
self.assertRaises(TypeError, c.copy_database, "foo", 4)
self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")
ctx = catch_warnings()
try:
warnings.simplefilter("ignore", DeprecationWarning)
self.assertRaises(TypeError, c.copy_database, 4, "foo")
self.assertRaises(TypeError, c.copy_database, "foo", 4)
self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")
c.pymongo_test.test.drop()
c.pymongo_test.test.insert({"foo": "bar"})
c.pymongo_test.test.drop()
c.pymongo_test.test.insert({"foo": "bar"})
c.drop_database("pymongo_test1")
self.assertFalse("pymongo_test1" in c.database_names())
c.drop_database("pymongo_test1")
self.assertFalse("pymongo_test1" in c.database_names())
c.copy_database("pymongo_test", "pymongo_test1")
self.assertTrue("pymongo_test1" in c.database_names())
self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
c.drop_database("pymongo_test1")
c.copy_database("pymongo_test", "pymongo_test1")
self.assertTrue("pymongo_test1" in c.database_names())
self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
c.drop_database("pymongo_test1")
finally:
ctx.exit()
def test_get_default_database(self):
host = one(self.hosts)