Ignore:
Timestamp:
18/02/09 16:32:03 (11 years ago)
Author:
cbyrom
Message:

Add better error handling + add general keyword catcher to avoid
issues with slight differences between the search clients + extend test data and test suites - handling proxies better.

Location:
ndgCommon/trunk/ndg/common/unittests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/unittests/clients/xmldb/eXist/testatomclient.py

    r4978 r4997  
    2626        self.utils = tu(tc.EXIST_DBCONFIG_FILE) 
    2727         
    28         # NB, if running tests on a local db, feedparser, used by feedclient won't 
    29         # pick up any 'no_proxy' settings - so  
    30         if self.utils.host == 'localhost' and os.environ.has_key(utils.PROXY_KEY): 
    31             self.oldProxy = os.environ[utils.PROXY_KEY] 
    32             del os.environ[utils.PROXY_KEY] 
    33          
    3428 
    3529    def testInit(self): 
     
    132126    def testNotSetUpEXistDB(self): 
    133127        fileName = self.client.resources.xsd.keys()[0] + '.xsd' 
    134         pathName = dc.SCHEMAS_COLLECTION_PATH + fileName 
     128        pathName = dc.SCHEMAS_COLLECTION_PATH + '/' + fileName 
    135129        self.client.deleteDoc(pathName) 
    136130        self.assertEquals(True, self.client.isNewDoc(pathName)) 
     
    164158    def testPublishAtom(self): 
    165159        createdAtom = self.utils.createAtomInEXist(tc.xmlString) 
     160        self.createdAtoms.append(createdAtom.getFullPath()) 
    166161        createdAtom.state = AtomState.PUBLISHED_STATE 
    167162        providerCollection = dc.PROVIDER_FEED_PATH + createdAtom.ME.providerID 
    168         self.createdAtoms.append(createdAtom.getFullPath()) 
    169163        feed = self.client.feedClient.getAtomFeed(providerCollection) 
    170164         
     
    219213            # delete the test file, in case it has been used in a test 
    220214            self.utils.deleteDoc(path) 
    221         if self.oldProxy: 
    222             os.environ[utils.PROXY_KEY] = self.oldProxy 
    223215 
    224216             
  • ndgCommon/trunk/ndg/common/unittests/clients/xmldb/eXist/testfeedclient.py

    r4983 r4997  
    1212from ndg.common.unittests.testutils import testUtils as tu 
    1313import ndg.common.src.lib.utilities as utils 
     14from ndg.common.src.models.myconfig import myConfig 
     15 
    1416 
    1517class testFeedClient(unittest.TestCase): 
     
    2931        self.utils = tu(self.confFile) 
    3032        self.feedClient = self.utils.ac.feedClient 
     33        self.cf = myConfig(tc.NDG_CONFIG_FILE) 
     34        self.proxyServer = self.cf.get('DEFAULT','proxyServer') 
     35        if self.utils.host == 'localhost': 
     36            self.proxyServer = None 
    3137 
    32         # NB, if running tests on a local db, feedparser, used by feedclient won't 
    33         # pick up any 'no_proxy' settings - so 
    34         self.oldProxy = None  
    35         if self.utils.host == 'localhost' and os.environ.has_key(utils.PROXY_KEY): 
    36             self.oldProxy = os.environ[utils.PROXY_KEY] 
    37             del os.environ[utils.PROXY_KEY] 
    3838 
    3939    def testCreateAtomFeed(self): 
     
    6565    def testGetAtomFeed(self): 
    6666        try: 
    67             feed = self.feedClient.getAtomFeed(self.VALID_COLLECTION_PATH) 
     67            feed = self.feedClient.getAtomFeed(self.VALID_COLLECTION_PATH, 
     68                                               proxyServer = self.proxyServer) 
    6869            self.assertTrue(feed.feed.has_key('links')) 
    6970        except Exception, e: 
     71            import pdb 
     72            pdb.set_trace() 
    7073            self.fail("Should not have thrown an exception") 
    7174 
     
    138141            self.utils.deleteDoc(path) 
    139142 
    140         if self.oldProxy: 
    141             os.environ[utils.PROXY_KEY] = self.oldProxy 
    142  
    143143if __name__ == '__main__': 
    144144 
  • ndgCommon/trunk/ndg/common/unittests/lib/testgranulite.py

    r4970 r4997  
    77import unittest, logging 
    88from ndg.common.src.lib.granulite import granulite 
     9import ndg.common.src.clients.xmldb.abstractxmldbatomclient as ac 
    910import ndg.common.unittests.testconstants as tc 
    1011from ndg.common.unittests.testutils import testUtils as tu 
     
    5354            # firstly, create the DEs referenced in the granulite 
    5455            self.createGranuliteDEs() 
    55             atom = self.g.processGranulite() 
     56            atom = self.g.processGranulite(replaceAtom = True) 
    5657            self.assertNotEqual(None, atom) 
    57             self.assertEqual('-8.26171875', atom.minX) 
    58             self.assertEqual('-11.25', atom.minY) 
    59             self.assertEqual('-3.33984375', atom.maxX) 
    60             self.assertEqual('-17.578125', atom.maxY) 
    61  
     58            self.assertEqual(-9.140625, atom.minX) 
     59            self.assertEqual(-11.25, atom.maxY) 
     60            self.assertEqual(-3.1640625, atom.maxX) 
     61            self.assertEqual(-17.578125, atom.minY) 
     62 
     63        except Exception, e: 
     64            self.fail("An exception should not have been thrown") 
     65        finally: 
     66            if atom is not None: 
     67                self.utils.deleteDoc(atom.getFullPath()) 
     68            self.deleteGranuliteDEs() 
     69             
     70         
     71         
     72    def testDuplicateProcessGranulite(self): 
     73        atom = None 
     74        try: 
     75            # firstly, create the DEs referenced in the granulite 
     76            self.createGranuliteDEs() 
     77            atom = self.g.processGranulite(replaceAtom = False) 
     78            atom = self.g.processGranulite(replaceAtom = False, initialiseAtom = True) 
     79            self.fail("An exception should not have been thrown") 
     80 
     81        except ac.DuplicateError, de: 
     82            self.assertTrue(de.message.startswith('An atom with the specified ID')) 
    6283        except Exception, e: 
    6384            self.fail("An exception should not have been thrown") 
  • ndgCommon/trunk/ndg/common/unittests/testconstants.py

    r4991 r4997  
    3939TEST_FILE_PATH = TEST_COLLECTION_PATH + '/' + TEST_FILE_NAME 
    4040 
    41 EXIST_DB = 'localhost'#'chinook.badc.rl.ac.uk' 
     41#EXIST_DB = 'chinook.badc.rl.ac.uk' 
     42EXIST_DB = 'localhost' 
    4243PG_DBCONFIG_FILE = TEST_DATA_DIR + 'pg.config' 
    4344EXIST_DBCONFIG_FILE = TEST_DATA_DIR + 'exist.config' 
    4445INVALID_TEST_GRANULITE = TEST_DATA_DIR + 'example.granulite' 
    45 VALID_TEST_GRANULITE = TEST_DATA_DIR + 'example.granulite' 
     46VALID_TEST_GRANULITE = TEST_DATA_DIR + 'valid_example.granulite' 
    4647MOLES_FILE_NAME = TEST_DATA_DIR + 'dataent_TESTDATA.xml' 
    4748VALID_MOLES_ID = 'dataent_TESTDATA' 
  • ndgCommon/trunk/ndg/common/unittests/testdata/ndgDiscovery.config

    r4946 r4997  
    3030# 
    3131mailserver:       xxxoutbox.rl.ac.uk 
    32 metadataMaintainer: b.n.lawrence@rl.ac.uk 
     32metadataMaintainer: calum.byrom@gmail.com 
    3333repository:        %(server)s 
    34 tbrecipient:      b.n.lawrence@rl.ac.uk 
     34tbrecipient:      calum.byrom@gmail.com 
    3535 
    3636# The following should only be needed for debugging some parts of the code when running on sandboxes behind a firewall 
    37 proxyServer:      http://wwwcache3.rl.ac.uk:8080/ 
     37proxyServer:      http://wwwcache.rl.ac.uk:8080/ 
    3838disclaimer:        
    3939 
  • ndgCommon/trunk/ndg/common/unittests/testdata/valid_example.granulite

    r4969 r4997  
    1111# use format: local id | provider id 
    1212# NB, can specify multiple entities, on new lines, to link the granule to 
    13 DE_e7fb7c64-f8fe-11dd-b220-00e081470264 | neodc.nerc.ac.uk 
     13DE_ac3bdf56-b8e4-102c-8001-001e4f9f5ef4 | badc.nerc.ac.uk 
    1414#testcloudmap | badc.nerc.ac.uk 
    1515 
     
    9999coverage:: 
    100100# NB, can specify both timerange and spatialrange data 
    101 POLYGON((45.256 -110.45 46.46 -109.48 43.84 -109.86 45.256 -110.45)) 
     101POLYGON((-8.26171875 -11.25,-9.140625 -17.40234375,-3.33984375 -17.578125,-3.1640625 -12.65625,-8.26171875 -11.25)) 
    102102TIMERANGE(1996-4-19, 1998-9-22) 
Note: See TracChangeset for help on using the changeset viewer.