source: exist/trunk/python/ndgUtils/test_ndgObject.py @ 4167

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/ndgUtils/test_ndgObject.py@4167
Revision 4167, 3.8 KB checked in by cbyrom, 11 years ago (diff)

Pull out common constants into module level variables, to improve
consistency + re-use. Fix setting of some config file defaults.
Extend test suite + improve - add checks for config files and use
module level variables.

Line 
1"""
2Test cases for the ndgObject module
3
4NERC Data Grid Project
5"""
6__author__ = "B Lawrence"
7__date__ = "06/12/07"
8__copyright__ = "(C) 2007 STFC & NERC"
9__license__ = \
10"""This software may be distributed under the terms of the Q Public
11License, version 1.0 or later."""
12__contact__ = "b.n.lawrence@rl.ac.uk"
13__revision__ = '$Id: $'
14
15import unittest, os, logging
16import ndgObject as no
17from ndgObject import ndgObject
18import ConfigParser
19import testconstants as tc
20
21logging.basicConfig(level=logging.DEBUG,
22                        format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s')
23
24class TestCase(unittest.TestCase):
25    """ Tests as required """
26   
27    def setUp(self):
28       
29        f='test.config'
30        if not os.path.exists(f):
31            raise IOError("Error: config file, 'test.config' missing")
32        self.config=ConfigParser.ConfigParser()
33        self.config.read(f)
34       
35    def __assertions(self,uri):
36        self.assertEqual(tc.VALID_PROVIDER_ID,uri.repository)
37        self.assertEqual(no.NDGB0_DOC_TYPE,uri.schema)
38        self.assertEqual(tc.VALID_MOLES_DOC_ID,uri.localID)
39   
40    def testURI1(self):
41        ''' Testing the underscore ID type '''
42        uri= tc.VALID_PROVIDER_ID + '__' + no.NDGB0_DOC_TYPE + '__' + \
43            tc.VALID_MOLES_DOC_ID
44        n=ndgObject(uri)
45        self.__assertions(n)
46       
47    def testURI2(self):
48        ''' Testing the colon form of ID '''
49        uri=tc.VALID_PROVIDER_ID + ':' + no.NDGB0_DOC_TYPE + ':' + \
50            tc.VALID_MOLES_DOC_ID
51        n=ndgObject(uri)
52        self.__assertions(n)
53   
54    def notestURI3(self):
55        ''' Testing the default MOLES form of id '''
56        uri=tc.VALID_PROVIDER_ID + '/' + tc.VALID_MOLES_DOC_ID
57        n=ndgObject(uri)
58        self.__assertions(n)
59   
60    def testMakeURL(self):
61        ''' Tests making a url via a configuration file '''
62        uri=tc.VALID_PROVIDER_ID + '__' + no.NDGB0_DOC_TYPE + '__' + \
63            tc.VALID_MOLES_DOC_ID
64        n=ndgObject(uri)
65        n.schema='DIF'
66        n.setConfig(self.config)
67        self.assertTrue(n.gettable)
68        self.assertEqual(n.discoveryURL,'ndgbeta.badc.rl.ac.uk/view/badc.nerc.ac.uk__DIF__dataent_hadisst?outputSchema=')
69         
70    def testStubB(self):
71        ''' Test the url components of a stub-b '''
72        uri=tc.VALID_PROVIDER_ID + '__' + no.NDGB1_DOC_TYPE + '__' + \
73            tc.VALID_MOLES_DOC_ID
74        n=ndgObject(uri,self.config)
75        self.assertEqual(n.discoveryURL, 'ndgbeta.badc.rl.ac.uk/view/badc.nerc.ac.uk__NDG-B1__dataent_hadisst?outputSchema=')
76        self.assertEqual(n.URL, tc.VALID_REPOSITORY)
77        self.assertEqual(n.xmlURL, tc.VALID_REPOSITORY + '?format=raw')
78        self.assertEqual(n.printableURL, tc.VALID_REPOSITORY + '?format=xml')
79         
80    def testAtom(self):
81        ''' Test the url components of a stub-b '''
82        uri=tc.VALID_PROVIDER_ID + '__' + no.ATOM_DOC_TYPE + '__' + \
83            tc.VALID_ATOM_DOC_ID
84        n=ndgObject(uri,self.config)
85        self.assertEqual(n.discoveryURL, 'ndgbeta.badc.rl.ac.uk/view/badc.nerc.ac.uk__ATOM__dataent_11679938403412067?outputSchema=')
86        self.assertEqual(n.URL, tc.VALID_REPOSITORY)
87        self.assertEqual(n.xmlURL, tc.VALID_REPOSITORY + '?format=raw')
88        self.assertEqual(n.printableURL, tc.VALID_REPOSITORY + '?format=xml')
89
90    def testPMLuri(self):
91        '''Make sure the pml uris work in ndg object '''
92        uri='www.npm.ac.uk__NDG-B1__dataent.692'
93        n=ndgObject(uri,self.config)
94        self.assertEqual(n.URL, tc.VALID_REPOSITORY)
95
96    def testHorribleURI(self):
97        ''' tests use of '__' in localID '''
98        uri='repository__schema__something__else'
99        n=ndgObject(uri)
100        self.assertEqual(('repository','schema','something__else'),
101            (n.repository,n.schema,n.localID))
102       
103
104if __name__=="__main__":
105    unittest.main()
Note: See TracBrowser for help on using the repository browser.