11import datetime
22import uuid
33
4- import pymongo
5-
64from bson import BSON
75from bson .binary import JAVA_LEGACY
86from bson .codec_options import CodecOptions
97from bson .raw_bson import RawBSONDocument
10- from test import client_context , unittest , pair
8+ from test import client_context , unittest
119
1210
1311class TestRawBSONDocument (unittest .TestCase ):
@@ -22,9 +20,13 @@ class TestRawBSONDocument(unittest.TestCase):
2220 )
2321 document = RawBSONDocument (bson_string )
2422
23+ @classmethod
24+ def setUpClass (cls ):
25+ cls .client = client_context .rs_or_standalone_client
26+
2527 def tearDown (self ):
2628 if client_context .connected :
27- client_context .client .pymongo_test .test_raw .drop ()
29+ self .client .pymongo_test .test_raw .drop ()
2830
2931 def test_decode (self ):
3032 self .assertEqual ('Sherlock' , self .document ['name' ])
@@ -37,9 +39,11 @@ def test_raw(self):
3739
3840 @client_context .require_connection
3941 def test_round_trip (self ):
40- client = pymongo .MongoClient (pair , document_class = RawBSONDocument )
41- client .pymongo_test .test_raw .insert_one (self .document )
42- result = client .pymongo_test .test_raw .find_one (self .document ['_id' ])
42+ db = self .client .get_database (
43+ 'pymongo_test' ,
44+ codec_options = CodecOptions (document_class = RawBSONDocument ))
45+ db .test_raw .insert_one (self .document )
46+ result = db .test_raw .find_one (self .document ['_id' ])
4347 self .assertIsInstance (result , RawBSONDocument )
4448 self .assertEqual (dict (self .document .items ()), dict (result .items ()))
4549
@@ -65,7 +69,7 @@ def test_round_trip_codec_options(self):
6569 'date' : datetime .datetime (2015 , 6 , 3 , 18 , 40 , 50 , 826000 ),
6670 '_id' : uuid .UUID ('026fab8f-975f-4965-9fbf-85ad874c60ff' )
6771 }
68- db = pymongo . MongoClient ( pair ) .pymongo_test
72+ db = self . client .pymongo_test
6973 coll = db .get_collection (
7074 'test_raw' ,
7175 codec_options = CodecOptions (uuid_representation = JAVA_LEGACY ))
@@ -80,7 +84,7 @@ def test_round_trip_codec_options(self):
8084 @client_context .require_connection
8185 def test_raw_bson_document_embedded (self ):
8286 doc = {'embedded' : self .document }
83- db = client_context .client .pymongo_test
87+ db = self .client .pymongo_test
8488 db .test_raw .insert_one (doc )
8589 result = db .test_raw .find_one ()
8690 self .assertEqual (BSON (self .document .raw ).decode (), result ['embedded' ])
0 commit comments