source: exist/trunk/python/ndgUtils/test_ndgRetrieve.py @ 3147

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

eggable version including elementtree 1.3

Line 
1import ndgObject
2from ndgRetrieve import ndgRetrieve
3from xmlHandler2 import xmlHandler
4import ConfigParser
5import unittest
6
7class TestCase(unittest.TestCase):
8   
9    def setUp(self):
10       
11        f='test.config'
12        self.c=ConfigParser.ConfigParser()
13        self.c.read(f)
14           
15    def testEXIST(self):
16        ''' test link to local exist via xml rpc.
17                users will need to ensure that the document is actually
18                in your exist database! '''
19        doc='badc.nerc.ac.uk__NDG-B0__activity_activity_cwvc'
20        doc='neodc.nerc.ac.uk__NDG-B1__dataent_11924879127625221' #NCAVEO
21        uri=ndgObject.ndgObject(doc)
22        status,xml=ndgRetrieve(uri,self.c)
23        if not status: raise ValueError(xml)
24        x=xmlHandler(xml,string=1)
25        self.assertEqual(x.tree.tag,'dgMetadataRecord')
26       
27    def testNoB(self):
28        ''' Test that we get a sensible error if a NDG-B doc doesn't exist '''
29        doc='badc.nerc.ac.uk__NDG-B0__blah'
30        uri=ndgObject.ndgObject(doc)
31        status,xml=ndgRetrieve(uri,self.c)
32        if status: raise ValueError(' NDG-B0 [%s] should not exist [%s]'%(doc,xml) )
33       
34    def testXMLdif(self):
35        ''' Make sure we can recall at least one DIF properly '''
36        doc='neodc.nerc.ac.uk__DIF__NEODC_NEXTMAP'
37        doc='badc.nerc.ac.uk__DIF__dataent_11738019833217179'
38        uri=ndgObject.ndgObject(doc)
39        status,xml=ndgRetrieve(uri,self.c)
40        if status: s=str(xml)
41
42    def testRemoteGet(self):
43        ''' Attempt a remote get '''
44        doc='www.npm.ac.uk__NDG-B1__data_entity.363'
45        uri=ndgObject.ndgObject(doc)
46        status,xml=ndgRetrieve(uri,self.c,remote=1)
47        if not status: print xml #ie print error message if there is one!
48        self.assertEqual(status,1)
49       
50    def testNumSim(self):
51        '''Get a NumSim document '''
52        doc='badc.nerc.ac.uk__NumSim__HadAM2_CodeBase'
53        doc='badc.nerc.ac.uk__NumSim__HadGEM1_Control_Experiment'
54        uri=ndgObject.ndgObject(doc)
55        status,xml=ndgRetrieve(uri,self.c)
56        self.assertEqual(status,1)
57       
58if __name__=="__main__":
59
60    unittest.main()
Note: See TracBrowser for help on using the repository browser.