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

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

Create new model, Deployment, to hold deployments info - for easy use
with templates. Delete the moles deployments code and implement code
with the new model + add containers in Atom - to allow deployments data
specified in links to be looked up.

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:datasetLanguage>English</moles:datasetLanguage> \
31         <moles:metadataLanguage>English</moles:metadataLanguage> \
32         <moles:created>' + createdDate + '</moles:created> \
33                </moles:molesISO> \
34                </moles:entity>'
35   
36    def setUp(self):
37        '''
38        set up data used in the tests.
39        '''
40        termURI = VTD().getTermCurrentVocabURL(VTD.GRANULE_TERM)
41        self.ME = ME.MolesEntity()
42        self.ME.abbreviation = self.ABBREVIATION
43        self.ME.providerID = self.PROVIDER_ID
44        self.ME.createdDate = self.createdDate
45       
46       
47    def testInit(self):
48        self.assertEqual(self.ME.abbreviation, self.ABBREVIATION)
49        self.assertEqual(self.ME.providerID, self.PROVIDER_ID)
50        self.assertEqual(self.ME.createdDate, self.createdDate)
51       
52       
53    def testFromString(self):
54        self.ME.fromString(self.xmlString)
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        if self.DEPLOYMENT_ID not in self.ME.deployments:
59            self.fail("Deployment not correctly added to moles entity")
60        deployment = self.ME.deployments[self.DEPLOYMENT_ID]
61        link = deployment.deploymentLinks[0]
62        self.assertEquals(link.url, self.CONTENT_URL)
63        self.assertEquals(link.vocabUrl, self.VOCAB_URL)
64        self.assertEquals(link.title, self.DEPLOYMENT_LINK_TITLE)
65
66
67if __name__ == '__main__':
68
69    unittest.main()
Note: See TracBrowser for help on using the repository browser.