source: TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/testfeeddocumentingester.py @ 4854

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/testfeeddocumentingester.py@4854
Revision 4854, 3.7 KB checked in by cbyrom, 11 years ago (diff)

Add new ingest script - to allow ingest of DIF docs from eXist hosted
atom feed. NB, this required restructure of original OAI harvester
to allow re-use of shared code - by abstracting this out into new class,
absstractdocumentingester.

Add new documentation and tidy up codebase removing dependencies where possible to simplify things.

Line 
1'''
2A test class for the feeddocumentingester module.
3
4@author C Byrom, Tessella Jan 2009
5'''
6import unittest, time, datetime
7from feeddocumentingester import FeedDocumentIngester
8from ndg.common.src.models.vocabtermdata import VocabTermData as VTD
9import ndgutilstests.testconstants as tc
10from ndgutilstests.testutils import testUtils as tu
11
12class testFeedDocumentIngester(unittest.TestCase):
13   
14    VALID_INTERVAL = 200.0
15    INVALID_INTERVAL = 'sausages'
16    VALID_DATE = '2000-12-02'
17    INVALID_DATE = '200x0-12-02'
18    VALID_FEED_URL = 'http://chinook.badc.rl.ac.uk:8080/exist/atom/content/db/atoms'
19   
20    def setUp(self):
21        '''
22        set up data used in the tests.
23        '''
24        self.utils = tu(tc.EXIST_DBCONFIG_FILE)
25        self.ingester = FeedDocumentIngester()
26        self.createdAtoms = []    # array to store paths to atoms created - in order to then delete them
27
28    def offtestSetPollInterval(self):
29        try:
30            self.ingester.setPollInterval(self.VALID_INTERVAL)
31            self.assertEquals(self.VALID_INTERVAL, self.ingester.pollInterval)
32        except:
33            self.fail("Should not have thrown an exception")
34
35    def offtestInvalidSetPollInterval(self):
36        try:
37            self.ingester.setPollInterval(self.INVALID_INTERVAL)
38            self.fail("Should have thrown an exception")
39        except Exception, e:
40            self.assertTrue(e.message.find('not a float or an int') > -1)
41
42    def offtestSetIngestFromDate(self):
43        try:
44            self.ingester.setIngestFromDate(self.VALID_DATE)
45            self.assertTrue(self.ingester.ingestFromDate < datetime.datetime.now())
46        except:
47            self.fail("Should not have thrown an exception")
48
49    def offtestInvalidSetIngestFromDate(self):
50        try:
51            self.ingester.setIngestFromDate(self.INVALID_DATE)
52            self.fail("Should have thrown an exception")
53        except Exception, e:
54            self.assertTrue(e.message.find('not in ISO8601 format') > -1)
55
56
57    def offtestIngestRESTfulAtomDocument(self):
58        try:
59            # firstly create doc in eXist to ensure there is an entry to ingest
60            # NB, for this test to work, we need use a data entity - since this
61            # is the only type of document that we'll ingest via the feed
62            atom = tu(tc.EXIST_DBCONFIG_FILE).createAtomInEXist(tc.xmlString)
63            self.createdAtoms.append(atom.getFullPath())
64
65            # ensure a feed client is available
66            self.ingester.setupPoll()
67
68            self.ingester.ingestRESTfulAtomDocument(atom.getFullPath())
69        except Exception, e:
70            print e.message
71            self.fail("Should not have thrown an exception")
72
73
74    def testProcessFeed(self):
75        try:
76            # firstly create doc in eXist to ensure there is an entry to ingest
77            # NB, for this test to work, we need use a data entity - since this
78            # is the only type of document that we'll ingest via the feed
79            atom = tu(tc.EXIST_DBCONFIG_FILE).createAtomInEXist(tc.xmlString)
80            self.createdAtoms.append(atom.getFullPath())
81            import pdb
82            pdb.set_trace()
83
84            # ensure a feed client is available
85            self.ingester.setupPoll()
86            self.ingester.setIngestFromDate(self.VALID_DATE)
87
88            self.ingester.processFeed(self.VALID_FEED_URL)
89        except Exception, e:
90            print e.message
91            self.fail("Should not have thrown an exception")
92           
93           
94    def tearDown(self):
95        for path in self.createdAtoms:
96            # delete the test file, in case it has been used in a test
97            self.utils.deleteAtomInExist(path)
98
99if __name__ == '__main__':
100
101    unittest.main()
Note: See TracBrowser for help on using the repository browser.