Example #1
0
    def test_clean(self):
        class DummyContent(object):
            def content(self):
                return "content"

        f = ParentField(str)
        f.parent = DummyContent()

        assert f.clean("") == "content"
Example #2
0
 def test_clean_value(self):
     parenttype = mock.Mock(**{"objects.get.return_value":"explicit"})
     f = ParentField(parenttype)
     
     assert f.clean(42) == "explicit"
     assert parenttype.objects.get.call_args[1].get('pk') == 42
Example #3
0
 def test_clean_mistype(self):
     f = ParentField(str)
     f.parent = mock.MagicMock()
     with pytest.raises(forms.ValidationError):
         f.clean("")
Example #4
0
 def test_clean_noparent(self):
     something = mock.Mock()
     f = ParentField(something)
     with pytest.raises(forms.ValidationError):
         f.clean("")