コード例 #1
0
ファイル: test_helpers.py プロジェクト: cch5ng/webcompat.com
 def test_get_browser_name(self):
     '''Test browser name parsing via get_browser_name helper method.'''
     self.assertEqual(get_browser_name(FIREFOX_UA), 'firefox')
     self.assertEqual(get_browser_name(FIREFOX_MOBILE_UA), 'firefox mobile')
     self.assertEqual(get_browser_name(FIREFOX_MOBILE_UA_OLD),
                      'firefox mobile')
     self.assertEqual(get_browser_name(FIREFOX_TABLET_UA),
                      'firefox mobile (tablet)')
     self.assertEqual(get_browser_name(SAFARI_UA), 'safari')
     self.assertEqual(get_browser_name(SAFARI_MOBILE_UA), 'mobile safari')
     self.assertEqual(get_browser_name(SAFARI_TABLET_UA), 'mobile safari')
     self.assertEqual(get_browser_name(CHROME_UA), 'chrome')
     self.assertEqual(get_browser_name(CHROME_MOBILE_UA), 'chrome mobile')
     self.assertEqual(get_browser_name(CHROME_TABLET_UA), 'chrome')
     self.assertEqual(get_browser_name(''), 'unknown')
     self.assertEqual(get_browser_name(None), 'unknown')
     self.assertEqual(get_browser_name(), 'unknown')
     self.assertEqual(get_browser_name(u'💀'), 'unknown')
     self.assertEqual(get_browser('<script>lol()</script>'), 'Unknown')
     self.assertEqual(get_browser(True), 'Unknown')
     self.assertEqual(get_browser(False), 'Unknown')
     self.assertEqual(get_browser(None), 'Unknown')
コード例 #2
0
 def test_get_browser_name(self):
     '''Test browser name parsing via get_browser_name helper method.'''
     self.assertEqual(get_browser_name(FIREFOX_UA), 'firefox')
     self.assertEqual(get_browser_name(FIREFOX_MOBILE_UA), 'firefox mobile')
     self.assertEqual(get_browser_name(FIREFOX_MOBILE_UA_OLD),
                      'firefox mobile')
     self.assertEqual(get_browser_name(FIREFOX_TABLET_UA),
                      'firefox mobile (tablet)')
     self.assertEqual(get_browser_name(SAFARI_UA), 'safari')
     self.assertEqual(get_browser_name(SAFARI_MOBILE_UA), 'mobile safari')
     self.assertEqual(get_browser_name(SAFARI_TABLET_UA), 'mobile safari')
     self.assertEqual(get_browser_name(CHROME_UA), 'chrome')
     self.assertEqual(get_browser_name(CHROME_MOBILE_UA), 'chrome mobile')
     self.assertEqual(get_browser_name(CHROME_TABLET_UA), 'chrome')
     self.assertEqual(get_browser_name(''), 'unknown')
     self.assertEqual(get_browser_name(None), 'unknown')
     self.assertEqual(get_browser_name(), 'unknown')
     self.assertEqual(get_browser_name(u'💀'), 'unknown')
     self.assertEqual(get_browser('<script>lol()</script>'), 'Unknown')
     self.assertEqual(get_browser(True), 'Unknown')
     self.assertEqual(get_browser(False), 'Unknown')
     self.assertEqual(get_browser(None), 'Unknown')
コード例 #3
0
def get_form(form_data):
    """Return an instance of flask_wtf.FlaskForm.

    It receives a dictionary of everything which needs to be fed to the form.
    """
    bug_form = IssueForm()
    ua_header = form_data['user_agent']
    # Populate the form
    bug_form.browser.data = get_browser(ua_header)
    bug_form.extra_labels = form_data.get('extra_labels', None)
    bug_form.os.data = get_os(ua_header)
    bug_form.reported_with.data = form_data.get('src', 'web')
    bug_form.ua_header.data = ua_header
    bug_form.url.data = form_data.get('url', None)
    return bug_form
コード例 #4
0
def get_form(form_data, form=IssueForm):
    """Return an instance of flask_wtf.FlaskForm.

    It receives a dictionary of everything which needs to be fed to the form.
    """
    bug_form = form()
    ua_header = form_data['user_agent']
    # Populate the form
    bug_form.browser.data = get_browser(ua_header)
    # Note: The details JSON that was POSTed to the new issue endpoint is at
    # this point a Python dict. We need to re-serialize to JSON when we store
    # its value in the hidden details form element, otherwise when we attempt
    # to decode it as JSON on form submission, it will throw (because Python
    # dicts are not valid JSON)
    bug_form.details.data = json.dumps(form_data.get('details'), indent=2)
    bug_form.extra_labels = form_data.get('extra_labels', None)
    bug_form.os.data = get_os(ua_header)
    bug_form.reported_with.data = form_data.get('src', 'web')
    bug_form.ua_header.data = ua_header
    bug_form.url.data = form_data.get('url', None)
    return bug_form
コード例 #5
0
ファイル: form.py プロジェクト: webcompat/webcompat.com
def get_form(form_data):
    """Return an instance of flask_wtf.FlaskForm.

    It receives a dictionary of everything which needs to be fed to the form.
    """
    bug_form = IssueForm()
    ua_header = form_data['user_agent']
    # Populate the form
    bug_form.browser.data = get_browser(ua_header)
    # Note: The details JSON that was POSTed to the new issue endpoint is at
    # this point a Python dict. We need to re-serialize to JSON when we store
    # its value in the hidden details form element, otherwise when we attempt
    # to decode it as JSON on form submission, it will throw (because Python
    # dicts are not valid JSON)
    bug_form.details.data = json.dumps(form_data.get('details'), indent=2)
    bug_form.extra_labels = form_data.get('extra_labels', None)
    bug_form.os.data = get_os(ua_header)
    bug_form.reported_with.data = form_data.get('src', 'web')
    bug_form.ua_header.data = ua_header
    bug_form.url.data = form_data.get('url', None)
    return bug_form
コード例 #6
0
 def test_get_browser(self):
     """Test browser parsing via get_browser helper method."""
     self.assertEqual(get_browser(FIREFOX_UA), 'Firefox 48.0')
     self.assertEqual(get_browser(FIREFOX_MOBILE_UA), 'Firefox Mobile 40.0')
     self.assertEqual(get_browser_name(FIREFOX_MOBILE_UA_OLD),
                      'firefox mobile')
     self.assertEqual(get_browser(FIREFOX_TABLET_UA),
                      'Firefox Mobile (Tablet) 41.0')
     self.assertEqual(get_browser(SAFARI_UA), 'Safari 9.0')
     self.assertEqual(get_browser(SAFARI_MOBILE_UA), 'Mobile Safari 6.0')
     self.assertEqual(get_browser(SAFARI_TABLET_UA), 'Mobile Safari 5.1')
     self.assertEqual(get_browser(CHROME_UA), 'Chrome 52.0.2720')
     self.assertEqual(get_browser(CHROME_MOBILE_UA),
                      'Chrome Mobile 18.0.1025')
     self.assertEqual(get_browser(CHROME_TABLET_UA), 'Chrome 18.0.1025')
     self.assertEqual(get_browser(''), 'Unknown')
     self.assertEqual(get_browser(), 'Unknown')
     self.assertEqual(get_browser('💀'), 'Unknown')
     self.assertEqual(get_browser('<script>lol()</script>'), 'Unknown')
     self.assertEqual(get_browser(True), 'Unknown')
     self.assertEqual(get_browser(False), 'Unknown')
     self.assertEqual(get_browser(None), 'Unknown')
コード例 #7
0
 def test_get_browser_Non_Tablet(self):
     '''Test Browser parsing for non-tablet devices.'''
     user_agent = NON_TABLET_UA
     parsed_browser = PARSED_NON_TABLET_BROWSER
     self.assertEqual(get_browser(user_agent), parsed_browser)
コード例 #8
0
ファイル: test_helpers.py プロジェクト: karlcow/webcompat.com
 def test_get_browser(self):
     '''Test browser parsing via get_browser helper method.'''
     self.assertEqual(get_browser(FIREFOX_UA), 'Firefox 48.0')
     self.assertEqual(get_browser(FIREFOX_MOBILE_UA), 'Firefox Mobile 40.0')
     self.assertEqual(get_browser_name(FIREFOX_MOBILE_UA_OLD),
                      'firefox mobile')
     self.assertEqual(get_browser(FIREFOX_TABLET_UA),
                      'Firefox Mobile (Tablet) 41.0')
     self.assertEqual(get_browser(SAFARI_UA), 'Safari 9.0')
     self.assertEqual(get_browser(SAFARI_MOBILE_UA), 'Mobile Safari 6.0')
     self.assertEqual(get_browser(SAFARI_TABLET_UA), 'Mobile Safari 5.1')
     self.assertEqual(get_browser(CHROME_UA), 'Chrome 52.0.2720')
     self.assertEqual(get_browser(CHROME_MOBILE_UA),
                      'Chrome Mobile 18.0.1025')
     self.assertEqual(get_browser(CHROME_TABLET_UA), 'Chrome 18.0.1025')
     self.assertEqual(get_browser(''), 'Unknown')
     self.assertEqual(get_browser(), 'Unknown')
     self.assertEqual(get_browser(u'💀'), 'Unknown')
     self.assertEqual(get_browser('<script>lol()</script>'), 'Unknown')
     self.assertEqual(get_browser(True), 'Unknown')
     self.assertEqual(get_browser(False), 'Unknown')
     self.assertEqual(get_browser(None), 'Unknown')
コード例 #9
0
 def test_get_browser_Non_Tablet(self):
     '''Test Browser parsing for non-tablet devices.'''
     user_agent = NON_TABLET_UA
     parsed_browser = PARSED_NON_TABLET_BROWSER
     self.assertEqual(get_browser(user_agent), parsed_browser)