source: exist/trunk/python/ndgUtils/models/testmolesentity.py @ 4209

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/ndgUtils/models/testmolesentity.py@4209
Revision 4209, 4.2 KB checked in by cbyrom, 11 years ago (diff)

Move the Atom and MolesEntity? models, and their associated Utilities class
to the ndgUtils package to allow sensible re-use with the ows_server
stack + refactor references accordingly.

Line 
1'''
2A test class for the GranuleAtom module.
3
4C Byrom Jun 2008
5Tessella
6'''
7import unittest
8import MolesEntity as ME
9from ndgUtils.vocabtermdata import VocabTermData as VTD
10import datetime
11
12class testMolesEntity(unittest.TestCase):
13   
14    ABBREVIATION = "test_abbrev"
15    PROVIDER_ID = "test.badc.ac.uk"
16    DEPLOYMENT_ID = "123"
17    CONTENT_URL = "http://badc.nerc.ac.uk/browse/badc.nerc.ac.uk/1162914696789330.xml"
18    VOCAB_URL = "http://vocab.ndg.nerc.ac.uk/term/XXX/None/OBS"
19    DEPLOYMENT_LINK_TITLE = "test deployment title"
20    createdDate = datetime.datetime.today().strftime("%Y-%m-%dT%H_%M_%S")
21   
22    xmlString = '<moles:entity type="granule">\
23        <moles:molesISO> \
24        <moles:abbreviation>' + ABBREVIATION + '</moles:abbreviation> \
25        <moles:providerID>' + PROVIDER_ID + '</moles:providerID> \
26        <moles:responsibleParties> \
27            <moles:responsibleParty><name>calum byrom</name><uri>www.cb.org</uri><role>Metadata maintainer</role></moles:responsibleParty> \
28            <moles:responsibleParty><name>dom lowe</name><uri>www.badc.rl.ac.uk</uri><role>Metadata maintainer</role></moles:responsibleParty> \
29        </moles:responsibleParties> \
30        <moles:deployments> \
31            <moles:deployment id="' + DEPLOYMENT_ID + '"> \
32            <moles:startDate>' + createdDate + '</moles:startDate> \
33            <moles:endDate>' + createdDate + '</moles:endDate> \
34            <link href="' + CONTENT_URL + '" rel="' + VOCAB_URL + '" title="' + DEPLOYMENT_LINK_TITLE + '"></link> \
35         </moles:deployment> \
36         </moles:deployments> \
37         <moles:datasetLanguage>English</moles:datasetLanguage> \
38         <moles:metadataLanguage>English</moles:metadataLanguage> \
39         <moles:created>' + createdDate + '</moles:created> \
40                </moles:molesISO> \
41                </moles:entity>'
42   
43    def setUp(self):
44        '''
45        set up data used in the tests.
46        '''
47        termURI = VTD().getTermCurrentVocabURL(VTD.GRANULE_TERM)
48        self.ME = ME.MolesEntity()
49        self.ME.abbreviation = self.ABBREVIATION
50        self.ME.providerID = self.PROVIDER_ID
51        self.ME.createdDate = self.createdDate
52       
53       
54    def testInit(self):
55        self.assertEqual(self.ME.abbreviation, self.ABBREVIATION)
56        self.assertEqual(self.ME.providerID, self.PROVIDER_ID)
57        self.assertEqual(self.ME.createdDate, self.createdDate)
58       
59       
60    def testAddDeployment(self):
61        self.ME.addDeployment(self.DEPLOYMENT_ID, self.createdDate, self.createdDate)
62        if self.DEPLOYMENT_ID not in self.ME.deployments:
63            self.fail("Deployment not correctly added to moles entity")
64       
65        deployment = self.ME.deployments[self.DEPLOYMENT_ID]
66        self.assertEquals(deployment.startDate, self.createdDate)
67        self.assertEquals(deployment.endDate, self.createdDate)
68       
69       
70    def testAddDeploymentLink(self):
71        self.ME.addDeploymentLink(self.DEPLOYMENT_ID, self.CONTENT_URL, self.VOCAB_URL, self.DEPLOYMENT_LINK_TITLE)
72        if self.DEPLOYMENT_ID not in self.ME.deployments:
73            self.fail("Deployment not correctly added to moles entity")
74       
75        deployment = self.ME.deployments[self.DEPLOYMENT_ID]
76        link = deployment.deploymentLinks[0]
77        self.assertEquals(link.url, self.CONTENT_URL)
78        self.assertEquals(link.vocabUrl, self.VOCAB_URL)
79        self.assertEquals(link.title, self.DEPLOYMENT_LINK_TITLE)
80       
81       
82    def testFromString(self):
83        self.ME.fromString(self.xmlString)
84        self.assertEqual(self.ME.abbreviation, self.ABBREVIATION)
85        self.assertEqual(self.ME.providerID, self.PROVIDER_ID)
86        self.assertEqual(self.ME.createdDate, self.createdDate)
87        if self.DEPLOYMENT_ID not in self.ME.deployments:
88            self.fail("Deployment not correctly added to moles entity")
89        deployment = self.ME.deployments[self.DEPLOYMENT_ID]
90        link = deployment.deploymentLinks[0]
91        self.assertEquals(link.url, self.CONTENT_URL)
92        self.assertEquals(link.vocabUrl, self.VOCAB_URL)
93        self.assertEquals(link.title, self.DEPLOYMENT_LINK_TITLE)
94       
95
96
97
98if __name__ == '__main__':
99
100    unittest.main()
Note: See TracBrowser for help on using the repository browser.