Skip to content

Commit

Permalink
Added a failing test to reproduce issue #47.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashaag committed Jun 6, 2011
1 parent 1341801 commit e69f95e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/mongodb/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from djangotoolbox.fields import RawField
from djangotoolbox.fields import RawField, ListField, EmbeddedModelField
from django_mongodb_engine.fields import GridFSField, GridFSString
from query.models import Post

class DescendingIndexModel(models.Model):
desc = models.IntegerField()
Expand Down Expand Up @@ -46,5 +47,8 @@ class GridFSFieldTestModel(models.Model):
gridstring = GridFSString()


class Issue47Model(models.Model):
foo = ListField(EmbeddedModelField(Post))

RawModel.objects.all().delete()
RawModel.objects.create(raw=42)
12 changes: 12 additions & 0 deletions tests/mongodb/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ def test_databasewrapper_api(self):
for call in calls:
call()

class RegressionTests(TestCase):
def test_issue_47(self):
""" ForeignKeys in subobjects should be ObjectIds, not unicode """
from bson.objectid import ObjectId
from query.models import Blog, Post
post = Post.objects.create(blog=Blog.objects.create())
m = Issue47Model.objects.create(foo=[post])
collection = get_collection(Issue47Model)
assert collection.count() == 1
doc = collection.find_one()
self.assertIsInstance(doc['foo'][0]['blog_id'], ObjectId)

class DatabaseOptionTests(TestCase):
""" Tests for MongoDB-specific database options """

Expand Down

0 comments on commit e69f95e

Please sign in to comment.