Rewrite main url tests and redirects test to use the test database

- Legacy-Id: 6837
This commit is contained in:
Ole Laursen 2013-12-07 13:29:48 +00:00
parent 77fc3ec134
commit f1a34faf08
2 changed files with 20 additions and 41 deletions

View file

@ -33,7 +33,7 @@
import unittest, os, re
from django.test.client import Client
from django.conf import settings
from ietf.utils.test_utils import SimpleUrlTestCase, RealDatabaseTest, split_url, read_testurls
from ietf.utils.test_utils import split_url, read_testurls, TestCase
import ietf.urls
import ietf.utils.test_runner as test_runner
@ -60,6 +60,10 @@ REDIRECT_TESTS = {
'/drafts/10845/related/',
'/public/idindex.cgi?command=id_detail&filename=draft-l3vpn-as4octet-ext-community':
'/drafts/draft-l3vpn-as4octet-ext-community/',
# non-ASCII parameter
'/public/pidtracker.cgi?command=view_id&dTag=11171%D182&rfc_flag=0':
'/idtracker/',
'/idtracker/': '/doc/',
# ipr
@ -86,29 +90,16 @@ REDIRECT_TESTS = {
}
class RedirectsTestCase(unittest.TestCase, RealDatabaseTest):
def setUp(self):
self.setUpRealDatabase()
def tearDown(self):
self.tearDownRealDatabase()
def testRedirects(self):
print " Testing redirects"
c = Client()
class RedirectsTests(TestCase):
def test_redirects(self):
for src, dst in REDIRECT_TESTS.items():
baseurl, args = split_url(src)
try:
response = c.get(baseurl, args)
self.assert_(str(response.status_code).startswith("3"))
location = response['Location']
if location.startswith("http://testserver/"):
location = location[17:]
self.assertEqual(location, dst)
print "OK "+src
except:
print "Fail "+src
raise
response = self.client.get(baseurl, args)
self.assertTrue(str(response.status_code).startswith("3"))
location = response['Location']
if location.startswith("http://testserver/"):
location = location[17:]
self.assertEqual(location, dst, (src, dst, location))
def get_patterns(module):
all = []
@ -155,9 +146,13 @@ class UrlCoverageTestCase(unittest.TestCase):
else:
print "All URLs are included in some testurl.list"
class MainUrlTestCase(SimpleUrlTestCase):
def testUrls(self):
self.doTestUrls(__file__)
class MainUrlTests(TestCase):
def test_urls(self):
self.assertEqual(self.client.get("/_doesnotexist/").status_code, 404)
self.assertEqual(self.client.get("/sitemap.xml").status_code, 200)
# Google webmaster tool verification page
self.assertEqual(self.client.get("/googlea30ad1dacffb5e5b.html").status_code, 200)
def get_templates():
templates = set()

View file

@ -1,16 +0,0 @@
# Top-level test URL list. Should probably be empty; all test URls should be
# specified in the application level testurl.list
200 /googlea30ad1dacffb5e5b.html # Google webmaster tool verification page
200 /sitemap.xml
404 /_doesnotexist/
#skip /_test500/
# non-ASCII parameter
301 /public/pidtracker.cgi?command=view_id&dTag=11171%D182&rfc_flag=0
#301 /list/request.... # test middleware that strips periods and redirects instead of 404
#skip /images/ietf-icon.bmp
#skip /css/base.css
#skip /js/