forked from Polymer/old-docs-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.py
More file actions
98 lines (76 loc) · 3.28 KB
/
test_server.py
File metadata and controls
98 lines (76 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
# This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
# The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
# The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
# Code distributed by Google as part of the polymer project is also
# subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
import re
import unittest
import urllib
import webapp2
import webtest
import yaml
from google.appengine.api import memcache
from google.appengine.ext import testbed
import server
class HandlerTest(unittest.TestCase):
def __redirect_resolves(self, url, expected_resp):
resp = self.testapp.get(url)
self.assertFalse(resp.location.endswith(url), 'Final URL is not different')
assert resp.status_int == 301
resp = resp.maybe_follow()
assert resp.status_int == 200
self.assertEqual(expected_resp.normal_body, resp.normal_body,
'Redirect response was correct')
return resp
def setUp(self):
app = webapp2.WSGIApplication([('/(.*)', server.Site)])
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_memcache_stub()
def tearDown(self):
self.testbed.deactivate()
def testMainHandler(self):
resp = self.testapp.get('/')
assert resp.status_code == 301
resp = resp.maybe_follow()
assert resp.status_code == 200
assert resp.content_type == 'text/html'
assert 'rel=preload' in resp.headers['Link']
resp = self.testapp.get('/1.0/')
assert resp.status_code == 200
assert resp.content_type == 'text/html'
resp = self.testapp.get('/1.0/page.html')
assert resp.status_code == 301
self.assertTrue(resp.location.endswith('/1.0/page'))
def test404(self):
resp = self.testapp.get('/pagethatdoesnotexist', status=404)
assert resp.status_code == 404
def testIndexRedirects(self):
expected_resp = self.testapp.get('/1.0/')
self.__redirect_resolves('/index.html', expected_resp)
self.__redirect_resolves('/index', expected_resp)
expected_resp = self.testapp.get('/1.0/')
self.__redirect_resolves('/1.0/index.html', expected_resp)
self.__redirect_resolves('/1.0/index', expected_resp)
expected_resp = self.testapp.get('/1.0/page')
self.__redirect_resolves('/1.0/page.html', expected_resp)
def testMarkdownAuthoring(self):
resp = self.testapp.get('/1.0/test')
assert resp.status_code == 200
assert resp.content_type == 'text/html'
assert 'rel=preload' in resp.headers['Link']
self.assertRegexpMatches(resp.normal_body, '<title>Test markdown page')
self.assertRegexpMatches(resp.normal_body, '<details id="toc">')
self.assertRegexpMatches(resp.normal_body, '<pre><code class="lang-html">')
def testRedirectFile(self):
redirects = server.read_redirects_file(server.REDIRECTS_FILE)
for start_url,dest_url in redirects.items():
resp = self.testapp.get(start_url)
assert resp.status_code == 301
self.assertTrue(resp.location.endswith(dest_url))
if __name__ == '__main__':
unittest.main()