def create_model(self, class_, *args, **kwargs): """ create an instance of the model being tested, this will instrument some methods of the model to check if they have been called """ obj = class_.objects.create(*args, **kwargs) # patch model class CallProxy.patch(obj, 'parse_transient_info') CallProxy.patch(obj, 'parse_persistent_info') CallProxy.patch(obj, '_refresh') CallProxy.patch(obj, 'load_info') CallProxy.patch(obj, 'save') return obj
def create_model(self, **kwargs): """ create an instance of the model being tested, this will instrument some methods of the model to check if they have been called """ cluster, chaff = Cluster.objects.get_or_create(hostname='test.foo.org') obj = self.Model(cluster=cluster, **kwargs) # patch model class CallProxy.patch(obj, 'parse_transient_info') CallProxy.patch(obj, 'parse_persistent_info') CallProxy.patch(obj, '_refresh') CallProxy.patch(obj, 'load_info') CallProxy.patch(obj, 'save') return obj
def __new__(klass, *args, **kwargs): instance = RapiProxy.__new__(klass, *args, **kwargs) # Unbind functions that are to be patched instance.GetInstances = None instance.GetInstance = None instance.GetInfo = None instance.GetOperatingSystems = None CallProxy.patch(instance, 'GetInstances', False, INSTANCES) CallProxy.patch(instance, 'GetInstance', False, XEN_PVM_INSTANCE) CallProxy.patch(instance, 'GetInfo', False, XEN_INFO) CallProxy.patch(instance, 'GetOperatingSystems', False, XEN_OPERATING_SYSTEMS) return instance
def test_cache_reset_error(self): """ Tests that cache reset is working properly. Verifies: * when success or error status is achieved the job no longer updates """ job = self.test_save() job.ignore_cache = True job.save() rapi = job.rapi rapi.GetJobStatus.response = JOB_RUNNING CallProxy.patch(job, '_refresh') # load with running status, should refresh job.load_info() self.assertTrue(job.ignore_cache) job._refresh.assertCalled(self) job._refresh.reset() # load again with running status, should refresh job.load_info() self.assertTrue(job.ignore_cache) job._refresh.assertCalled(self) job._refresh.reset() # load again with success status, should refresh and flip cache flag rapi.GetJobStatus.response = JOB_ERROR job.load_info() self.assertFalse(job.ignore_cache) job._refresh.assertCalled(self) job._refresh.reset() # load again with success status, should use cache job.load_info() self.assertFalse(job.ignore_cache) job._refresh.assertNotCalled(self)
def __new__(klass, *args, **kwargs): instance = object.__new__(klass) instance.__init__(*args, **kwargs) CallProxy.patch(instance, 'GetInstances', False, INSTANCES) CallProxy.patch(instance, 'GetInstance', False, INSTANCE) CallProxy.patch(instance, 'GetNodes', False, NODES_MAP) CallProxy.patch(instance, 'GetNode', False, NODE) CallProxy.patch(instance, 'GetInfo', False, INFO) CallProxy.patch(instance, 'GetOperatingSystems', False, OPERATING_SYSTEMS) CallProxy.patch(instance, 'GetJobStatus', False, JOB_RUNNING) CallProxy.patch(instance, 'StartupInstance', False, 1) CallProxy.patch(instance, 'ShutdownInstance', False, 1) CallProxy.patch(instance, 'RebootInstance', False, 1) CallProxy.patch(instance, 'ReinstallInstance', False, 1) CallProxy.patch(instance, 'AddInstanceTags', False) CallProxy.patch(instance, 'DeleteInstanceTags', False) CallProxy.patch(instance, 'CreateInstance', False, 1) CallProxy.patch(instance, 'DeleteInstance', False, 1) CallProxy.patch(instance, 'ModifyInstance', False, 1) CallProxy.patch(instance, 'MigrateInstance', False, 1) CallProxy.patch(instance, 'RenameInstance', False, 1) CallProxy.patch(instance, 'RedistributeConfig', False, 1) CallProxy.patch(instance, 'ReplaceInstanceDisks', False, 1) CallProxy.patch(instance, 'SetNodeRole', False, 1) CallProxy.patch(instance, 'EvacuateNode', False, 1) CallProxy.patch(instance, 'MigrateNode', False, 1) return instance