source: ndgCommon/trunk/ndg/common/unittests/models/testcodetablerecord.py @ 5097

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

Update and extend test suite.

Line 
1'''
2A test class for the codetablerecord module.
3
4@author C Byrom, Tessella Feb 2009
5'''
6import unittest
7from xml.etree import cElementTree as ET
8from ndg.common.src.models.codetablerecord import CodeTableRecord
9from ndg.common.src.clients.http.vocabserverclient import VocabServerClient
10from ndg.common.src.models.vocablist import VocabList
11import ndg.common.unittests.testconstants as tc
12from ndg.common.src.models.myconfig import myConfig
13from ndg.common.src.models.ndgObject import ndgObject
14
15class testCodeTableRecord(unittest.TestCase):
16   
17    def setUp(self):
18        '''
19        set up data used in the tests.
20        '''
21        self.ctr = CodeTableRecord()
22        self.cf = myConfig(tc.NDG_CONFIG_FILE)
23        self.client = VocabServerClient(proxyServer = self.cf.get('DEFAULT','proxyServer'))
24
25    def testBasicLoad(self):
26        self.assertEquals('', self.ctr.listKey)
27        self.assertEquals('', self.ctr.entryKey)
28        self.assertEquals('', self.ctr.entryTerm)
29        self.assertEquals('', self.ctr.entryTermAbbr)
30        self.assertEquals('', self.ctr.entryTermDef)
31        self.assertEquals('', self.ctr.entryTermLastMod)
32
33       
34    def testFromET(self):
35        doc = self.client.readURL(self.client.GET_LIST_QUERY
36                                  %(self.client.path, tc.STANDARD_NAMES_LIST))
37        et = ET.fromstring(doc) 
38        records = et.findall('{%s}codeTableRecord' %ndgObject.VOCAB_NS)
39                                 
40        self.ctr.fromET(records[0])
41        self.assertEquals(tc.STANDARD_NAMES_LIST, self.ctr.listKey)
42        self.assertNotEquals('', self.ctr.entryKey)
43        self.assertNotEquals('', self.ctr.entryTerm)
44        # NB, the abbrev. term is generally blank for standard names atm
45        self.assertEquals('', self.ctr.entryTermAbbr)
46        self.assertNotEquals('', self.ctr.entryTermDef)
47        self.assertNotEquals('', self.ctr.entryTermLastMod)
48
49       
50    def testFromETCheckData(self):
51        doc = self.client.readURL(self.client.GET_LIST_QUERY
52                                  %(self.client.path, tc.STANDARD_NAMES_LIST))
53        et = ET.fromstring(doc)
54        vl = VocabList(et = et)
55                                 
56        self.ctr = vl.getVocabTermDataByEntryKey(tc.STANDARD_NAME_TERM)
57
58        self.assertEquals(tc.SN_MOD_DATE, self.ctr.entryTermLastMod, 
59                          'TEST DATA IS OUT OF DATE - SINCE IT REFERENCES A TERM THAT HAS ' + \
60                          'BEEN MODIFIED - UPDATE TO USE CURRENT DATA')
61
62        self.assertEquals(tc.STANDARD_NAMES_LIST, self.ctr.listKey)
63        self.assertEquals(tc.STANDARD_NAME_TERM, self.ctr.entryKey)
64        self.assertEquals(tc.SN_TERM_NAME, self.ctr.entryTerm)
65        self.assertEquals(tc.SN_ABBREV, self.ctr.entryTermAbbr)
66        self.assertEquals(tc.SN_DEF, self.ctr.entryTermDef)
67
68       
69    def testInitialiseWithET(self):
70        doc = self.client.readURL(self.client.GET_LIST_QUERY
71                                  %(self.client.path, tc.STANDARD_NAMES_LIST))
72        et = ET.fromstring(doc) 
73        records = et.findall('{%s}codeTableRecord' %ndgObject.VOCAB_NS)
74                                 
75        self.ctr = CodeTableRecord(et = records[0])
76        self.assertEquals(tc.STANDARD_NAMES_LIST, self.ctr.listKey)
77        self.assertNotEquals('', self.ctr.entryKey)
78        self.assertNotEquals('', self.ctr.entryTerm)
79        self.assertEquals('', self.ctr.entryTermAbbr)
80        self.assertNotEquals('', self.ctr.entryTermDef)
81        self.assertNotEquals('', self.ctr.entryTermLastMod)
82
83
Note: See TracBrowser for help on using the repository browser.