source: ndgCommon/trunk/ndg/common/unittests/models/testdif.py @ 4944

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/unittests/models/testdif.py@4944
Revision 4944, 1.9 KB checked in by cbyrom, 11 years ago (diff)

Update tests for the models package - removing tests for redundant
code + adding new tests where needed + improve old tests to better
set up and remove the required test environment + remove dependencies
on xmlHandler2.

Line 
1import unittest
2from ndg.common.src.models.DIF import DIF
3from ndg.common.src.models.ndgObject import ndgObject
4from ndg.common.src.dal.ndgRetrieve import ndgRetrieve
5from ndg.common.src.models.myconfig import myConfig
6import ndg.common.unittests.testconstants as tc
7from xml.etree import ElementTree as ET
8
9class TestCase(unittest.TestCase):
10    """
11    Exercise the DIF model
12    """
13
14    # TODO: the 'examples' files are not available in the codebase... fix!
15    inputFile = 'examples/neodc.eg1.dif'
16    inputFile2= 'examples/bodc.eg2.edmed.dif'
17    inputFile2= 'examples/bodc.eg3.difChange.dif'
18    inputFile2= 'examples/ndg.noc.soton.ac.uk__DIF__NOCSDAT162.xml'
19
20   
21    def setUp(self):
22        ''' Load example config and DIF files for testing '''
23        f = file(tc.DIF_FILE)
24        xml = f.read()
25        f.close()
26        x=ET.fromstring(xml)
27        self.dif=DIF(x, et=1)
28        self.config=myConfig(tc.NDG_CONFIG_FILE)
29
30    def testEntries(self):
31        ''' Testing the DIF object can be loaded and some key entries extracted '''
32        print 'Entry ID [%s]'%self.dif.entryID
33        print 'Author [%s]'%self.dif.authors
34        print 'Abstract [%s]'%self.dif.abstract
35        print 'BBox [%s]'%self.dif.bbox.boxes
36   
37    def testParameters(self):
38        ''' Testing obtaining parameters from an edmed dif in original format '''
39        print 'Parameters %s'%self.dif.parameters
40       
41    def OFFtestDifficult(self):
42        # NB, need to have dif doc available for test
43        ''' Grab a test example from the internet and load it '''
44        #testURI='grid.bodc.nerc.ac.uk__DIF__EDMED1048008'
45        testURI='neodc.nerc.ac.uk__DIF__NEODC_NEXTMAP'
46        uri=ndgObject(testURI,config=self.config)
47        status,xml=ndgRetrieve(uri,self.config)
48        self.assertEqual(status,1)
49        xml = ET.fromstring(xml)
50        d=DIF(xml.tree,et=1)
51        print d.entryID,[str(i) for i in d.services]
52
53
54if __name__=="__main__":
55    unittest.main()
56
57       
Note: See TracBrowser for help on using the repository browser.