def get_mock_customer_logic(): global customer_logic_mock customer_logic_mock = mock.MagicMock() if root.CustomerLogic.return_error == 0: res = Models.CustomerResultWrapper(transaction_id='1', id='1', links={}, updated=None, created='1') list_res = Models.CustomerSummaryResponse() list_res.customers.append(Models.CustomerSummary(name='1', id='1', description='1')) customer_logic_mock.create_customer.return_value = res customer_logic_mock.update_customer.return_value = res customer_logic_mock.get_customer.return_value = Models.Customer(**RET_CUSTOMER_JSON) customer_logic_mock.get_customer_list_by_criteria.return_value = list_res elif root.CustomerLogic.return_error == 1: customer_logic_mock.create_customer.side_effect = SystemError() customer_logic_mock.update_customer.side_effect = SystemError() customer_logic_mock.get_customer.side_effect = SystemError() customer_logic_mock.delete_customer_by_uuid.side_effect = SystemError() customer_logic_mock.get_customer_list_by_criteria.side_effect = SystemError() else: customer_logic_mock.create_customer.side_effect = ErrorStatus(status_code=404) customer_logic_mock.update_customer.side_effect = ErrorStatus(status_code=404) customer_logic_mock.get_customer.side_effect = ErrorStatus(status_code=404) customer_logic_mock.delete_customer_by_uuid.side_effect = ErrorStatus( status_code=409) customer_logic_mock.get_customer_list_by_criteria.side_effect = ErrorStatus(status_code=404) return customer_logic_mock
def setUp(self): global customer FunctionalTest.setUp(self) customer_logic.DataManager = get_mock_datamanager customer_logic.pecan = mock.MagicMock() customer_logic.utils = mock.MagicMock() customer_logic.utils.make_transid.return_value = 'some_trans_id' customer_logic.utils.audit_trail.return_value = None customer_logic.utils.make_uuid.return_value = 'some_uuid' customer_logic.utils.get_time_human.return_value = '1337' customer_logic.RdsProxy = mock.MagicMock() customer_logic.RdsProxy.send_customer.return_value = None customer_logic.RdsProxy.get_status.return_value = RdsStatus() customer_logic.build_response = mock.MagicMock() customer = models.Customer() user = models.User() customer.users = [user, models.User()] user.role = ['user', 'admin'] global flow_type flow_type = 0
def to_wsme(self): name = self.name description = self.description enabled = True if self.enabled else False regions = [ customer_region.to_wsme() for customer_region in self.customer_customer_regions if customer_region.region_id != -1 ] defaultRegion = [ customer_region.to_wsme() for customer_region in self.customer_customer_regions if customer_region.region_id == -1 ] metadata = {} for metadata1 in self.customer_metadata: metadata[metadata1.field_key] = metadata1.field_value result = WsmeModels.Customer( description=description, enabled=enabled, name=name, regions=regions, users=defaultRegion[0].users if defaultRegion else [], metadata=metadata, defaultQuotas=defaultRegion[0].quotas if defaultRegion else [], custId=self.uuid, uuid=self.uuid) return result
def get_cust_model(): """this function create a customer model object for testing :return: new customer object """ cust = models.Customer(enabled=False, name='a', metadata={'a': 'b'}, regions=[ models.Region( name='r1', type='group', quotas=[models.Quota()], users=[models.User(id='a', role=['admin'])]) ], users=[models.User(id='b', role=['admin'])], defaultQuotas=[models.Quota()]) return cust
def mock_to_wsme(): return models.Customer( regions=[models.Region(name='DPK', status='Success')])