Skip to content

Commit cbf4b77

Browse files
author
Luke Lovett
committed
PYTHON-472 - Fix raw BSON tests when run with authentication.
1 parent 733079b commit cbf4b77

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

test/test_raw_bson.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import datetime
22
import uuid
33

4-
import pymongo
5-
64
from bson import BSON
75
from bson.binary import JAVA_LEGACY
86
from bson.codec_options import CodecOptions
97
from bson.raw_bson import RawBSONDocument
10-
from test import client_context, unittest, pair
8+
from test import client_context, unittest
119

1210

1311
class 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

Comments
 (0)