Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 def test_freeze(self):
     """should freeze the model on success"""
     ModelBridge(SuccessAdapter())(**self.options)
     self.assertEqual(self.model.frozen(), True)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 def test_reload_on_success(self):
     """should reload the model on success"""
     ModelBridge(SuccessAdapter())(**self.options)
     self.assertEqual(len(TestAdapter.calls), 1)
Ejemplo n.º 9
0
 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)