source: TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/tests/lib/testharvester.py @ 5255

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/tests/lib/testharvester.py@5255
Revision 5255, 2.2 KB checked in by cbyrom, 10 years ago (diff)

Extend OAI Info editor documentation and help pages + improve the
setup config + extend test suite and fix problem with setting
email addresses in providerinfo.

Line 
1'''
2A test class for the ProviderInfo module.
3
4@author C Byrom, Tessella Apr 2009
5'''
6import unittest, os
7from oai_info_editor.lib.harvester import Harvester
8from oai_info_editor.tests.testdata.testconstants import *
9from ndg.common.src.lib.fileutilities import *
10
11class testHarvester(unittest.TestCase):
12   
13    def setUp(self):
14        '''
15        set up data used in the tests.
16        '''
17        if os.path.isdir(VALID_HARVEST_DIR):
18            raise ValueError("Dir used for tests, '%s' already exists - exiting tests since this will delete this dir" %VALID_HARVEST_DIR)
19
20        setUpDir(VALID_HARVEST_DIR)
21        self.h = Harvester(VALID_MAIL_SERVER)
22       
23    def testBasicConstructorWithKeyword(self):
24        h = Harvester(VALID_MAIL_SERVER, outDir = VALID_HARVEST_DIR)
25        self.assertEquals(VALID_HARVEST_DIR, h.outDir)
26        self.assertEquals(VALID_MAIL_SERVER, h.mailServer)
27       
28    def testBasicConstructor(self):
29        self.assertEquals(None, self.h.outDir)
30        self.assertEquals(VALID_MAIL_SERVER, self.h.mailServer)
31
32    def testInvalidInputHarvestRepository(self):
33        self.assertRaises(ValueError, self.h.harvestRepository, PROVIDER_INFO_1)
34
35    def testInvalidHarvestRepository(self):
36        self.h.JAVA_COMMAND = HARVEST_COMMAND
37        status, out, dir = self.h.harvestRepository(REPOSITORY_INFO_1, outDir = VALID_HARVEST_DIR)
38        self.assertFalse(status)
39        self.assertEquals('Error: The request for data resulted in an invalid response from the provider. Error: Server returned HTTP response code: 400 for URL: http://rep2.ac.uk?verb=Identify', out)
40        self.assertEquals('%s/rep2-ac-uk-DIF' %VALID_HARVEST_DIR, dir)
41
42    def testHarvestRepository(self):
43        self.h.JAVA_COMMAND = HARVEST_COMMAND
44        status, out, dir = self.h.harvestRepository(VALID_REAL_REPOSITORY_INFO, outDir = VALID_HARVEST_DIR)
45        self.assertTrue(status)
46        self.assertTrue(out.find('Harvest of http://badc.nerc.ac.uk/badc_oai/provider is complete') > -1)
47        self.assertEquals('%s/badc-nerc-ac-uk-dif' %VALID_HARVEST_DIR, dir)
48   
49    def tearDown(self):
50        if exists(VALID_HARVEST_DIR):
51            cleanDir(VALID_HARVEST_DIR)
52            os.rmdir(VALID_HARVEST_DIR)
Note: See TracBrowser for help on using the repository browser.