def testMaximumLength(self):
     self.assertFalse(
         framework_bizobj.IsValidProjectName(
             'x' * (framework_constants.MAX_PROJECT_NAME_LENGTH + 1)))
     self.assertTrue(
         framework_bizobj.IsValidProjectName(
             'x' * (framework_constants.MAX_PROJECT_NAME_LENGTH)))
예제 #2
0
  def CreateProject(
      self, cnxn, project_name, owner_ids, committer_ids, contributor_ids,
      summary, description, state=project_pb2.ProjectState.LIVE,
      access=None, read_only_reason=None, home_page=None, docs_url=None,
      source_url=None, logo_gcs_id=None, logo_file_name=None):
    """Create and store a Project with the given attributes.

    Args:
      cnxn: connection to SQL database.
      project_name: a valid project name, all lower case.
      owner_ids: a list of user IDs for the project owners.
      committer_ids: a list of user IDs for the project members.
      contributor_ids: a list of user IDs for the project contributors.
      summary: one-line explanation of the project.
      description: one-page explanation of the project.
      state: a project state enum defined in project_pb2.
      access: optional project access enum defined in project.proto.
      read_only_reason: if given, provides a status message and marks
        the project as read-only.
      home_page: home page of the project
      docs_url: url to redirect to for wiki/documentation links
      source_url: url to redirect to for source browser links
      logo_gcs_id: google storage object id of the project's logo
      logo_file_name: uploaded file name of the project's logo

    Returns:
      The int project_id of the new project.

    Raises:
      ProjectAlreadyExists: if a project with that name already exists.
    """
    assert framework_bizobj.IsValidProjectName(project_name)
    if self.LookupProjectIDs(cnxn, [project_name]):
      raise exceptions.ProjectAlreadyExists()

    project = project_pb2.MakeProject(
        project_name, state=state, access=access,
        description=description, summary=summary,
        owner_ids=owner_ids, committer_ids=committer_ids,
        contributor_ids=contributor_ids, read_only_reason=read_only_reason,
        home_page=home_page, docs_url=docs_url, source_url=source_url,
        logo_gcs_id=logo_gcs_id, logo_file_name=logo_file_name)

    project.project_id = self._InsertProject(cnxn, project)
    return project.project_id
예제 #3
0
    def ProcessFormData(self, mr, post_data):
        """Process the posted form."""
        # 1. Parse and validate user input.
        # Project name is taken from post_data because we are creating it.
        project_name = post_data.get('projectname')
        if not project_name:
            mr.errors.projectname = _MSG_MISSING_PROJECT_NAME
        elif not framework_bizobj.IsValidProjectName(project_name):
            mr.errors.projectname = _MSG_INVALID_PROJECT_NAME

        summary = post_data.get('summary')
        if not summary:
            mr.errors.summary = _MSG_MISSING_PROJECT_SUMMARY
        description = post_data.get('description', '')

        access = project_helpers.ParseProjectAccess(None,
                                                    post_data.get('access'))
        home_page = post_data.get('project_home')
        if home_page and not (home_page.startswith('http://')
                              or home_page.startswith('https://')):
            mr.errors.project_home = 'Home page link must start with http(s)://'
        docs_url = post_data.get('docs_url')
        if docs_url and not (docs_url.startswith('http:')
                             or docs_url.startswith('https:')):
            mr.errors.docs_url = 'Documentation link must start with http: or https:'

        self.CheckCaptcha(mr, post_data)

        # These are not specified on via the ProjectCreate form,
        # the user must edit the project after creation to set them.
        committer_ids = []
        contributor_ids = []

        # Validate that provided logo is supported.
        logo_provided = 'logo' in post_data and not isinstance(
            post_data['logo'], basestring)
        if logo_provided:
            item = post_data['logo']
            try:
                gcs_helpers.CheckMimeTypeResizable(
                    filecontent.GuessContentTypeFromFilename(item.filename))
            except gcs_helpers.UnsupportedMimeType, e:
                mr.errors.logo = e.message
예제 #4
0
 def testValidName(self):
   self.assertTrue(framework_bizobj.IsValidProjectName('098asd'))
   self.assertTrue(framework_bizobj.IsValidProjectName('one-two-three'))
예제 #5
0
 def testInvalidName(self):
   self.assertFalse(framework_bizobj.IsValidProjectName(''))
   self.assertFalse(framework_bizobj.IsValidProjectName('000'))
예제 #6
0
 def testMinimumLength(self):
   self.assertFalse(framework_bizobj.IsValidProjectName('x'))
   self.assertTrue(framework_bizobj.IsValidProjectName('xy'))
예제 #7
0
 def testBadHyphen(self):
   self.assertFalse(framework_bizobj.IsValidProjectName('name-'))
   self.assertFalse(framework_bizobj.IsValidProjectName('-name'))
   self.assertTrue(framework_bizobj.IsValidProjectName('project-name'))
예제 #8
0
 def testBadChars(self):
   self.assertFalse(framework_bizobj.IsValidProjectName('spa ce'))
   self.assertFalse(framework_bizobj.IsValidProjectName('under_score'))
   self.assertFalse(framework_bizobj.IsValidProjectName('name.dot'))
   self.assertFalse(framework_bizobj.IsValidProjectName('pie#sign$'))
   self.assertFalse(framework_bizobj.IsValidProjectName('(who?)'))