def test_exception_when_no_key(self): """should thrown an exception if the response does not have a value for the primary_key attribute""" adapter = SuccessAdapter() adapter.response.parsed = None bridge = ModelBridge(adapter) self.assertRaises(KeyError, bridge, **self.options)
def test_resets_caching(self): self.called_foo = False def foo(): self.called_foo = True caching.register(foo) ModelBridge(SuccessAdapter())(**self.options) self.assertEqual(self.called_foo, True)
def test_freeze(self): """should freeze the model on success""" ModelBridge(SuccessAdapter())(**self.options) self.assertEqual(self.model.frozen(), True)
def test_no_exception_without_read(self): """should not throw an exception if no read adapter is configured""" del self.model_class.reader adapter = SuccessAdapter() adapter.response.parsed = None ModelBridge(adapter)(**self.options)
def test_new_record_success(self): """should set the model's new_record attribute to false on success""" ModelBridge(SuccessAdapter())(**self.options) self.assertEqual(self.model.new_record, False)
def test_set_key(self): """should set the model's primary_key attribute on success""" ModelBridge(SuccessAdapter())(**self.options) self.assertEqual(self.model.id, 42)
def test_skip_reload(self): """should not reload the model if no read adapter is available""" del self.model_class.reader ModelBridge(SuccessAdapter())(**self.options) self.assertEqual(len(TestAdapter.calls), 0)
def test_reload_on_success(self): """should reload the model on success""" ModelBridge(SuccessAdapter())(**self.options) self.assertEqual(len(TestAdapter.calls), 1)
def test_saved_on_success(self): """should set model's saved attribute to true on success""" ModelBridge(SuccessAdapter())(**self.options) self.assertEqual(self.model.saved, True)