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

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

Move VocabList? model to the VocabTermEditor? project, since this is
where it sits most comfortably. Adjust getList method of vocabserverclient to return its data in an elementtree instead of
VocabList? to avoid codebase pollution + move tests + update tests
to cope with loss of VocabList?.

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