diff --git a/tests/unit/test_form.py b/tests/unit/test_form.py index 68223f7a5..68965d157 100644 --- a/tests/unit/test_form.py +++ b/tests/unit/test_form.py @@ -101,8 +101,8 @@ def test_metadata_wrapping(self): def test_radio_button_label(self): """Check that appropriate radio button label is returned.""" test_labels_list = [ - ('detection_bug', 'Desktop site instead of mobile site'), - ('unknown_bug', 'Something else') + ('detection_bug', 'i.svg', 'Desktop site instead of mobile site'), + ('unknown_bug', 'b.svg', 'Something else') ] r = form.get_radio_button_label('unknown_bug', test_labels_list) @@ -126,7 +126,7 @@ def test_get_form(self): actual = form.get_form(form_data) expected_browser = 'Firefox 48.0' expected_os = 'Mac OS X 10.11' - self.assertIsInstance(actual, form.IssueForm) + self.assertIsInstance(actual, form.FormWizard) self.assertEqual(actual.browser.data, expected_browser) self.assertEqual(actual.os.data, expected_os) self.assertEqual(actual.reported_with.data, 'desktop-reporter') diff --git a/webcompat/form.py b/webcompat/form.py index 0806b8d0e..77aae5c8b 100644 --- a/webcompat/form.py +++ b/webcompat/form.py @@ -85,14 +85,6 @@ } ] -problem_choices = [ - ('detection_bug', 'Desktop site instead of mobile site'), - ('site_bug', 'Site is not usable'), - ('layout_bug', 'Design is broken'), - ('video_bug', 'Video or audio doesn\'t play'), - ('unknown_bug', 'Something else') -] - problem_choices_wizard = [ ('detection_bug', 'svg-problem-mobile-vs-desktop.svg', 'Desktop site instead of mobile site'), @@ -191,57 +183,48 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) -class IssueForm(FlaskForm): - """Define form fields and validation for our bug reporting form.""" - - url = StringField(url_label, - [InputRequired(message=url_message)]) - browser = StringField('Is this information correct?', [Optional()]) - os = StringField('Operating System', [Optional()]) - # A dummy field to trap common bots. Users do not see that. - username = StringField('Username', - [Length(max=0, message=username_message)]) - # Field for people who want to be contacted, but do not want to login - # regex for GitHub usernames - username_pattern = r"^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$" - # Field definition - contact = StringField( - contact_label, - [Regexp(username_pattern, - flags=re.IGNORECASE, - message=contact_message)]) - description = StringField(desc_label, - [InputRequired(message=desc_message)]) +class FormWizard(FlaskForm): + """IssueForm to a multi step wizard form. + + Attributes notes: + * contact: + Field for people who want to be contacted, + but do not want to login + username_pattern defines regex for GitHub usernames + * image: + We filter allowed type in uploads.py + We don't use the label programatically for this input[type=file], + any changes here need to be updated in form.html. + * username: + A dummy field to trap common bots. Users do not see that. + """ + steps = NEW_ISSUE_STEPS + # Hidden Form Fields + console_logs_url = HiddenField() + description = HiddenField() + details = HiddenField() + extra_labels = HiddenField() + reported_with = HiddenField() + submit_type = HiddenField() + ua_header = HiddenField() - steps_reproduce = TextAreaField(textarea_label, [Optional()]) - problem_category = RadioField([InputRequired(message=radio_message)], - choices=problem_choices) + # Visible Form Fields + browser = StringField( + u'Browser', + [Optional()] + ) browser_test = RadioField(browser_test_label, [Optional()], choices=tested_elsewhere) - # we filter allowed type in uploads.py - # Note, we don't use the label programtically for this input[type=file], - # any changes here need to be updated in form.html. image = FileField('Attach a screenshot image', [Optional(), FileAllowed(ImageUpload.ALLOWED_FORMATS, image_message)]) - details = HiddenField() - reported_with = HiddenField() - ua_header = HiddenField() - submit_type = HiddenField() - extra_labels = HiddenField() - console_logs_url = HiddenField() - - -class FormWizard(IssueForm): - """Re-designed version of IssueForm to a multi step wizard form.""" - - steps = NEW_ISSUE_STEPS - - browser = StringField(u'Browser', [Optional()]) os = StringField('Operating System', [Optional()]) - description = HiddenField() - + steps_reproduce = TextAreaField(textarea_label, [Optional()]) + url = StringField(url_label, [InputRequired(message=url_message)]) + username = StringField('Username', + [Length(max=0, message=username_message)]) + # Steps Form Fields problem_category = PrefixedRadioField( [InputRequired(message=radio_message)], choices=problem_choices_wizard @@ -270,9 +253,16 @@ class FormWizard(IssueForm): [InputRequired(message=radio_message)], choices=browser_choices ) + # Bots Trap + username_pattern = r"^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$" + contact = StringField( + contact_label, + [Regexp(username_pattern, + flags=re.IGNORECASE, + message=contact_message)]) -def get_form(form_data, form=IssueForm): +def get_form(form_data, form=FormWizard): """Return an instance of flask_wtf.FlaskForm. It receives a dictionary of everything which needs to be fed to the form. @@ -346,7 +336,7 @@ def get_problem_summary(category): else: # Return the usual message in lowercase # because it is not at the start of the summary. - return get_radio_button_label(category, problem_choices).lower() + return get_radio_button_label(category, problem_choices_wizard).lower() def wrap_metadata(metadata): @@ -521,7 +511,7 @@ def build_formdata(form_object): 'browser': normalize_metadata(form_object.get('browser')), 'os': normalize_metadata(form_object.get('os')), 'problem_type': get_radio_button_label( - form_object.get('problem_category'), problem_choices), + form_object.get('problem_category'), problem_choices_wizard), 'browser_test_type': get_radio_button_label(form_object.get( 'browser_test'), tested_elsewhere), 'description': form_object.get('description'),