source: exist/trunk/python/ndgutilstests/test_ndgRetrieve.py @ 4488

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/ndgutilstests/test_ndgRetrieve.py@4488
Revision 4488, 4.0 KB checked in by cbyrom, 12 years ago (diff)

Move ndgUtils tests to their own test structure + fix various broken tests. Also move some utility methods from the MILK codebase to ndgUtils utility modules.

Line 
1"""
2Test cases for the ndgRetrieve module
3
4NERC Data Grid Project
5"""
6__author__ = "C Byrom - Tessella"
7__date__ = "03/09/08"
8__copyright__ = "(C) 2008 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
15from ndgUtils.ndgObject import ndgObject as no
16from ndgUtils.ndgRetrieve import ndgRetrieve
17from ndgUtils.xmlHandler2 import xmlHandler
18import unittest, os, logging, 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   
26    def setUp(self):
27       
28        f='test.config'
29        if not os.path.exists(f):
30            raise IOError("Error: config file, 'test.config' missing")
31        self.c=ConfigParser.ConfigParser()
32        self.c.read(f)
33           
34    def testRetrieveFromLocalEXIST(self):
35        ''' Test link to local exist via xml rpc.
36                users will need to ensure that the document is actually
37                in your exist database! '''
38        doc='badc.nerc.ac.uk__NDG-B0__activity_activity_cwvc'
39        #doc='neodc.nerc.ac.uk__NDG-B1__dataent_11924879127625221' #NCAVEO
40        uri=no(doc)
41        status,xml=ndgRetrieve(uri,self.c, discovery=0)
42        if not status: raise ValueError(xml)
43        x=xmlHandler(xml,string=1)
44        self.assertEqual(x.tree.tag,'{http://ndg.nerc.ac.uk/moles}dgMetadataRecord')
45       
46    def testNoB(self):
47        ''' Test that we get a sensible error if a NDG-B doc doesn't exist '''
48        doc='badc.nerc.ac.uk__NDG-B0__blah'
49        uri=no(doc)
50        status,xml=ndgRetrieve(uri,self.c, discovery=0)
51        if status: raise ValueError(' NDG-B0 [%s] should not exist [%s]'%(doc,xml) )
52       
53    def testRetrieveXMLdif(self):
54        ''' Make sure we can recall at least one DIF properly '''
55        doc= tc.VALID_PROVIDER_ID + "__" + no.DIF_DOC_TYPE + \
56            "__" + tc.VALID_MOLES_DOC_ID
57        uri=no(doc)
58        status,xml=ndgRetrieve(uri,self.c, discovery=0)
59        self.assertEqual(status,1)
60        self.assertNotEqual(xml.find(tc.VALID_MOLES_DOC_ID), -1)
61
62    def OFFtestRemoteGet(self):
63        ''' Attempt a remote get '''
64        # TODO: not sure what remote repository to use for this?
65        doc='www.npm.ac.uk__NDG-B1__data_entity.363'
66        uri=no(doc)
67        status,xml=ndgRetrieve(uri,self.c,remote=1, discovery=0)
68        if not status: print xml #ie print error message if there is one!
69        self.assertEqual(status,1)
70       
71    def testRetrieveNumSim(self):
72        '''Get a NumSim document '''
73        doc= tc.VALID_PROVIDER_ID + "__" + no.NUMSIM_DOC_TYPE + \
74            "__" + tc.VALID_NUMSIM_DOC_ID
75        uri=no(doc)
76        status,xml=ndgRetrieve(uri,self.c, discovery=0)
77        self.assertEqual(status,1)
78        self.assertNotEqual(xml.find(tc.VALID_NUMSIM_DOC_ID), -1)
79       
80    def testRetrieveAtom(self):
81        '''Get an atom document '''
82        doc= tc.VALID_PROVIDER_ID + "__" + no.ATOM_DOC_TYPE + \
83            "__" + tc.VALID_ATOM_DOC_ID
84        uri=no(doc)
85        status,xml=ndgRetrieve(uri,self.c, discovery=0)
86        self.assertEqual(status,1)
87        self.assertNotEqual(xml.find(tc.VALID_ATOM_DOC_ID), -1)
88       
89    def testRetrieveInvalidAtom(self):
90        '''Get an invalid atom document '''
91        doc= tc.VALID_PROVIDER_ID + "__" + no.ATOM_DOC_TYPE + \
92            "__" + tc.VALID_ATOM_DOC_ID + "blah"
93        uri=no(doc)
94        status,xml=ndgRetrieve(uri,self.c, discovery=0)
95        self.assertEqual(status,0)
96       
97    def testRetrieveAtomBackup(self):
98        '''Get a backed up atom document '''
99        doc= tc.VALID_PROVIDER_ID + "__" + no.ATOM_BACKUP_DOC_TYPE + \
100            "__" + tc.VALID_ATOM_DOC_ID
101        uri=no(doc)
102        status,xml=ndgRetrieve(uri,self.c, discovery=0)
103        self.assertEqual(status,1)
104        self.assertNotEqual(xml.find(tc.VALID_ATOM_DOC_ID), -1)
105       
106if __name__=="__main__":
107
108    unittest.main()
Note: See TracBrowser for help on using the repository browser.