def test_post_save_unchanged(self): with must_be_called(False) as func: post_save_changed.connect(func, sender=FakeModel) obj = FakeModel() post_init.send(instance=obj, sender=FakeModel) # This *doesn't* call post_save_changed, because we haven't changed anything. post_save.send(instance=obj, sender=FakeModel)
def test_post_save_with_fields_unchanged(self): with must_be_called(False) as func: post_save_changed.connect(func, sender=FakeModel, fields=('a_key',)) obj = FakeModel() post_init.send(instance=obj, sender=FakeModel) obj.another = 'dont care about this field' post_save.send(instance=obj, sender=FakeModel)
def test_post_save_with_fields_changed(self): with must_be_called(True) as func: post_save_changed.connect(func, sender=FakeModel, fields=('a_key',)) obj = FakeModel() post_init.send(instance=obj, sender=FakeModel) obj.a_key = 'change a field that we care about' post_save.send(instance=obj, sender=FakeModel)
def test_post_save_changed(self): with must_be_called(True) as func: post_save_changed.connect(func, sender=FakeModel) obj = FakeModel() post_init.send(instance=obj, sender=FakeModel) obj.a_key = 'another value' post_save.send(instance=obj, sender=FakeModel)
def test_post_save_changed(self): with must_be_called(True) as func: post_save_changed.connect(func, sender=FakeModel) obj = FakeModel() post_init.send(instance=obj, sender=FakeModel) obj.a_key = "another value" post_save.send(instance=obj, sender=FakeModel) assert func.kwargs["changed_fields"] == { "a_key": ("a value", "another value") }
def test_post_save_with_fields_changed(self): with must_be_called(True) as func: post_save_changed.connect(func, sender=FakeModel, fields=("a_key", )) obj = FakeModel() post_init.send(instance=obj, sender=FakeModel) obj.a_key = "change a field that we care about" post_save.send(instance=obj, sender=FakeModel) assert func.kwargs["changed_fields"] == { "a_key": ("a value", "change a field that we care about") }
def test_m2m_fields_error(self): with must_be_called(False) as func: with self.assertRaises(ValueError): post_save_changed.connect(func, sender=FakeModel, fields=('m2m',))
def test_app_cache_not_ready(self): apps.models_ready = False with self.assertRaisesRegexp(AppRegistryNotReady, r"django-fieldsignals signals.*"): post_save_changed.connect(func, sender=FakeModel)
def test_one_to_one_rel_field_error(self): with must_be_called(False) as func: with pytest.raises(ValueError): post_save_changed.connect(func, sender=FakeModelWithOneToOne, fields=("o2o", "f"))
def test_one_to_one_rel_excluded(self): with must_be_called(False) as func: post_save_changed.connect(func, sender=FakeModelWithOneToOne)
def test_one_to_one_rel_field_error(self): with must_be_called(False) as func: with self.assertRaises(ValueError): post_save_changed.connect(func, sender=FakeModelWithOneToOne, fields=('o2o', 'f'))
def test_m2m_fields_error(self): with must_be_called(False) as func: with self.assertRaises(ValueError): post_save_changed.connect(func, sender=FakeModel, fields=('m2m', ))
def test_app_cache_not_ready(self): apps.models_ready = False with pytest.raises(AppRegistryNotReady): post_save_changed.connect(func, sender=FakeModel)
def test_m2m_fields_error(self): with must_be_called(False) as func: with pytest.raises(ValueError): post_save_changed.connect(func, sender=FakeModel, fields=("m2m", ))