foo.a_value = 30
foo.b_value = True
bar = Mock(spec=models.Bar)
bar._state = Mock()
foo.bar = bar
self.assertRaises(models.BadFooError, foo.full_clean)
How to use Mock library to mock a Django ForeignKey value?