Browse files

test_that_checks_redirect_using_incorrect_query_values

  • Loading branch information...
1 parent 8a4e4fe commit 4f359d2751c567c8648f8ac9c1dd9e6393a32c19 @bebef1987 bebef1987 committed Oct 9, 2012
Showing with 77 additions and 0 deletions.
  1. +11 −0 requirements.txt
  2. 0 tests/__init__.py
  3. +32 −0 tests/base.py
  4. +34 −0 tests/test_redirects.py
View
11 requirements.txt
@@ -0,0 +1,11 @@
+# This pulls in all the libraries needed to run Selenium tests
+# on Mozilla WebQA projects
+
+py==1.4.8
+pytest==2.2.4
+pytest-xdist==1.8
+pytest-mozwebqa==1.0
+unittestzero
+requests==0.11.2
+beautifulsoup4==4.0.4
+
View
0 tests/__init__.py
No changes.
View
32 tests/base.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import requests
+from bs4 import BeautifulSoup
+from unittestzero import Assert
+
+
+class Base:
+
+ _user_agent_firefox = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.1) Gecko/20100101 Firefox/10.0.1'
+
+ def _get_redirect(self, url, user_agent=_user_agent_firefox, locale='en-US', params=None):
+
+ headers = {'user-agent': user_agent,
+ 'accept-language': locale}
+
+ return requests.get(url, headers=headers, verify=False, timeout=5, params=params)
+
+ def assert_valid_url(self, url, path, user_agent=_user_agent_firefox, locale='en-US'):
+ """Checks if a URL returns a 200 OK response."""
+ headers = {'user-agent': user_agent,
+ 'accept-language': locale}
+
+ # HEAD doesn't return page body.
+ r = requests.head(url, headers=headers, timeout=5, allow_redirects=True, verify=False)
+ return Assert.equal(r.status_code, requests.codes.ok, 'Bad URL %s found in %s' % (url, path))
+
+ def _parse_response(self, content):
+ return BeautifulSoup(content)
View
34 tests/test_redirects.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import pytest
+import requests
+from urlparse import urlparse
+from urllib import urlencode
+from unittestzero import Assert
+
+from base import Base
+
+
+@pytest.mark.skip_selenium
+@pytest.mark.nondestructive
+class TestRedirects(Base):
+
+ @pytest.mark.parametrize('url', ["http://download.allizom.org/", "https://download.allizom.org/"])
+ def test_that_checks_incorrect_values(self, url):
+ param = {
+ 'product': 'firefox-16.0b6',
+ 'lang': 'test_kity',
+ 'os': 'stella'
+ }
+
+ response = self._get_redirect(url, params=param)
+
+ Assert.equal(response.status_code, requests.codes.not_found)
+
+ parsed_url = urlparse(response.url)
+ Assert.equal(parsed_url.scheme, 'https')
+ Assert.equal(parsed_url.netloc, urlparse(url).netloc)
+ Assert.equal(parsed_url.query, urlencode(param))

0 comments on commit 4f359d2

Please sign in to comment.