source: ndgCommon/trunk/ndg/common/unittests/clients/http/testvocabserverclient.py @ 5374

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

Update vocab server 'getRelated' calls to include the required data
to allow proper invocation of services + adjust calls so that the
service is ran for both vocab terms + free text inputs and the results
are combined + extend tests.

Line 
1"""
2Test cases for the VocabServerClient class
3
4NERC Data Grid Project
5"""
6__author__ = "C Byrom - Tessella"
7__date__ = "17/02/09"
8__copyright__ = "(C) 2008 STFC & NERC"
9__license__ = \
10"""This software may be distributed under the terms of the Q Public
11License, version 1.0 or later."""
12__contact__ = "b.n.lawrence@rl.ac.uk"
13__revision__ = '$Id: $'
14
15import logging, unittest
16from xml.etree import cElementTree as ET
17from ndg.common.src.models.ndgObject import ndgObject
18from ndg.common.src.clients.http.vocabserverclient import VocabServerClient
19import ndg.common.unittests.testconstants as tc
20from ndg.common.src.models.myconfig import myConfig
21
22class TestVocabServerClient(unittest.TestCase): 
23
24    def setUp(self):
25        '''
26        set up data used in the tests.
27        '''
28        self.cf = myConfig(tc.NDG_CONFIG_FILE)
29        self.client = VocabServerClient(proxyServer = self.cf.get('DEFAULT','proxyServer'))
30
31   
32    def testGetRelated1(self):
33        res = self.client.getRelated('rain')
34        self.assertEquals(res[0][0], 'precipitation')
35
36   
37    def testGetRelated2(self):
38        res = self.client.getRelated('snow')
39        self.assertEquals(res[0][0], 'precipitation')
40
41   
42    def testGetRelated3(self):
43        res = self.client.getRelated('sno*')
44        self.assertEquals(res[0][0], 'precipitation')
45        self.assertEquals(res[2][0], 'anser caerulescens')
46
47   
48    def testGetRelated4(self):
49        res = self.client.getRelated('SNOW')
50        self.assertEquals(res[0][0], 'precipitation')
51   
52    def testGetRelated5(self):
53        res = self.client.getRelated('precipitation')
54        self.assertEquals(res[0][0], 'meteorology')
55        self.assertEquals(res[1][1], 'snow')
56
57       
58    def testInvalidGetRelated(self):
59        res = self.client.getRelated('rainxxxxx')
60        self.assertEquals([], res[0])
61        self.assertEquals([], res[1])
62        self.assertEquals([], res[2])
63        self.assertEquals(3, len(res))
64       
65    def testGetList(self):
66        et = self.client.getList(tc.STANDARD_NAMES_LIST)
67        el = ET.ElementTree()
68        self.assertTrue(isinstance(et, type(el)))
69        self.assertEqual('false', et.findtext('{%s}error' %ndgObject.VOCAB_NS))
70        self.assertTrue(len(et.findall('{%s}codeTableRecord' %ndgObject.VOCAB_NS)) > 0)
71       
72    def testInvalidGetList(self):
73        self.assertRaises(IOError, self.client.getList, tc.STANDARD_NAMES_LIST + 'blah')
74       
75       
76    def testGetListInfo(self):
77        info = self.client.getListInfo(tc.STANDARD_NAMES_LIST)
78        self.assertEquals(tc.SN_LIST_MOD_DATE, info.listLastMod, 
79                          "The list used by this test has changed; update the values in testdata.py to match the new ones")
80        self.assertEquals(tc.STANDARD_NAMES_LIST, info.listKey)
81        self.assertEquals(tc.SN_LIST_DEF, info.listDefinition)
82        self.assertEquals(tc.SN_LIST_VERSION, info.listVersion)
83        self.assertEquals(tc.SN_LIST_LONG_NAME, info.listLongName)
84        self.assertEquals(tc.SN_LIST_SHORT_NAME, info.listShortName)
85       
86    def testSearchVocabTerm(self):
87        records = self.client.searchVocabTerm(tc.STANDARD_NAMES_LIST, tc.VALID_SEARCH_TERM)
88        self.assertTrue(len(records) > 0)
89        for record in records:
90            self.assertTrue(record.entryTerm.find(tc.VALID_SEARCH_TEXT) > -1)
91       
92    def testInvalidSearchVocabTerm(self):
93        records = self.client.searchVocabTerm(tc.STANDARD_NAMES_LIST, tc.INVALID_SEARCH_TERM)
94        self.assertEquals([], records)
95       
96       
97
Note: See TracBrowser for help on using the repository browser.