def test_collection_work_on(self): """ WorkContext propagated through work_on """ env = mock.MagicMock(name='env') collection = mock.MagicMock(name='collection') collection.env = env work = EventWorkContext(collection=collection, model_name='res.users', components_registry=self.components_registry) work2 = work.work_on(model_name='res.partner') self.assertEqual('WorkContext', work2.__class__.__name__) self.assertEqual(collection, work2.collection) self.assertEqual(env, work2.env) self.assertEqual('res.partner', work2.model_name) self.assertEqual(self.components_registry, work2.components_registry)
def test_env_work_on(self): """ WorkContext propagated through work_on """ env = mock.MagicMock(name='env') collection = mock.MagicMock(name='collection') collection.env = env work = EventWorkContext(env=env, model_name='res.users', components_registry=self.components_registry) work2 = work.work_on(model_name='res.partner', collection=collection) self.assertEqual('WorkContext', work2.__class__.__name__) self.assertEqual(env, work2.env) self.assertEqual('res.partner', work2.model_name) self.assertEqual(self.components_registry, work2.components_registry) with self.assertRaises(ValueError): # pylint: disable=W0104 work.collection # noqa
def test_collection_work_on_collection(self): """ WorkContext collection changed with work_on """ env = mock.MagicMock(name='env') collection = mock.MagicMock(name='collection') collection.env = env work = EventWorkContext(model_name='res.users', env=env, components_registry=self.components_registry) work2 = work.work_on(collection=collection) # when work_on is used inside an event component, we want # to switch back to a normal WorkContext, because we don't # need anymore the EventWorkContext self.assertEqual('WorkContext', work2.__class__.__name__) self.assertEqual(collection, work2.collection) self.assertEqual(env, work2.env) self.assertEqual('res.users', work2.model_name) self.assertEqual(self.components_registry, work2.components_registry)