source: ndgCommon/trunk/ndg/common/unittests/clients/ws/testdiscoveryserviceclient.py @ 4941

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/unittests/clients/ws/testdiscoveryserviceclient.py@4941
Revision 4941, 2.7 KB checked in by cbyrom, 11 years ago (diff)

Remove old ws search test and replace with one for new client - with
extended tests.

Line 
1import unittest, logging
2import ndg.common.unittests.testconstants as tc
3from ndg.common.src.models.ndgObject import ndgObject as no
4from ndg.common.src.clients.ws.discoveryserviceclient import DiscoveryServiceClient
5
6class TestCase(unittest.TestCase):
7   
8    def testSearch(self):
9        ''' Test fundamental search capability - should return ten documents'''
10        term='temperature'
11        s=DiscoveryServiceClient()
12        howmany=10
13        docs=s.search(term,start=1,howmany=howmany)
14        self.assertEqual(howmany,len(docs))
15       
16    def testgetLabelledDocs(self):
17        ''' Test returning of labelled documents '''
18        term='dppp'
19        s=DiscoveryServiceClient()
20        r=s.search(term)
21        output=s.getLabelledDocs()
22        self.assertNotEqual(len(output), 0)
23       
24    def testNoReturn(self):
25        ''' Tests a search return with (hopefully nothing to be found)'''
26        term='xpabnl'
27        s=DiscoveryServiceClient()
28        r=s.search(term)
29        self.assertEqual(s.hits,0)
30       
31    def testGetDoc(self):
32        ''' Test obtaining a specific document which had better exist '''
33        doc= tc.VALID_DISCOVERY_PROVIDER_ID + "__" + no.DIF_DOC_TYPE + \
34            "__" + tc.VALID_DISCOVERY_DOC_ID + ".xml"
35        s=DiscoveryServiceClient()
36        r=s.getDoc(doc)
37        self.assertNotEqual(r.find('<DIF'), -1)
38       
39    def testSequence(self):
40        ''' Tests that repeated searches work and can support zero responses in the middle '''
41        # this was a bug we found and needed a test case for
42        s=DiscoveryServiceClient()
43        term='CD97' # hopefully just get a couple of hits for now.
44        r=s.search(term)
45        #if we uncomment this it used to break, and not if uncommented, now it seems ok...
46        output1=s.getLabelledDocs() 
47        term='xpabnl'
48        r=s.search(term)
49        self.assertEqual(s.hits,0)
50        term='CD97'
51        r=s.search(term)
52        self.assertEqual(s.getLabelledDocs(),output1)
53       
54    def testGet(self):
55        ''' Tests getting via uri components '''
56       
57        (r,s,l)=tc.VALID_DISCOVERY_PROVIDER_ID, \
58            no.DIF_DOC_TYPE, tc.VALID_DISCOVERY_DOC_ID
59        ss=DiscoveryServiceClient()
60        x=ss.getNDGDoc(r,s,l,format='DC')
61        self.assertNotEqual(x.find('<oai_dc'), -1)
62       
63    def testFailedGet(self):
64        doc='abc'
65        s=DiscoveryServiceClient()
66        try:
67            r=s.getDoc(doc)
68        except ValueError,e:
69            self.assertEqual(str(e),\
70                'Error during document retrieval: Document retrieval was successful but generated no results.')
71        except Exception,e:
72            self.fail(str(e))
73
74if __name__=="__main__":
75    unittest.main()
Note: See TracBrowser for help on using the repository browser.