def testParseProjectAccess_AllowedChoice(self): project = project_pb2.MakeProject('proj') access = project_helpers.ParseProjectAccess(project, '1') self.assertEqual(project_pb2.ProjectAccess.ANYONE, access) access = project_helpers.ParseProjectAccess(project, '3') self.assertEqual(project_pb2.ProjectAccess.MEMBERS_ONLY, access)
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
def ProcessFormData(self, mr, post_data): """Process the posted form.""" # 1. Parse and validate user input. summary, description = self._ParseMeta(post_data, mr.errors) access = project_helpers.ParseProjectAccess(mr.project, post_data.get('access')) only_owners_remove_restrictions = ('only_owners_remove_restrictions' in post_data) only_owners_see_contributors = 'only_owners_see_contributors' in post_data issue_notify = post_data['issue_notify'] if issue_notify and not validate.IsValidEmail(issue_notify): mr.errors.issue_notify = _MSG_INVALID_EMAIL_ADDRESS process_inbound_email = 'process_inbound_email' in post_data 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: or https:' 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:' source_url = post_data.get('source_url') if source_url and not (source_url.startswith('http:') or source_url.startswith('https:')): mr.errors.source_url = 'Source link must start with http: or https:' logo_gcs_id = '' logo_file_name = '' if 'logo' in post_data and not isinstance(post_data['logo'], basestring): item = post_data['logo'] logo_file_name = item.filename try: logo_gcs_id = gcs_helpers.StoreLogoInGCS( logo_file_name, item.value, mr.project.project_id) except gcs_helpers.UnsupportedMimeType, e: mr.errors.logo = e.message
def testParseProjectAccess_BogusChoice(self): project = project_pb2.MakeProject('proj') access = project_helpers.ParseProjectAccess(project, '9') self.assertEqual(None, access)
def testParseProjectAccess_NotOffered(self): project = project_pb2.MakeProject('proj') access = project_helpers.ParseProjectAccess(project, None) self.assertEqual(None, access)