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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/ndgUtils/test_ndgObject.py@3125
Revision 3125, 2.1 KB checked in by lawrence, 12 years ago (diff)

ndgUtils taking shape with test cases etc

RevLine 
[3125]1import unittest
2from ndgObject import ndgObject
3import ConfigParser
4
5class TestCase(unittest.TestCase):
6    """ Tests as required """
7   
8    def setUp(self):
9       
10        f='test.config'
11        self.config=ConfigParser.ConfigParser()
12        self.config.read(f)
13   
14    def testURI1(self):
15        ''' Testing the underscore ID type '''
16        uri='badc.nerc.ac.uk__NDG-B0__local1'
17        n=ndgObject(uri)
18        self.__assertions(n)
19       
20    def __assertions(self,uri):
21        self.assertEqual('badc.nerc.ac.uk',uri.repository)
22        self.assertEqual('NDG-B0',uri.schema)
23        self.assertEqual('local1',uri.localID)
24       
25    def testURI2(self):
26        ''' Testing the colon form of ID '''
27        uri='badc.nerc.ac.uk:NDG-B0:local1'
28        n=ndgObject(uri)
29        self.__assertions(n)
30   
31    def notestURI3(self):
32        ''' Testing the default MOLES form of id '''
33        uri='badc.nerc.ac.uk/local1'
34        n=ndgObject(uri)
35        self.__assertions(n)
36   
37    def testMakeURL(self):
38        ''' Tests making a url via a configuration file '''
39        uri='badc.nerc.ac.uk__NDG-B0__local1'
40        n=ndgObject(uri)
41        n.schema='DIF'
42        n.setConfig(self.config)
43        if n.gettable:
44             print n.discoveryURL
45             self.assertEqual(n.discoveryURL[0:5],'http:')
46         
47    def testStubB(self):
48        ''' Test the url components of a stub-b '''
49        uri='badc.nerc.ac.uk__NDG-B1__dataent_chablis'
50        n=ndgObject(uri,self.config)
51        print n.discoveryURL
52        print n.URL
53        print n.xmlURL
54        print n.printableURL
55
56    def testPMLuri(self):
57        '''Make sure the pml uris work in ndg object '''
58        uri='www.npm.ac.uk__NDG-B1__dataent.692'
59        n=ndgObject(uri,self.config)
60        print n.URL
61
62    def testHorribleURI(self):
63        ''' tests __ in localID '''
64        uri='repository__schema__something__else'
65        n=ndgObject(uri)
66        self.assertEqual(('repository','schema','something__else'),
67            (n.repository,n.schema,n.localID))
68       
69
70if __name__=="__main__":
71    unittest.main()
Note: See TracBrowser for help on using the repository browser.