source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/tests/functional/testNdgInterface.py @ 4182

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/tests/functional/testNdgInterface.py@4182
Revision 4182, 2.7 KB checked in by cbyrom, 12 years ago (diff)

Extend controller level test suite.

Line 
1'''
2A test class for the ndgInterface module.
3
4C Byrom Jul 2008
5Tessella
6'''
7from ows_server.tests import *
8import unittest
9from paste.registry import Registry
10import pylons, os
11from pylons.util import ContextObj
12from pylons.wsgiapp import WSGIRequest
13from ows_server.lib import ndgInterface as NI
14from pylons.wsgiapp import PylonsApp
15from ows_server.config.ndgMiddleware import ndgMiddleware
16from ows_server.config.middleware import make_app
17from paste.deploy import loadapp
18import paste.fixture
19from paste.deploy.config import ConfigMiddleware, CONFIG
20import logging
21
22logging.basicConfig(level=logging.DEBUG,
23                        format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s')
24
25here_dir = os.path.dirname(os.path.abspath(__file__))
26conf_dir = os.path.dirname(os.path.dirname(here_dir))
27
28VALID_DE_DOC = 'badc.nerc.ac.uk__DIF__dataent_11872529492720024'
29class testNDGInterface(TestController):
30#class testNDGInterface(unittest.TestCase):
31    """A basic test case which allows access to pylons.c and pylons.request.
32    """
33
34    def setUp(self):
35        #make_app({})
36        self._attach_locals()
37        # Load our default Pylons WSGI app and make g available
38        wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
39        app = paste.fixture.TestApp(wsgiapp)
40        response = app.get('/')
41        print response.g
42        print response.session
43        print response.c
44        print response.req.environ['ndgConfig']
45       
46        try:
47            response = self.app.get(url_for(controller='retrieve',uri='blah'))
48            fail('An exception should have been thrown here')
49        except Exception, e:
50            pass
51       
52        #g = app.globals
53        #app = ConfigMiddleware(app, conf)
54       
55        # YOUR MIDDLEWARE
56        # Put your own middleware here, so that any problems are caught by the error
57        # handling middleware underneath
58
59        #app = ndgMiddleware(app, g)
60
61        pylons.session._push_object({'user':'user_id'})
62        #response = self.app.get(url_for('/'))
63        #pylons.session._pop_object()
64       
65        self.registry=Registry()
66        self.registry.prepare()
67
68        self.context_obj=ContextObj()
69        self.registry.register(pylons.c, self.context_obj)
70
71        self.request_obj=WSGIRequest(dict(HTTP_HOST="nohost", environ=response.req.environ))
72        self.registry.register(pylons.request, self.request_obj) 
73        self.NI = NI.ndgInterface()
74
75
76    def testValidGetXML(self):
77        status, xml = self.NI.GetXML(VALID_DE_DOC)
78        self.assertNotEqual(None, xml)
79   
80if __name__ == '__main__':
81
82    unittest.main()
Note: See TracBrowser for help on using the repository browser.