PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/blogmaker/util/fetch_test.py

http://blogmaker.googlecode.com/
Python | 45 lines | 27 code | 12 blank | 6 comment | 1 complexity | a0190ead682404941b0f2e2cba758d97 MD5 | raw file
 1''' Tests for the fetch module.
 2    You must be running the blogcosm server in dev mode on port 8000
 3    when you run these tests.
 4    
 5    Copyright (c) 2006-2007, PreFab Software Inc.
 6'''
 7
 8import unittest, urllib2
 9import fetch
10
11from blogcosm.test import constants as c
12
13class FetchTest(unittest.TestCase):
14    def test_open_resource(self):
15        f = fetch.open_resource('http://localhost:8000/test/simpleHomePage/')
16        data = f.read()
17        f.close()
18        
19        self.assertEquals(200, f.code)
20        self.assertEquals('http://localhost:8000/test/simpleHomePage/', f.url)
21        self.assert_(data)
22        
23        self.assertEquals(c.lastModified, f.headers['last-modified'])
24    
25        self.assertEquals(c.eTag, f.headers['etag'])
26    
27    def test_notModified(self):
28        f = fetch.open_resource('http://localhost:8000/test/304/')
29        self.assertEquals(304, f.status)
30
31    def test_redirect(self):
32        f = fetch.open_resource('http://localhost:8000/test/simpleHomePage')
33        self.assertEquals(200, f.code)
34        self.assertEquals(301, f.status)
35        self.assertEquals('http://localhost:8000/test/simpleHomePage/', f.url)
36        
37        f = fetch.open_resource('http://localhost:8000/test/tempRedirect/')
38        self.assertEquals(200, f.code)
39        self.assertEquals(302, f.status)
40        self.assertEquals('http://localhost:8000/test/simpleHomePage/', f.url)
41        
42    
43if __name__ == '__main__':
44    unittest.main()
45