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

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

Add cmp method to DeploymentLink? to allow for object equality tests +
add new method to MolesEntity? to ensure that only unique deployment
links are added to the helper arrays + add new constructor input to
Atom to allow the content to be defined at creation.

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    def testAddDeploymentDetails(self):
97        a = ME.DeploymentLink('http://blah', VTD.TERM_DATA[VTD.ACTIVITY_TERM].vocabURL, title='fred')
98        b = ME.DeploymentLink('http://blah', VTD.TERM_DATA[VTD.ACTIVITY_TERM].vocabURL, title='fred')
99        c = ME.DeploymentLink('http://blah', VTD.TERM_DATA[VTD.ACTIVITY_TERM].vocabURL, title='freddy')
100       
101        self.ME._addDeploymentDetails(a)
102        self.assertEquals(self.ME.activities[0], a)
103       
104        self.ME._addDeploymentDetails(b)
105        self.assertEquals(len(self.ME.activities), 1)
106       
107        self.ME._addDeploymentDetails(c)
108        self.assertEquals(len(self.ME.activities), 2)
109       
110        self.ME._addDeploymentDetails(c)
111        self.assertEquals(len(self.ME.activities), 2)
112       
113
114
115if __name__ == '__main__':
116
117    unittest.main()
Note: See TracBrowser for help on using the repository browser.