def setUp(self): self.mox = mox.Mox() self.cnxn = fake.MonorailConnection() self.services = service_manager.Services( config=fake.ConfigService(), issue=fake.IssueService(), user=fake.UserService(), user_star=fake.UserStarService(), usergroup=fake.UserGroupService(), project=fake.ProjectService(), project_star=fake.ProjectStarService(), features=fake.FeaturesService()) self.project = self.services.project.TestAddProject('proj', project_id=987) self.user = self.services.user.TestAddUser('*****@*****.**', 111) self.user_2 = self.services.user.TestAddUser('*****@*****.**', 222) self.group1_id = self.services.usergroup.CreateGroup( self.cnxn, self.services, '*****@*****.**', 'anyone') self.group2_id = self.services.usergroup.CreateGroup( self.cnxn, self.services, '*****@*****.**', 'anyone') self.services.usergroup.UpdateMembers(self.cnxn, self.group1_id, [111], 'member') self.services.usergroup.UpdateMembers(self.cnxn, self.group2_id, [222, 111], 'owner') self.users_svcr = users_servicer.UsersServicer(self.services, make_rate_limiter=False) self.prpc_context = context.ServicerContext() self.prpc_context.set_code(codes.StatusCode.OK)
def setUp(self): self.mox = mox.Mox() self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_memcache_stub() self.testbed.init_datastore_v3_stub() self.testbed.init_user_stub() self.cnxn = fake.MonorailConnection() self.services = service_manager.Services( user=fake.UserService(), usergroup=fake.UserGroupService(), project=fake.ProjectService(), cache_manager=fake.CacheManager()) self.project = self.services.project.TestAddProject( 'proj', project_id=789, owner_ids=[111]) self.user = self.services.user.TestAddUser('*****@*****.**', 222) self.svcr = TestableServicer(self.services) self.token = xsrf.GenerateToken(222, xsrf.XHR_SERVLET_PATH) self.request = UpdateSomethingRequest(exc_class=None) self.prpc_context = context.ServicerContext() self.prpc_context.set_code(codes.StatusCode.OK) self.auth = authdata.AuthData(user_id=222, email='*****@*****.**') self.oauth_patcher = mock.patch( 'google.appengine.api.oauth.get_current_user') self.mock_oauth_gcu = self.oauth_patcher.start() self.mock_oauth_gcu.return_value = None
def _mk_update_req(self, build, token='token', paths=None): build_req = rpc_pb2.UpdateBuildRequest( build=build, update_mask=dict(paths=paths or []), ) ctx = prpc_context.ServicerContext() if token: metadata = ctx.invocation_metadata() metadata.append((api.BUILD_TOKEN_HEADER, token)) return build_req, ctx
def error_handling_test(self, ex, expected_code, expected_details): @api.rpc_impl_async('GetBuild') @ndb.tasklet def get_build_async(_req, _res, _ctx, _mask): raise ex ctx = prpc_context.ServicerContext() req = rpc_pb2.GetBuildRequest(id=1) res = build_pb2.Build() # pylint: disable=no-value-for-parameter get_build_async(req, res, ctx).get_result() self.assertEqual(ctx.code, expected_code) self.assertEqual(ctx.details, expected_details)
def call(self, method, req, ctx=None, expected_code=prpc.StatusCode.OK, expected_details=None): ctx = ctx or prpc_context.ServicerContext() res = method(req, ctx) self.assertEqual(ctx.code, expected_code) if expected_details is not None: self.assertEqual(ctx.details, expected_details) if expected_code != prpc.StatusCode.OK: self.assertIsNone(res) return res
def setUp(self): self.mox = mox.Mox() self.cnxn = fake.MonorailConnection() self.services = service_manager.Services( config=fake.ConfigService(), issue=fake.IssueService(), user=fake.UserService(), usergroup=fake.UserGroupService(), project=fake.ProjectService(), project_star=fake.ProjectStarService(), features=fake.FeaturesService()) self.admin = self.services.user.TestAddUser('*****@*****.**', 123) self.admin.is_site_admin = True self.services.user.TestAddUser('*****@*****.**', 111) self.services.user.TestAddUser('*****@*****.**', 222) self.services.user.TestAddUser('*****@*****.**', 333) self.services.user.TestAddUser('*****@*****.**', 444) self.services.user.TestAddUser('*****@*****.**', 666) # User group 888 has members: user_555 and [email protected] self.services.user.TestAddUser('*****@*****.**', 888) self.services.usergroup.TestAddGroupSettings( 888, '*****@*****.**') self.services.usergroup.TestAddMembers(888, [555, 1001]) # User group 999 has members: user_111 and user_444 self.services.user.TestAddUser('*****@*****.**', 999) self.services.usergroup.TestAddGroupSettings( 999, '*****@*****.**') self.services.usergroup.TestAddMembers(999, [111, 444]) # User group 777 has members: user_666 and group 999. self.services.user.TestAddUser('*****@*****.**', 777) self.services.usergroup.TestAddGroupSettings( 777, '*****@*****.**') self.services.usergroup.TestAddMembers(777, [666, 999]) self.project = self.services.project.TestAddProject( 'proj', project_id=789) self.project.owner_ids.extend([111]) self.project.committer_ids.extend([222]) self.project.contributor_ids.extend([333]) self.projects_svcr = projects_servicer.ProjectsServicer( self.services, make_rate_limiter=False) self.prpc_context = context.ServicerContext() self.prpc_context.set_code(codes.StatusCode.OK)
def setUp(self): self.mox = mox.Mox() self.cnxn = fake.MonorailConnection() self.services = service_manager.Services( config=fake.ConfigService(), issue=fake.IssueService(), user=fake.UserService(), usergroup=fake.UserGroupService(), project=fake.ProjectService(), features=fake.FeaturesService(), hotlist_star=fake.HotlistStarService()) self.project = self.services.project.TestAddProject( 'proj', project_id=789, owner_ids=[111], contrib_ids=[222, 333]) self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789) self.user = self.services.user.TestAddUser('*****@*****.**', 111) self.user = self.services.user.TestAddUser('*****@*****.**', 222) self.user = self.services.user.TestAddUser('*****@*****.**', 333) self.user = self.services.user.TestAddUser('*****@*****.**', 444) self.features_svcr = features_servicer.FeaturesServicer( self.services, make_rate_limiter=False) self.prpc_context = context.ServicerContext() self.prpc_context.set_code(codes.StatusCode.OK) self.issue_1 = fake.MakeTestIssue( 789, 1, 'sum', 'New', 111, project_name='proj', issue_id=78901) self.issue_2 = fake.MakeTestIssue( 789, 2, 'sum', 'New', 111, project_name='proj', issue_id=78902) self.services.issue.TestAddIssue(self.issue_1) self.services.issue.TestAddIssue(self.issue_2) # For testing PredictComponent self._ml_engine = component_helpers_test.FakeMLEngine(self) self._top_words = None self._components_by_index = None mock.patch( 'services.ml_helpers.setup_ml_engine', lambda: self._ml_engine).start() mock.patch( 'features.component_helpers._GetTopWords', lambda _: self._top_words).start() mock.patch('cloudstorage.open', self.cloudstorageOpen).start() mock.patch('settings.component_features', 5).start() self.addCleanup(mock.patch.stopall)
def testConvertPRPCStatusToHTTPStatus(self): """We can convert pRPC status codes to http codes for monitoring.""" prpc_context = context.ServicerContext() prpc_context.set_code(codes.StatusCode.OK) self.assertEqual( 200, monorail_servicer.ConvertPRPCStatusToHTTPStatus(prpc_context)) prpc_context.set_code(codes.StatusCode.INVALID_ARGUMENT) self.assertEqual( 400, monorail_servicer.ConvertPRPCStatusToHTTPStatus(prpc_context)) prpc_context.set_code(codes.StatusCode.PERMISSION_DENIED) self.assertEqual( 403, monorail_servicer.ConvertPRPCStatusToHTTPStatus(prpc_context)) prpc_context.set_code(codes.StatusCode.NOT_FOUND) self.assertEqual( 404, monorail_servicer.ConvertPRPCStatusToHTTPStatus(prpc_context)) prpc_context.set_code(codes.StatusCode.INTERNAL) self.assertEqual( 500, monorail_servicer.ConvertPRPCStatusToHTTPStatus(prpc_context))