Commit 57d260d5 by Dudás Ádám

vm: remove __new__ patches

Patching __new__ on an object seems to have lasting effects even after the
context block's end.
parent afbfa085
from datetime import datetime from datetime import datetime
from mock import Mock, MagicMock, patch, call from mock import Mock, MagicMock, patch, call
import types
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test import TestCase from django.test import TestCase
...@@ -180,14 +181,18 @@ class InstanceActivityTestCase(TestCase): ...@@ -180,14 +181,18 @@ class InstanceActivityTestCase(TestCase):
def test_create_no_concurrency_check(self): def test_create_no_concurrency_check(self):
instance = MagicMock(spec=Instance) instance = MagicMock(spec=Instance)
instance.activity_log.filter.return_value.exists.return_value = True instance.activity_log.filter.return_value.exists.return_value = True
mock_instance_activity_cls = MagicMock(spec=InstanceActivity,
with patch.object(InstanceActivity, '__new__'): ACTIVITY_CODE_BASE='test')
try:
InstanceActivity.create('test', instance, original_create = InstanceActivity.create
concurrency_check=False) mocked_create = types.MethodType(original_create.im_func,
except ActivityInProgressError: mock_instance_activity_cls,
raise AssertionError("'create' method checked for concurrent " original_create.im_class)
"activities.") try:
mocked_create('test', instance, concurrency_check=False)
except ActivityInProgressError:
raise AssertionError("'create' method checked for concurrent "
"activities.")
def test_create_sub_concurrency_check(self): def test_create_sub_concurrency_check(self):
iaobj = MagicMock(spec=InstanceActivity) iaobj = MagicMock(spec=InstanceActivity)
...@@ -201,10 +206,10 @@ class InstanceActivityTestCase(TestCase): ...@@ -201,10 +206,10 @@ class InstanceActivityTestCase(TestCase):
iaobj.activity_code = 'test' iaobj.activity_code = 'test'
iaobj.children.filter.return_value.exists.return_value = True iaobj.children.filter.return_value.exists.return_value = True
with patch.object(InstanceActivity, '__new__'): create_sub_func = InstanceActivity.create_sub
with patch('vm.models.activity.InstanceActivity'):
try: try:
InstanceActivity.create_sub(iaobj, 'test', create_sub_func(iaobj, 'test', concurrency_check=False)
concurrency_check=False)
except ActivityInProgressError: except ActivityInProgressError:
raise AssertionError("'create_sub' method checked for " raise AssertionError("'create_sub' method checked for "
"concurrent activities.") "concurrent activities.")
......
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 sign in to comment