From 319f1deceb75499dc0c962a0fe8fdd7436f22894 Mon Sep 17 00:00:00 2001 From: Sridhar Sundarraman Date: Sun, 12 Apr 2015 17:28:26 +0300 Subject: [PATCH] Unit Test to Demonstrate #954 --- tests/document/validation.py | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/document/validation.py b/tests/document/validation.py index 573c2e57..646efddb 100644 --- a/tests/document/validation.py +++ b/tests/document/validation.py @@ -165,6 +165,48 @@ class ValidatorErrorTest(unittest.TestCase): self.assertRaises(ValidationError, lambda: d2.validate()) + def test_parent_reference_in_child_document(self): + """ Test to demonstrate behavior in Issue #954 + """ + class Parent(Document): + meta = {'allow_inheritance': True} + reference = ReferenceField('self') + + class Child(Parent): + pass + + parent = Parent() + parent.save() + + child = Child(reference=parent) + try: + # Saving child should not raise a ValidationError + child.save() + except ValidationError as e: + self.fail("test should not throw validation error. %s" % e.message) + + def test_parent_reference_set_as_attribute_in_child_document_(self): + """ Test to demonstrate behavior (when set as attribute) in Issue #954 + """ + class Parent(Document): + meta = {'allow_inheritance': True} + reference = ReferenceField('self') + + class Child(Parent): + pass + + parent = Parent() + parent.save() + + child = Child() + child.reference = parent + + try: + # Saving the child should not raise a ValidationError + child.save() + except ValidationError as e: + self.fail("test should not throw validation error. %s" % e.message) + if __name__ == '__main__': unittest.main()