Skip to content

Instantly share code, notes, and snippets.

@jaraco
Last active July 26, 2016 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaraco/dddc5a70523dba9fc127162ca70e6c75 to your computer and use it in GitHub Desktop.
Save jaraco/dddc5a70523dba9fc127162ca70e6c75 to your computer and use it in GitHub Desktop.
Test attempting to replicate /whit537/mongs/issues/32
__requires__ = ['jaraco.mongodb', 'pymongo==3.2.2', 'pytest']
import pytest
import sys
import bson
def test_issue(mongodb_instance):
coll = mongodb_instance.get_connection()['test_db']['test_coll']
explicit_id = bson.ObjectId()
# insert id as string
id = coll.insert({'_id': str(explicit_id), 'foo': 'bar'})
assert isinstance(id, str)
constructed_id = bson.ObjectId(id)
assert explicit_id == constructed_id
doc = coll.find_one(str(id))
assert doc['foo'] == 'bar'
doc = coll.find_one(constructed_id)
assert doc is None
__name__ == '__main__' and pytest.main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment