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

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

Move generic 'httpify' method to utilities + adjust utilities method
to retrive default proxy to cope with standard formatting + set this
up on each call to urlopen - since different urls may use different
proxies + tidyup and extend test suite.

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        ndgRetrieve = NDGRetrieve(self.config)
48        status,xml = ndgRetrieve.retrieveDoc(uri)
49        self.assertEqual(status,1)
50        xml = ET.fromstring(xml)
51        d=DIF(xml.tree,et=1)
52        print d.entryID,[str(i) for i in d.services]
53
54
55if __name__=="__main__":
56    unittest.main()
57
58       
Note: See TracBrowser for help on using the repository browser.