Fix last issue with binary field as primary key and skipped new test
This commit is contained in:
parent
3421fffa9b
commit
571a7dc42d
@ -312,8 +312,9 @@ class Document(BaseDocument):
|
|||||||
# In PyMongo 3.0, the save() call calls internally the _update() call
|
# In PyMongo 3.0, the save() call calls internally the _update() call
|
||||||
# but they forget to return the _id value passed back, therefore getting it back here
|
# but they forget to return the _id value passed back, therefore getting it back here
|
||||||
if not object_id and pymongo.version_tuple == (3, 0):
|
if not object_id and pymongo.version_tuple == (3, 0):
|
||||||
object_id = self._qs.filter(**self._object_key).first() and \
|
pk_as_mongo_obj = self._fields.get(self._meta['id_field']).to_mongo(self.pk)
|
||||||
self._qs.filter(**self._object_key).first().pk
|
object_id = self._qs.filter(pk=pk_as_mongo_obj).first() and \
|
||||||
|
self._qs.filter(pk=pk_as_mongo_obj).first().pk
|
||||||
else:
|
else:
|
||||||
object_id = doc['_id']
|
object_id = doc['_id']
|
||||||
updates, removals = self._delta()
|
updates, removals = self._delta()
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys
|
import sys
|
||||||
|
from nose.plugins.skip import SkipTest
|
||||||
|
|
||||||
sys.path[0:0] = [""]
|
sys.path[0:0] = [""]
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
@ -2491,8 +2493,25 @@ class FieldTest(unittest.TestCase):
|
|||||||
binary_id = uuid.uuid4().bytes
|
binary_id = uuid.uuid4().bytes
|
||||||
att = Attachment(id=binary_id).save()
|
att = Attachment(id=binary_id).save()
|
||||||
self.assertEqual(1, Attachment.objects.count())
|
self.assertEqual(1, Attachment.objects.count())
|
||||||
|
self.assertEqual(1, Attachment.objects.filter(id=att.id).count())
|
||||||
# TODO use assertIsNotNone once Python 2.6 support is dropped
|
# TODO use assertIsNotNone once Python 2.6 support is dropped
|
||||||
self.assertFalse(Attachment.objects.filter(id=binary_id).first() is not None)
|
self.assertTrue(Attachment.objects.filter(id=att.id).first() is not None)
|
||||||
|
att.delete()
|
||||||
|
self.assertEqual(0, Attachment.objects.count())
|
||||||
|
|
||||||
|
def test_binary_field_primary_filter_by_binary_pk_as_str(self):
|
||||||
|
|
||||||
|
raise SkipTest("Querying by id as string is not currently supported")
|
||||||
|
|
||||||
|
class Attachment(Document):
|
||||||
|
id = BinaryField(primary_key=True)
|
||||||
|
|
||||||
|
Attachment.drop_collection()
|
||||||
|
binary_id = uuid.uuid4().bytes
|
||||||
|
att = Attachment(id=binary_id).save()
|
||||||
|
self.assertEqual(1, Attachment.objects.filter(id=binary_id).count())
|
||||||
|
# TODO use assertIsNotNone once Python 2.6 support is dropped
|
||||||
|
self.assertTrue(Attachment.objects.filter(id=binary_id).first() is not None)
|
||||||
att.delete()
|
att.delete()
|
||||||
self.assertEqual(0, Attachment.objects.count())
|
self.assertEqual(0, Attachment.objects.count())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user