def test_new_acct_new_customer(self): self.mock_find_resources.return_value = ([], 'I do not care') # Use mock side effect to simulate two different return results results = [('acct_id_2', 'I do not care'), ('cust_id_1', 'I do not care')] def side_effect(*args, **kwargs): return results.pop() self.mock_create.side_effect = side_effect # TEST: Execute the service operation call account_id = self.bank_service.new_account('John') self.mock_find_resources.assert_called_once_with('BankCustomer', None, 'John', True) # assert last call first, pop the stack, assert the previous one self.assertEqual(self.mock_ionobj.call_count, 2) self.mock_ionobj.assert_called_with('BankAccount', account_type='Checking') pop_last_call(self.mock_ionobj) self.mock_ionobj.assert_called_once_with('BankCustomer', name='John') # assert last call first, pop the stack, assert the previous one self.assertEqual(self.mock_create.call_count, 2) self.mock_create.assert_called_with(self.mock_ionobj.return_value) pop_last_call(self.mock_create) self.mock_create.assert_called_once_with(self.mock_ionobj.return_value) self.mock_create_association.assert_called_once_with('cust_id_1', PRED.hasAccount, 'acct_id_2', None) self.assertEqual(account_id, 'acct_id_2')
def test_new_acct_new_customer(self): self.mock_find_resources.return_value = ([], 'I do not care') # Use mock side effect to simulate two different return results results = [('acct_id_2', 'I do not care'), ('cust_id_1', 'I do not care')] def side_effect(*args, **kwargs): return results.pop() self.mock_create.side_effect = side_effect # TEST: Execute the service operation call account_id = self.bank_service.new_account('John') self.mock_find_resources.assert_called_once_with( 'BankCustomer', None, 'John', True) # assert last call first, pop the stack, assert the previous one self.assertEqual(self.mock_ionobj.call_count, 2) self.mock_ionobj.assert_called_with('BankAccount', account_type='Checking') pop_last_call(self.mock_ionobj) self.mock_ionobj.assert_called_once_with('BankCustomer', name='John') # assert last call first, pop the stack, assert the previous one self.assertEqual(self.mock_create.call_count, 2) self.mock_create.assert_called_with(self.mock_ionobj.return_value) pop_last_call(self.mock_create) self.mock_create.assert_called_once_with(self.mock_ionobj.return_value) self.mock_create_association.assert_called_once_with( 'cust_id_1', PRED.hasAccount, 'acct_id_2', "H2H") self.assertEqual(account_id, 'acct_id_2')
def test_new_acct_new_customer(self): self.mock_find_resources.return_value = ([], "I do not care") # Use mock side effect to simulate two different return results results = [("acct_id_2", "I do not care"), ("cust_id_1", "I do not care")] def side_effect(*args, **kwargs): return results.pop() self.mock_create.side_effect = side_effect # TEST: Execute the service operation call account_id = self.bank_service.new_account("John") self.mock_find_resources.assert_called_once_with("BankCustomer", None, "John", True) # assert last call first, pop the stack, assert the previous one self.assertEqual(self.mock_ionobj.call_count, 2) self.mock_ionobj.assert_called_with("BankAccount", account_type="Checking") pop_last_call(self.mock_ionobj) self.mock_ionobj.assert_called_once_with("BankCustomer", name="John") # assert last call first, pop the stack, assert the previous one self.assertEqual(self.mock_create.call_count, 2) self.mock_create.assert_called_with(self.mock_ionobj.return_value) pop_last_call(self.mock_create) self.mock_create.assert_called_once_with(self.mock_ionobj.return_value) self.mock_create_association.assert_called_once_with("cust_id_1", PRED.hasAccount, "acct_id_2", "H2H") self.assertEqual(account_id, "acct_id_2")
def test_create_data_process(self): # setup self.resource_registry.read.return_value = (self.data_process_def_obj) self.resource_registry.create.return_value = (self.data_process_id, 'Version_1') self.transform_management_service.create_transform.return_value = self.transform_id self.data_acquisition_management.register_process.return_value = self.data_prod_id self.mock_ionobj.return_value = self.data_process_object # test call dp_id = self.data_process_mgmt_service.create_data_process \ (self.data_proc_def_id, \ [self.in_product_A], \ self.out_product_A) # verify results self.assertEqual(dp_id, 'ID4process') self.resource_registry.read.assert_called_once_with( self.data_proc_def_id, '') self.mock_ionobj.assert_called_once_with(RT.DataProcess, name=self.data_process_name) self.resource_registry.create.assert_called_once_with( self.data_process_object) self.data_acquisition_management.register_process.assert_called_once_with( self.data_process_id) self.transform_management_service.create_transform.assert_called_once_with( self.data_prod_id, self.subscription_id, self.stream_id) self.transform_management_service.schedule_transform.assert_called_once_with( self.transform_id) self.transform_management_service.bind_transform.assert_called_once_with( self.transform_id) self.assertEqual(self.resource_registry.create_association.call_count, 3) self.resource_registry.create_association.assert_called_with( self.data_process_id, PRED.hasTransform, self.transform_id, None) pop_last_call(self.resource_registry.create_association) self.resource_registry.create_association.assert_called_with( self.data_process_id, PRED.hasOutputProduct, self.out_product_A, None) pop_last_call(self.resource_registry.create_association) self.resource_registry.create_association.assert_called_once_with( self.data_process_id, PRED.hasInputProduct, self.in_product_A, None)
def test_create_data_process(self): # setup self.resource_registry.read.return_value = (self.data_process_def_obj) self.resource_registry.create.return_value = (self.data_process_id, 'Version_1') self.transform_management_service.create_transform.return_value = self.transform_id self.data_acquisition_management.register_process.return_value = self.data_prod_id self.mock_ionobj.return_value = self.data_process_object # test call dp_id = self.data_process_mgmt_service.create_data_process \ (self.data_proc_def_id, \ [self.in_product_A], \ self.out_product_A) # verify results self.assertEqual(dp_id, 'ID4process') self.resource_registry.read.assert_called_once_with(self.data_proc_def_id, '') self.mock_ionobj.assert_called_once_with(RT.DataProcess, name=self.data_process_name) self.resource_registry.create.assert_called_once_with(self.data_process_object) self.data_acquisition_management.register_process.assert_called_once_with(self.data_process_id) self.transform_management_service.create_transform.assert_called_once_with(self.data_prod_id, self.subscription_id, self.stream_id) self.transform_management_service.schedule_transform.assert_called_once_with(self.transform_id) self.transform_management_service.bind_transform.assert_called_once_with(self.transform_id) self.assertEqual(self.resource_registry.create_association.call_count, 3) self.resource_registry.create_association.assert_called_with(self.data_process_id, PRED.hasTransform, self.transform_id, None) pop_last_call(self.resource_registry.create_association) self.resource_registry.create_association.assert_called_with(self.data_process_id, PRED.hasOutputProduct, self.out_product_A, None) pop_last_call(self.resource_registry.create_association) self.resource_registry.create_association.assert_called_once_with(self.data_process_id, PRED.hasInputProduct, self.in_product_A, None)