2525
2626from bson .objectid import ObjectId
2727from bson .son import SON
28+ from pymongo .connection import Connection
2829from pymongo .mongo_client import MongoClient
2930from pymongo .mongo_replica_set_client import MongoReplicaSetClient
3031from pymongo .errors import ConfigurationError , OperationFailure
@@ -56,6 +57,39 @@ def test_baseobject(self):
5657
5758 warnings .simplefilter ("ignore" )
5859
60+ # Connection tests
61+ c = Connection (pair )
62+ self .assertFalse (c .slave_okay )
63+ self .assertFalse (c .safe )
64+ self .assertEqual ({}, c .get_lasterror_options ())
65+ db = c .pymongo_test
66+ db .drop_collection ("test" )
67+ self .assertFalse (db .slave_okay )
68+ self .assertFalse (db .safe )
69+ self .assertEqual ({}, db .get_lasterror_options ())
70+ coll = db .test
71+ self .assertFalse (coll .slave_okay )
72+ self .assertFalse (coll .safe )
73+ self .assertEqual ({}, coll .get_lasterror_options ())
74+
75+ self .assertEqual ((False , {}), coll ._get_write_mode ())
76+ coll .safe = False
77+ coll .write_concern .update (w = 1 )
78+ self .assertEqual ((True , {}), coll ._get_write_mode ())
79+ coll .write_concern .update (w = 3 )
80+ self .assertEqual ((True , {'w' : 3 }), coll ._get_write_mode ())
81+
82+ coll .safe = True
83+ coll .write_concern .update (w = 0 )
84+ self .assertEqual ((False , {}), coll ._get_write_mode ())
85+
86+ coll = db .test
87+ cursor = coll .find ()
88+ self .assertFalse (cursor ._Cursor__slave_okay )
89+ cursor = coll .find (slave_okay = True )
90+ self .assertTrue (cursor ._Cursor__slave_okay )
91+
92+ # MongoClient test
5993 c = MongoClient (pair )
6094 self .assertFalse (c .slave_okay )
6195 self .assertTrue (c .safe )
@@ -69,6 +103,19 @@ def test_baseobject(self):
69103 self .assertFalse (coll .slave_okay )
70104 self .assertTrue (coll .safe )
71105 self .assertEqual ({}, coll .get_lasterror_options ())
106+
107+ self .assertEqual ((True , {}), coll ._get_write_mode ())
108+ coll .safe = False
109+ coll .write_concern .update (w = 1 )
110+ self .assertEqual ((True , {}), coll ._get_write_mode ())
111+ coll .write_concern .update (w = 3 )
112+ self .assertEqual ((True , {'w' : 3 }), coll ._get_write_mode ())
113+
114+ coll .safe = True
115+ coll .write_concern .update (w = 0 )
116+ self .assertEqual ((False , {}), coll ._get_write_mode ())
117+
118+ coll = db .test
72119 cursor = coll .find ()
73120 self .assertFalse (cursor ._Cursor__slave_okay )
74121 cursor = coll .find (slave_okay = True )
0 commit comments