def test_register_service(self, mock_serv_endpoint_get, mock_client_constructor, mock_log): #Init ##Child mocks service_id = '101' mock_service_create = Mock(id=service_id) endpoint_id = '999' endpoint_region = 'RegionOne' endpoint_public_url = 'http://my.endpoint' mock_endpoint_create = Mock(id=endpoint_id, region=endpoint_region, publicurl=endpoint_public_url) attrs = {'services.create.return_value': mock_service_create, 'endpoints.create.return_value': mock_endpoint_create} mock_keystone_object = Mock(id=1, **attrs) ##return values mock_serv_endpoint_get.return_value = '' mock_client_constructor.return_value = mock_keystone_object #Calls service = Service(MCNApplication(), self.epc_svc_type) service.register_service(self.epc_svc_type) #Asserts mock_serv_endpoint_get.assert_called_once_with(tenant_name=self.SERVICE_TENANT_NAME, token=self.SERVICE_TOKEN, identifier='epc', endpoint=self.DESIGN_URI, url_type='public') mock_client_constructor.assert_called_once_with(tenant_name=self.SERVICE_TENANT_NAME, token=self.SERVICE_TOKEN, auth_url=self.DESIGN_URI) mock_log.assert_called_with( 'Service is now registered with keystone: ID: ' + endpoint_id + ' Region: ' + endpoint_region + ' Public URL: ' + endpoint_public_url + ' Service ID: ' + service_id)
def test_run(self, mock_register_backend, mock_register_service, mock_makeserver): #Inits mock_serv_forever = MagicMock() mock_makeserver.return_value = mock_serv_forever #Runs app = MCNApplication() service = Service(app, self.epc_svc_type) service.run() #Asserts mock_register_service.assert_called_once_with(self.epc_svc_type) mock_register_backend.assert_called_once_with(self.epc_svc_type, service.service_backend) mock_makeserver.assert_called_once_with('', 8888, app) mock_serv_forever.serve_forever.assert_called_once_with()
def test_init_for_sanity(self, mock_sb): service = Service(MCNApplication(), self.epc_svc_type) self.assertEqual(service.srv_type, self.epc_svc_type)