source: ceda_http_fileserver/trunk/ceda_http_fileserver/ceda/server/wsgi/fileserver/test/test_fileserver.py @ 7009

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ceda_http_fileserver/trunk/ceda_http_fileserver/ceda/server/wsgi/fileserver/test/test_fileserver.py@7009
Revision 7009, 2.3 KB checked in by pjkersha, 10 years ago (diff)

Incomplete - task 9: Data Browser Replacement - Refactoring to include:

  • block based reading and writing of requests/responses
  • Fix to make WSGI compliant input read
  • configurable HTTP method support


Next:

  • URL encoding of file names for GET
  • USe mimetypes package
  • Property svn:keywords set to Id
Line 
1"""CEDA (Centre for Environmental Data Archival) HTTP file server application
2unit test module
3
4CEDA HTTP File Server WSGI Application
5"""
6__author__ = "P J Kershaw"
7__date__ = "11/06/10"
8__copyright__ = "(C) 2010 Science and Technology Facilities Council"
9__license__ = """http://www.apache.org/licenses/LICENSE-2.0"""
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = '$Id$'
12import logging
13logging.basicConfig(level=logging.DEBUG)
14
15import unittest
16from os import path
17
18import httplib
19
20import paste.fixture
21from paste.deploy import loadapp
22
23from ceda.server.wsgi.fileserver.app import FileServerApp
24
25
26class FileServerAppTestCase(unittest.TestCase):
27    THIS_DIR = path.abspath(path.dirname(__file__))
28    HTDOCS_DIRNAME = 'htdocs'
29    HTDOCS_DIR = path.join(THIS_DIR, HTDOCS_DIRNAME)
30
31    def __init__(self, *args, **kwargs):
32        self.fileServerApp = FileServerApp(self.__class__.HTDOCS_DIR)
33        self.app = paste.fixture.TestApp(self.fileServerApp)
34         
35        unittest.TestCase.__init__(self, *args, **kwargs)
36
37    def test01Assert(self):
38        response = self.app.get('/', status=200)
39        print(response)
40        self.assert_(response)
41
42    def test02CheckBlkSizeValidation(self):
43        def _set(x):
44            self.fileServerApp.readBlkSize = x
45           
46        self.assertRaises(ValueError, _set, 'my block size') 
47        self.assertRaises(ValueError, _set, -10)
48       
49    def test03CheckHttpMethodValidation(self):
50        def _set():
51            self.fileServerApp.httpMethodMap = None
52           
53        self.assertRaises(TypeError, _set)
54       
55    def test04TrapHttpMethodNotAllowed(self):
56        self.fileServerApp.httpMethodMap = {}
57        response = self.app.get('/', status=httplib.METHOD_NOT_ALLOWED)
58   
59   
60class FileServerAppTestCaseBase(unittest.TestCase): 
61    """Base class for common Paste Deploy related set-up"""
62    THIS_DIR = path.abspath(path.dirname(__file__))
63    INI_FILENAME = 'fileserver.ini'
64    INI_FILEPATH = path.join(THIS_DIR, INI_FILENAME)
65   
66    def __init__(self, *args, **kwargs):
67        wsgiapp = loadapp('config:' + self.__class__.INI_FILEPATH)
68        self.app = paste.fixture.TestApp(wsgiapp)
69               
70        unittest.TestCase.__init__(self, *args, **kwargs) 
71   
72if __name__ == "__main__":
73    unittest.main()
74
Note: See TracBrowser for help on using the repository browser.