Skip to content

Commit

Permalink
PYTHON-472 - Fix raw BSON tests when run with authentication.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Lovett committed Nov 19, 2015
1 parent 733079b commit cbf4b77
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions test/test_raw_bson.py
@@ -1,13 +1,11 @@
import datetime
import uuid

import pymongo

from bson import BSON
from bson.binary import JAVA_LEGACY
from bson.codec_options import CodecOptions
from bson.raw_bson import RawBSONDocument
from test import client_context, unittest, pair
from test import client_context, unittest


class TestRawBSONDocument(unittest.TestCase):
Expand All @@ -22,9 +20,13 @@ class TestRawBSONDocument(unittest.TestCase):
)
document = RawBSONDocument(bson_string)

@classmethod
def setUpClass(cls):
cls.client = client_context.rs_or_standalone_client

def tearDown(self):
if client_context.connected:
client_context.client.pymongo_test.test_raw.drop()
self.client.pymongo_test.test_raw.drop()

def test_decode(self):
self.assertEqual('Sherlock', self.document['name'])
Expand All @@ -37,9 +39,11 @@ def test_raw(self):

@client_context.require_connection
def test_round_trip(self):
client = pymongo.MongoClient(pair, document_class=RawBSONDocument)
client.pymongo_test.test_raw.insert_one(self.document)
result = client.pymongo_test.test_raw.find_one(self.document['_id'])
db = self.client.get_database(
'pymongo_test',
codec_options=CodecOptions(document_class=RawBSONDocument))
db.test_raw.insert_one(self.document)
result = db.test_raw.find_one(self.document['_id'])
self.assertIsInstance(result, RawBSONDocument)
self.assertEqual(dict(self.document.items()), dict(result.items()))

Expand All @@ -65,7 +69,7 @@ def test_round_trip_codec_options(self):
'date': datetime.datetime(2015, 6, 3, 18, 40, 50, 826000),
'_id': uuid.UUID('026fab8f-975f-4965-9fbf-85ad874c60ff')
}
db = pymongo.MongoClient(pair).pymongo_test
db = self.client.pymongo_test
coll = db.get_collection(
'test_raw',
codec_options=CodecOptions(uuid_representation=JAVA_LEGACY))
Expand All @@ -80,7 +84,7 @@ def test_round_trip_codec_options(self):
@client_context.require_connection
def test_raw_bson_document_embedded(self):
doc = {'embedded': self.document}
db = client_context.client.pymongo_test
db = self.client.pymongo_test
db.test_raw.insert_one(doc)
result = db.test_raw.find_one()
self.assertEqual(BSON(self.document.raw).decode(), result['embedded'])
Expand Down

0 comments on commit cbf4b77

Please sign in to comment.