diff options
author | Camil Staps | 2016-03-04 23:09:53 +0100 |
---|---|---|
committer | Camil Staps | 2016-03-04 23:10:12 +0100 |
commit | 5372ebb8be5a5e6669129b6dc78fa6f333b6e186 (patch) | |
tree | 37e96eeb9749a3f9cfae44082d72514f49785156 /project1/proj1_s4498062/webtests.py | |
parent | Project one until step 8 in the readme (diff) |
Project 1: Config system; ETags; error pages
Diffstat (limited to 'project1/proj1_s4498062/webtests.py')
-rw-r--r-- | project1/proj1_s4498062/webtests.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/project1/proj1_s4498062/webtests.py b/project1/proj1_s4498062/webtests.py index a869de1..5e45acf 100644 --- a/project1/proj1_s4498062/webtests.py +++ b/project1/proj1_s4498062/webtests.py @@ -1,7 +1,9 @@ +import os.path
import unittest
import socket
import sys
+from webhttp.config import config
import webhttp.message
import webhttp.parser
@@ -22,6 +24,8 @@ class TestGetRequests(unittest.TestCase): ('Connection', 'close')
]
+ config().read(os.path.expanduser('~/.webpy.ini'))
+
def tearDown(self):
"""Clean up after testing"""
self.client_socket.shutdown(socket.SHUT_RDWR)
@@ -59,7 +63,23 @@ class TestGetRequests(unittest.TestCase): """GET for an existing single resource followed by a GET for that same
resource with caching utilized on the client/tester side
"""
- pass
+ response = self.request('GET', '/test', self.default_headers)
+
+ response = self.request('GET', '/test', self.default_headers + \
+ [('If-None-Match', 'invalid-etag')])
+ self.assertEqual(response.code, 200, 'If-None-Match returns 200')
+
+ response = self.request('GET', '/test', self.default_headers + \
+ [('If-None-Match', response.get_header('ETag'))])
+ self.assertEqual(response.code, 304, 'If-None-Match returns 304')
+
+ response = self.request('GET', '/test', self.default_headers + \
+ [('If-Match', response.get_header('ETag'))])
+ self.assertEqual(response.code, 200, 'If-Match returns 200')
+
+ response = self.request('GET', '/test', self.default_headers + \
+ [('If-Match', 'invalid-etag')])
+ self.assertEqual(response.code, 304, 'If-Match returns 304')
def test_extisting_index_file(self):
"""GET for a directory with an existing index.html file"""
@@ -72,6 +92,11 @@ class TestGetRequests(unittest.TestCase): self.assertEqual(response.code, 403)
self.assertTrue(response.body)
+ def test_error_page(self):
+ r1 = self.request('GET', '/test/nonexistant', self.default_headers)
+ r2 = self.request('GET', config('error404'), self.default_headers)
+ self.assertEqual(r1.body, r2.body)
+
def test_persistent_close(self):
"""Multiple GETs over the same (persistent) connection with the last
GET prompting closing the connection, the connection should be closed.
@@ -91,6 +116,10 @@ class TestGetRequests(unittest.TestCase): """
pass
+ def test_doubledot(self):
+ response = self.request('GET', '/../test', self.default_headers)
+ self.assertEquals(response.code, 403)
+
if __name__ == "__main__":
# Parse command line arguments
|