source: mauRepo/MolesManager/trunk/cedaMoles/tests/cedamoles/mo/responsiblePartyInfo.py @ 8522

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/cedaMoles/tests/cedamoles/mo/responsiblePartyInfo.py@8522
Revision 8522, 8.2 KB checked in by mnagni, 8 years ago (diff)

Incomplete - # 22528: Migration of FAtCat Open Search link for HPFeld
 http://team.ceda.ac.uk/trac/ceda/ticket/22528
Incomplete - # 22534: Add versiojn number to the gui page
 http://team.ceda.ac.uk/trac/ceda/ticket/22534

Line 
1'''
2BSD Licence
3Copyright (c) 2012, Science & Technology Facilities Council (STFC)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification,
7are permitted provided that the following conditions are met:
8
9    * Redistributions of source code must retain the above copyright notice,
10        this list of conditions and the following disclaimer.
11    * Redistributions in binary form must reproduce the above copyright notice,
12        this list of conditions and the following disclaimer in the documentation
13        and/or other materials provided with the distribution.
14    * Neither the name of the Science & Technology Facilities Council (STFC)
15        nor the names of its contributors may be used to endorse or promote
16        products derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29Created on 2 Aug 2012
30
31@author: mnagni
32'''
33from cedaMoles.libs.migration.processor.commons import create_mo_responsible_party_info,\
34    create_ci_onlineresource, create_ci_address, create_ci_telephone,\
35    create_ci_contact, create_mo_organization
36from cedaMoles.MolesManager.codelist import getCLValue, MM_RoleValue
37from ea_model.moles3_4.utilities.mo_organisation import MO_Organisation
38from ea_model.moles3_4.utilities.mo_responsiblepartyinfo import MO_ResponsiblePartyInfo
39from cedaMoles.MolesManager.db.partyIndexes import PartyIndexes, createAssociateIndexes
40from cedaMoles.tests.cedamolestest import CedaMolesTest
41
42def _createResponsibleParty():
43    parties = []
44    i_linkage = 'http://badc.rl.ac.uk'
45    i_onlineResources = create_ci_onlineresource(linkage = i_linkage, name = 'British Atmospheric Data Centre Website')
46    i_address = create_ci_address(deliveryPoint = ['British Atmospheric Data Centre, STFC Rutherford Appleton Laboratory'], \
47                                 electronicMailAddress=['badc@rl.ac.uk'], postalCode='OX11 0QX', country='UK', city='Harwell Oxford')                                   
48    i_phone = create_ci_telephone(voice=['+44(0)1235 446432'])                                 
49    contact = create_ci_contact(phone=i_phone, address=i_address, onlineResource=i_onlineResources)                       
50    parties.append(create_mo_organization(name = "NERC - British Atmospheric Data Centre", contactInfo = [contact]))
51   
52    i_linkage = 'http://www.neodc.rl.ac.uk'
53    i_onlineResources = create_ci_onlineresource(linkage = i_linkage, name = 'NERC Earth Observation Data Centre website')
54    i_address = create_ci_address(deliveryPoint = ['NERC - Earth Observation Data Centre, STFC Rutherford Appleton Laboratory'], \
55                                 electronicMailAddress=['neodc@rl.ac.uk'], postalCode='OX11 0QX', country='UK', city='Harwell Oxford')                                   
56    i_phone = create_ci_telephone(voice=['+44(0)1235 446432'])                                 
57    contact = create_ci_contact(phone=i_phone, address=i_address, onlineResource=i_onlineResources)                       
58    parties.append(create_mo_organization(name = 'NERC - Earth Observation Data Centre', contactInfo = [contact]))       
59    return create_mo_responsible_party_info(getCLValue(MM_RoleValue.cl_publisher), parties)   
60
61class ResponsiblePartyInfoTest(CedaMolesTest):
62
63    def testCreationAndDelete(self):
64        '''
65        Creates and delete a MO_REsponsiblePartyInfo containing two parties.
66       
67        **Tests**
68         1. Creates and persists of the instance `RP`
69         1. Deletes `RP`
70         1. When `RP` is deleted the parties referred from `RP.party` ARE NOT deleted from the database
71        '''   
72        rp = _createResponsibleParty()
73        self.epbRepo.moles3EPB.persistInstance(rp)
74        self.assertTrue(len(rp.party) == 2, "Error")
75        self.assertEqual(rp.role, getCLValue(MM_RoleValue.cl_publisher), "Error")
76               
77        #stores the parties ids               
78        partyIds = []
79        for party in rp.party:
80            partyIds.append(party.id)
81       
82        # Delete the responsible party
83        #-----------------------------
84        rpid = getattr(rp, 'id')
85        self.epbRepo.moles3EPB.deleteInstance(rp, commit = True)
86        self.assertEqual(self.epbRepo.moles3EPB.search(MO_ResponsiblePartyInfo, rpid), None, "Error")
87        #-----------------------------
88       
89        # Verifies that the underlying parties has been deleted
90        #----------------------------------------------------
91        res = self.epbRepo.moles3EPB.search(MO_Organisation, partyIds[0])
92        self.assertTrue(res.id in partyIds, "Error")
93        res = self.epbRepo.moles3EPB.search(MO_Organisation, partyIds[1])
94        self.assertTrue(res.id in partyIds, "Error")
95        #----------------------------------------------------
96
97    def testPartyOrder(self):
98        '''
99        Creates a PartyIndexes
100       
101        **Tests**
102         1. Creates and try to persists a PartyIndexes with PartyIndexes.id = None
103         1. Creates and try to persists a PartyIndexes with PartyIndexes.id which
104            does not refer to any existing MO_REsponsiblePartyInfo
105         1. Creates and try to persists a PartyIndexes with PartyIndexes.id which
106            does refer to an brand new created MO_REsponsiblePartyInfo           
107         1. Creates and persists a MO_REsponsiblePartyInfo and verifies that
108            each entity in MO_REsponsiblePartyInfo.party has its own `party_order`                       
109         1. Delete a MO_REsponsiblePartyInfo and verifies that
110            the associated PartyIndexs is deleted too           
111           
112        '''
113        rp = _createResponsibleParty()               
114        pi = createAssociateIndexes(rp)
115       
116        #------------ Test 1 ---------------
117        pi.id = None
118        try:       
119            self.epbRepo.moles3EPB.persistInstance(pi)
120            self.fail("PartyIndexes.id cannot be None - PrimaryKey Error")
121        except:
122            self.epbRepo.moles3EPB.rollback()
123        #-----------------------------------
124       
125        #------------ Test 2 ---------------
126        pi.id = 100
127        try:
128            self.epbRepo.moles3EPB.persistInstance(pi)
129            self.fail("PartyIndexes.id has not associated MO_REsponsiblePartyInfo - ForeignKey Error")
130        except:
131            self.epbRepo.moles3EPB.rollback()
132        #-----------------------------------
133       
134        #------------ Test 3 ---------------
135        self.epbRepo.moles3EPB.persistInstance(rp)
136        pi.id = getattr(rp, 'id')
137        try:
138            self.epbRepo.moles3EPB.persistInstance(pi)
139            self.fail("PartyIndexes.id has not associated MO_REsponsiblePartyInfo - ForeignKey Error")
140        except Exception as e:
141            self.epbRepo.moles3EPB.rollback()
142        #-----------------------------------
143       
144        #------------ Test 4 ---------------
145        resId = getattr(rp, 'id')
146        self.epbRepo.moles3EPB.expunge(rp)
147        res = self.epbRepo.moles3EPB.search(MO_ResponsiblePartyInfo, resId)
148        for party in res.party:
149            self.assertTrue(party.party_order > -1, "MO_Party.party_order is not assigned - Error")
150        #-----------------------------------                                               
151       
152        #------------ Test 5 ---------------
153        self.epbRepo.moles3EPB.deleteInstance(res, commit = True)
154        pi = self.epbRepo.moles3EPB.search(PartyIndexes, resId)
155        self.assertTrue(pi is None, "PartyIndexes is not deleted after MO_ResponsiblePartyInfo is deleted - Error")
156        #-----------------------------------
157
158                       
Note: See TracBrowser for help on using the repository browser.