summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Miric <imiric@gmail.com>2013-10-16 22:25:26 +0200
committerRaphaƫl Barrois <raphael.barrois@polyconseil.fr>2013-12-25 01:21:18 +0100
commit924d8a6ac279ca6ad560a3cf5efa1b141cedd253 (patch)
tree9b9eb975badef0e62967599a01b2aa335c66d9f4 /tests
parentb2c15880cc0bfe9a0c149ce3124813e95e8592b0 (diff)
downloadfactory-boy-924d8a6ac279ca6ad560a3cf5efa1b141cedd253.tar
factory-boy-924d8a6ac279ca6ad560a3cf5efa1b141cedd253.tar.gz
Added SubFactory support for MongoEngine's EmbeddedDocument
Diffstat (limited to 'tests')
-rw-r--r--tests/test_mongoengine.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/tests/test_mongoengine.py b/tests/test_mongoengine.py
index f26eb85..803607a 100644
--- a/tests/test_mongoengine.py
+++ b/tests/test_mongoengine.py
@@ -19,7 +19,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
-"""Tests for factory_boy/SQLAlchemy interactions."""
+"""Tests for factory_boy/MongoEngine interactions."""
import factory
import os
@@ -34,14 +34,23 @@ except ImportError:
if mongoengine:
from factory.mongoengine import MongoEngineFactory
+ class Address(mongoengine.EmbeddedDocument):
+ street = mongoengine.StringField()
+
class Person(mongoengine.Document):
name = mongoengine.StringField()
+ address = mongoengine.EmbeddedDocumentField(Address)
+
+ class AddressFactory(MongoEngineFactory):
+ FACTORY_FOR = Address
+
+ street = factory.Sequence(lambda n: 'street%d' % n)
class PersonFactory(MongoEngineFactory):
FACTORY_FOR = Person
name = factory.Sequence(lambda n: 'name%d' % n)
-
+ address = factory.SubFactory(AddressFactory)
@unittest.skipIf(mongoengine is None, "mongoengine not installed.")
@@ -65,11 +74,11 @@ class MongoEngineTestCase(unittest.TestCase):
def test_build(self):
std = PersonFactory.build()
self.assertEqual('name0', std.name)
+ self.assertEqual('street0', std.address.street)
self.assertIsNone(std.id)
def test_creation(self):
std1 = PersonFactory.create()
self.assertEqual('name1', std1.name)
+ self.assertEqual('street1', std1.address.street)
self.assertIsNotNone(std1.id)
-
-