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

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

Extend the discovery ws client to allow access to the getListNames and
getList methods + add tests to these + extend search method to include
the orderBy and orderDirection parameters. NB, there is a bug in the
getListNames code which means that the getListNameRequest object
cannot be created, so the method cannot be invoked - presumably this
is an error due to the wsdl2python generation.

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.discovery.discoveryserviceclient import DiscoveryServiceClient
5from ZSI import FaultException
6
7class TestCase(unittest.TestCase):
8   
9    # NB, for the tests to work, this search term needs to return some results
10    VALID_TERM = 'temperature'
11    INVALID_TERM = 'xpabnl_________DFDSF'
12    def setUp(self):
13        '''
14        set up data used in the tests.
15        '''
16        self.client = DiscoveryServiceClient()
17
18    def OFFtestGetListNames(self):
19        # this method doesn't work owing to a problem with the generated code...
20        names = self.client.getListNames()
21
22    def testValidGetList(self):
23        names = self.client.getList('orderByFieldList')
24        self.assertTrue(len(names) > 0)
25
26    def testInvalidGetList(self):
27        self.assertRaises(FaultException, self.client.getList, 'orderByFieldListxx')
28   
29    def testSearch(self):
30        ''' Test fundamental search capability - should return ten documents'''
31        term='temperature'
32        howmany=10
33        docs = self.client.search(term,start=1,howmany=howmany)
34        self.assertEqual(howmany,len(docs))
35       
36    def testgetLabelledDocs(self):
37        ''' Test returning of labelled documents '''
38        term='dppp'
39        r=self.client.search(term)
40        output=self.client.getLabelledDocs()
41        self.assertNotEqual(len(output), 0)
42       
43    def testNoReturn(self):
44        ''' Tests a search return with (hopefully nothing to be found)'''
45        r=self.client.search(self.INVALID_TERM)
46        self.assertEqual(self.client.hits,0)
47   
48    def testGetDoc(self):
49        ''' Test obtaining a specific document '''
50        docs = self.client.search(self.VALID_TERM,start = 1,howmany = 1)
51        r=self.client.getDoc(docs[0])
52        self.assertNotEqual(r.find('<DIF'), -1)
53   
54    def testGetDocs(self):
55        ''' Test obtaining specific documents '''
56        docs = self.client.search(self.VALID_TERM,start = 1,howmany = 10)
57        r=self.client.getDocs(docs)
58        for key, val in r.items():
59            self.assertNotEqual(val.find('<DIF'), -1)
60           
61        self.assertTrue(r.keys() > 1)
62        docs = r.values()
63        self.assertNotEquals(docs[0], docs[1])
64       
65       
66    def testSequence(self):
67        ''' Tests that repeated searches work and can support zero responses in the middle '''
68        # this was a bug we found and needed a test case for
69        term='CD97' # hopefully just get a couple of hits for now.
70        r=self.client.search(term)
71        #if we uncomment this it used to break, and not if uncommented, now it seems ok...
72        output1=self.client.getLabelledDocs() 
73        r=self.client.search(self.INVALID_TERM)
74        self.assertEqual(self.client.hits,0)
75        term='CD97'
76        r=self.client.search(term)
77        self.assertEqual(self.client.getLabelledDocs(),output1)
78       
79    def testGet(self):
80        ''' Tests getting via uri components '''
81        docs = self.client.search(self.VALID_TERM,start = 1,howmany = 1)
82        doc = docs[0].split('.xml')[0]
83        n = no(doc)
84        x=self.client.getNDGDoc(n.repository, n.schema, n.localID,format='DC')
85        self.assertTrue(x.find('<oai_dc') > -1)
86       
87    def testFailedGet(self):
88        doc='abc'
89        try:
90            r=self.client.getDoc(doc)
91        except ValueError,e:
92            self.assertEqual(str(e),\
93                'Error during document retrieval: Document retrieval was successful but generated no results.')
94        except Exception,e:
95            self.fail(str(e))
96
97if __name__=="__main__":
98    unittest.main()
Note: See TracBrowser for help on using the repository browser.