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

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

Add code to allow ingest of docs when harvest button clicked - NB,
harvest completes first of all, then the ingest is ran asynchronously
since it can take some time. If the user has provided an email
address for the provider, the results are then mailed to them.

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()
22       
23    def testBasicConstructorWithKeyword(self):
24        h = Harvester(outDir = VALID_HARVEST_DIR)
25        self.assertEquals(VALID_HARVEST_DIR, h.outDir)
26       
27    def testBasicConstructor(self):
28        self.assertEquals(None, self.h.outDir)
29
30    def testInvalidInputHarvestRepository(self):
31        self.assertRaises(ValueError, self.h.harvestRepository, PROVIDER_INFO_1)
32
33    def testInvalidHarvestRepository(self):
34        self.h.JAVA_COMMAND = HARVEST_COMMAND
35        status, out, dir = self.h.harvestRepository(REPOSITORY_INFO_1, outDir = VALID_HARVEST_DIR)
36        self.assertFalse(status)
37        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)
38        self.assertEquals('tmp/rep2-ac-uk-DIF', dir)
39
40    def testHarvestRepository(self):
41        self.h.JAVA_COMMAND = HARVEST_COMMAND
42        status, out, dir = self.h.harvestRepository(VALID_REAL_REPOSITORY_INFO, outDir = VALID_HARVEST_DIR)
43        self.assertTrue(status)
44        self.assertTrue(out.find('Harvest of http://badc.nerc.ac.uk/badc_oai/provider is complete') > -1)
45        self.assertEquals('tmp/badc-nerc-ac-uk-dif', dir)
46   
47    def tearDown(self):
48        if exists(VALID_HARVEST_DIR):
49            cleanDir(VALID_HARVEST_DIR)
50            os.rmdir(VALID_HARVEST_DIR)
Note: See TracBrowser for help on using the repository browser.