Beispiel #1
0
def GetRequestObjects(headers=None,
                      path='/',
                      params=None,
                      payload=None,
                      user_info=None,
                      project=None,
                      method='GET',
                      perms=None,
                      services=None,
                      hotlist=None):
    """Make fake request and MonorailRequest objects for testing.

  Host param will override the 'Host' header, and has a default value of
  '127.0.0.1'.

  Args:
    headers: Dict of HTTP header strings.
    path: Path part of the URL in the request.
    params: Dict of query-string parameters.
    user_info: Dict of user attributes to set on a MonorailRequest object.
        For example, "user_id: 5" causes self.auth.user_id=5.
    project: optional Project object for the current request.
    method: 'GET' or 'POST'.
    perms: PermissionSet to use for this request.
    services: Connections to backends.
    hotlist: optional Hotlist object for the current request

  Returns:
    A tuple of (http Request, monorailrequest.MonorailRequest()).
  """
    headers = headers or {}
    params = params or {}

    headers.setdefault('Host', DEFAULT_HOST)
    post_items = None
    if method == 'POST' and payload:
        post_items = payload
    elif method == 'POST' and params:
        post_items = params

    if not services:
        services = service_manager.Services(project=fake.ProjectService(),
                                            user=fake.UserService(),
                                            usergroup=fake.UserGroupService(),
                                            features=fake.FeaturesService())
        services.project.TestAddProject('proj')
        services.features.TestAddHotlist('hotlist')

    request = webapp2.Request.blank(path, headers=headers, POST=post_items)
    mr = fake.MonorailRequest(user_info=user_info,
                              project=project,
                              perms=perms,
                              params=params,
                              hotlist=hotlist)
    mr.ParseRequest(request,
                    services,
                    profiler.Profiler(),
                    do_user_lookups=False)
    mr.auth.user_pb = user_pb2.MakeUser(0)
    return request, mr
def MakeReqInfo(user_pb, user_id, viewed_user_pb, viewed_user_id,
                viewed_user_name):
    mr = fake.MonorailRequest(None, perms=permissions.USER_PERMISSIONSET)
    mr.auth.user_pb = user_pb
    mr.auth.user_id = user_id
    mr.auth.effective_ids = {user_id}
    mr.viewed_user_auth.email = viewed_user_name
    mr.viewed_user_auth.user_pb = viewed_user_pb
    mr.viewed_user_auth.user_id = viewed_user_id
    mr.viewed_user_auth.effective_ids = {viewed_user_id}
    mr.viewed_user_auth.user_view = framework_views.UserView(viewed_user_pb)
    mr.viewed_user_name = viewed_user_name
    mr.request = webapp2.Request.blank("/")
    return mr
 def setUp(self):
     self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
     self.cd1 = tracker_bizobj.MakeComponentDef(1, 789, 'FrontEnd', 'doc',
                                                False, [], [111], 0, 0)
     self.cd2 = tracker_bizobj.MakeComponentDef(2, 789, 'FrontEnd>Splash',
                                                'doc', False, [], [222], 0,
                                                0)
     self.cd3 = tracker_bizobj.MakeComponentDef(3, 789, 'BackEnd', 'doc',
                                                True, [], [111, 333], 0, 0)
     self.config.component_defs = [self.cd1, self.cd2, self.cd3]
     self.services = service_manager.Services(user=fake.UserService(),
                                              config=fake.ConfigService())
     self.services.user.TestAddUser('*****@*****.**', 111)
     self.services.user.TestAddUser('*****@*****.**', 222)
     self.services.user.TestAddUser('*****@*****.**', 333)
     self.mr = fake.MonorailRequest(self.services)
     self.mr.cnxn = fake.MonorailConnection()
Beispiel #4
0
def MakeReqInfo(user_pb,
                user_id,
                viewed_user_pb,
                viewed_user_id,
                viewed_user_name,
                path=None,
                _reveal_email=False,
                _params=None):
    if path is None:
        path = "/u/%d" % viewed_user_id
    mr = fake.MonorailRequest()
    mr.auth.user_pb = user_pb
    mr.auth.user_id = user_id
    mr.auth.effective_ids = {user_id}
    mr.viewed_user_auth.email = viewed_user_name
    mr.viewed_user_auth.user_pb = viewed_user_pb
    mr.viewed_user_auth.user_id = viewed_user_id
    mr.viewed_user_auth.effective_ids = {viewed_user_id}
    mr.viewed_user_auth.user_view = framework_views.UserView(viewed_user_pb)
    mr.viewed_user_name = viewed_user_name
    mr.request = webapp2.Request.blank("/")
    return mr