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

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

Add new tests and test constants.

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[1][0], 'rain')
35
36   
37    def testGetRelated2(self):
38        res = self.client.getRelated('snow')
39        self.assertEquals(res[1][0], 'snow')
40
41       
42    def testInvalidGetRelated(self):
43        res = self.client.getRelated('rainxxxxx')
44        self.assertEquals([], res[0])
45        self.assertEquals([], res[1])
46        self.assertEquals(3, len(res))
47       
48    def testGetList(self):
49        et = self.client.getList(tc.STANDARD_NAMES_LIST)
50        el = ET.ElementTree()
51        self.assertTrue(isinstance(et, type(el)))
52        self.assertEqual('false', et.findtext('{%s}error' %ndgObject.VOCAB_NS))
53        self.assertTrue(len(et.findall('{%s}codeTableRecord' %ndgObject.VOCAB_NS)) > 0)
54       
55    def testInvalidGetList(self):
56        self.assertRaises(IOError, self.client.getList, tc.STANDARD_NAMES_LIST + 'blah')
57       
58       
59    def testGetListInfo(self):
60        info = self.client.getListInfo(tc.STANDARD_NAMES_LIST)
61        self.assertEquals(tc.SN_LIST_MOD_DATE, info.listLastMod, 
62                          "The list used by this test has changed; update the values in testdata.py to match the new ones")
63        self.assertEquals(tc.STANDARD_NAMES_LIST, info.listKey)
64        self.assertEquals(tc.SN_LIST_DEF, info.listDefinition)
65        self.assertEquals(tc.SN_LIST_VERSION, info.listVersion)
66        self.assertEquals(tc.SN_LIST_LONG_NAME, info.listLongName)
67        self.assertEquals(tc.SN_LIST_SHORT_NAME, info.listShortName)
68       
69    def testSearchVocabTerm(self):
70        records = self.client.searchVocabTerm(tc.STANDARD_NAMES_LIST, tc.VALID_SEARCH_TERM)
71        self.assertTrue(len(records) > 0)
72        for record in records:
73            self.assertTrue(record.entryTerm.find(tc.VALID_SEARCH_TEXT) > -1)
74       
75    def testInvalidSearchVocabTerm(self):
76        records = self.client.searchVocabTerm(tc.STANDARD_NAMES_LIST, tc.INVALID_SEARCH_TERM)
77        self.assertEquals([], records)
78       
79       
80
Note: See TracBrowser for help on using the repository browser.