Commit f131bbb3 authored by Jérome Perrin's avatar Jérome Perrin

ERP5Type: make sure we can use mock in tests

In ERP5 software release we now have `mock` egg installed, so we can use it in tests instead of doing manually like this:

```python
saved_method = Class.method
def patched_method():
  ...
try:
   Class.method = patched_method
   ...
finally:
   Class.method = saved_method
```

/reviewed-on !882
parent 7c4f1757
......@@ -32,6 +32,7 @@ except ImportError: # BBB: ZODB < 4
import cPickle
import unittest
import sys
import mock
import transaction
from random import randint
......@@ -3022,6 +3023,25 @@ return True''')
self.assertNotEquals(None, method)
self.assertTrue(method())
def test_dynamic_accessor_mockable(self):
"""Test dynamic accessors also work with mock and that
generally mock is usable in erp5 tests.
"""
self._addProperty(
'Credit Card',
self.id(),
'test_mocked_property',
elementary_type='string',
portal_type='Standard Property')
doc = self.portal.person_module.newContent(
portal_type='Person',
).newContent(
portal_type='Credit Card',
test_mocked_property='original')
with mock.patch('erp5.portal_type.Credit Card.getTestMockedProperty', return_value='mocked'):
self.assertEqual('mocked', doc.getTestMockedProperty())
self.assertEqual('original', doc.getTestMockedProperty())
def test_type_provider(self):
self.portal.newContent(id='dummy_type_provider', portal_type="Types Tool")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment