source: ndgCommon/trunk/ndg/common/unittests/clients/xmldb/eXist/testfeedclient.py @ 5019

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/unittests/clients/xmldb/eXist/testfeedclient.py@5019
Revision 5019, 5.4 KB checked in by cbyrom, 11 years ago (diff)

Move deployments + DE lookup URLs for atoms to within Atom data model

  • to tidy up handling in MILK stack + tidy up a few tests.
Line 
1'''
2A test class for the FeedClient module.
3
4@author C Byrom, Tessella Jan 2009
5'''
6import unittest, time, os
7import ndg.common.src.clients.xmldb.eXist.dbconstants as dc
8from ndg.common.src.clients.xmldb.eXist.feedclient import FeedClient as feedClient, FeedClientError
9from ndg.common.src.models.Atom import Atom
10from ndg.common.src.models.vocabtermdata import VocabTermData as VTD
11import ndg.common.unittests.testconstants as tc
12from ndg.common.unittests.testutils import testUtils as tu
13import ndg.common.src.lib.utilities as utils
14from ndg.common.src.models.myconfig import myConfig
15
16
17class testFeedClient(unittest.TestCase):
18   
19    VALID_COLLECTION_PATH = dc.ATOM_COLLECTION_PATH
20    VALID_FILE = "tst.xml"
21    VALID_FILE_PATH = VALID_COLLECTION_PATH + VALID_FILE
22    INVALID_PATH = 'blah'
23    DUMMY_COLLECTION = VALID_COLLECTION_PATH + INVALID_PATH
24   
25    def setUp(self):
26        '''
27        set up data used in the tests.
28        '''
29        self.createdAtoms = []    # array to store paths to atoms created - in order to then delete them
30        self.confFile = tc.EXIST_DBCONFIG_FILE
31        self.utils = tu(self.confFile)
32        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
37
38
39    def testCreateAtomFeed(self):
40        try:
41            self.feedClient.createAtomFeed(self.VALID_COLLECTION_PATH, 
42                                          self.feedClient.TOPLEVEL_ATOM_FEED_TITLE)
43        except:
44            self.fail("Should not have thrown an exception")
45
46    def testCreateCorrectionsFeedEntry(self):
47        try:
48            self.feedClient.createCorrectionsFeedEntry('some title info',
49                                                       'some body info')
50        except:
51            self.fail("Should not have thrown an exception")
52
53
54
55    def testInvalidCollectionCreateAtomFeed(self):
56        try:
57            self.feedClient.createAtomFeed(self.INVALID_PATH, 
58                                          self.feedClient.TOPLEVEL_ATOM_FEED_TITLE)
59            self.fail("Should have thrown an exception")
60        except FeedClientError, fce:
61            self.assertTrue(fce.message.find('+not+found') > -1)
62        except Exception, e:
63            self.fail("Should have thrown a FeedClientError exception")
64
65    def testGetAtomFeed(self):
66        try:
67            feed = self.feedClient.getAtomFeed(self.VALID_COLLECTION_PATH,
68                                               proxyServer = self.proxyServer)
69            self.assertTrue(feed.feed.has_key('links'))
70        except Exception, e:
71            self.fail("Should not have thrown an exception (%s)" %e)
72
73    def testInvalidGetAtomFeed(self):
74        try:
75            feed = self.feedClient.getAtomFeed(self.INVALID_PATH)
76            self.fail("Should have thrown an exception")
77        except FeedClientError, fce:
78            self.assertTrue(fce.message.startswith(self.feedClient.FEED_ERROR_MSG) > -1)
79        except Exception, e:
80            self.fail("Should have thrown a FeedClientError exception")
81
82
83    def testCreateAtomFeedEntry(self):
84        try:
85            self.tidyUp = True
86            atom = self.utils.createAtom(tc.xmlString)
87            self.feedClient.createAtomFeedEntry(self.VALID_COLLECTION_PATH,
88                                                atom) 
89        except:
90            self.fail("Should not have thrown an exception")
91
92
93    def testCreateAtomFeedEntryWithIsDIFRecordKeyword(self):
94        try:
95            self.tidyUp = True
96            atom = self.utils.createAtom(tc.xmlString)
97            self.feedClient.createAtomFeedEntry(self.VALID_COLLECTION_PATH,
98                                                atom, isDIFRecord=True) 
99        except Exception, e:
100            self.fail("Should not have thrown an exception")
101
102
103    def testCreateAtomFeedEntryCheckFeedSize(self):
104        try:
105            feed = self.feedClient.getAtomFeed(self.VALID_COLLECTION_PATH)
106            self.assertTrue(feed.feed.has_key('links'))
107            entriesNo = len(feed.entries)
108            atom = self.utils.createAtom(tc.xmlString)
109            self.feedClient.createAtomFeedEntry(self.VALID_COLLECTION_PATH,
110                                                atom) 
111            feed = self.feedClient.getAtomFeed(self.VALID_COLLECTION_PATH)
112            self.assertEquals(entriesNo + 1, len(feed.entries))
113        except Exception, e:
114            self.fail("Should not have thrown an exception")
115
116
117    def testInvalidCollectionCreateAtomFeedEntry(self):
118        try:
119            atom = self.utils.createAtom(tc.xmlString)
120            self.feedClient.createAtomFeedEntry(self.INVALID_PATH,
121                                                atom) 
122            self.fail("Should have thrown an exception")
123        except FeedClientError, fce:
124            self.assertTrue(fce.message.startswith(self.feedClient.FEED_ERROR_MSG) > -1)
125        except Exception, e:
126            self.fail("Should have thrown a FeedClientError exception")
127
128
129    def testSetupBasicFeeds(self):
130        try:
131            feed = self.feedClient.setupBasicFeeds()
132        except:
133            self.fail("Should not have thrown an exception")
134       
135
136    def tearDown(self):
137        for path  in self.createdAtoms:
138            # delete the test file, in case it has been used in a test
139            self.utils.deleteDoc(path)
140
141if __name__ == '__main__':
142
143    unittest.main()
Note: See TracBrowser for help on using the repository browser.