Exemple #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)
Exemple #2
0
 def test_always_errors_on_fail(self):
     """should add error messages to the model even if the response has no
     errors"""
     adapter = FailureAdapter()
     adapter.response.parsed = None
     ModelBridge(adapter)(**self.options)
     self.assertEqual(self.model.errors, { 'base': 'record not saved' })
Exemple #3
0
 def test_add_default_errors(self):
     """should add a default error message to the model on failure even when
     the response has no error messages"""
     adapter = FailureAdapter()
     adapter.response.parsed = None
     ModelBridge(adapter)(**self.options)
     self.assertEqual(self.model.errors, { 'base': 'record not deleted' })
Exemple #4
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)
Exemple #5
0
    def setUp(self):
        class FakeAdapter(object):
            def __init__(self):
                self.called = False
                self.args = None
                self.return_value = [{ 'id': 1 }]

            def __call__(self, **kwargs):
                self.called = True
                self.args = kwargs
                return self.return_value

        self.adapter = FakeAdapter()
        self.bridge = ModelBridge(self.adapter, {})
        self.relation = Test.scoped()
        self.stack_opts = { 'relation': self.relation, 'mode': 'read' }
Exemple #6
0
 def test_new_record_fail(self):
     """should keep the model's new_record attribute as true on failure"""
     ModelBridge(FailureAdapter())(**self.options)
     self.assertEqual(self.model.new_record, True)
Exemple #7
0
 def test_saved_on_fail(self):
     """should set model's saved attribute to false on failure"""
     ModelBridge(FailureAdapter())(**self.options)
     self.assertEqual(self.model.saved, False)
Exemple #8
0
 def test_optional_params(self):
     """should take optional configuration options"""
     mb = ModelBridge('foo', { 'bar': 'baz' })
     self.assertEqual(mb.options, { 'bar': 'baz' })
Exemple #9
0
 def test_not_freeze_on_fail(self):
     """should not freeze the model on failure"""
     ModelBridge(FailureAdapter())(**self.options)
     self.assertEqual(self.model.frozen(), False)
Exemple #10
0
 def test_add_errors(self):
     """should add error messages to the model on failure"""
     adapter = FailureAdapter()
     adapter.response.parsed = { 'errors': { 'base': 'record not found' } }
     ModelBridge(adapter)(**self.options)
     self.assertEqual(self.model.errors, { 'base': 'record not found' })
Exemple #11
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)
Exemple #12
0
 def test_freeze(self):
     """should freeze the model on success"""
     ModelBridge(SuccessAdapter())(**self.options)
     self.assertEqual(self.model.frozen(), True)
Exemple #13
0
 def test_reload_on_success(self):
     """should reload the model on success"""
     ModelBridge(SuccessAdapter())(**self.options)
     self.assertEqual(len(TestAdapter.calls), 1)
Exemple #14
0
 def test_params(self):
     """should take an argument for next item in the call stack"""
     mb = ModelBridge('foo')
     self.assertEqual(mb.next, 'foo')
Exemple #15
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)
Exemple #16
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)
Exemple #17
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)
Exemple #18
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)
Exemple #19
0
 def test_reload_on_fail(self):
     """should not reload the model on failure"""
     ModelBridge(FailureAdapter())(**self.options)
     self.assertEqual(len(TestAdapter.calls), 0)