source: mauRepo/MolesManager/trunk/tests/moles2gui/mo/responsiblePartyInfo.py @ 8477

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

Implemented adapters for TM_Instant, TM_Period and partially for CEDA_Observation

Added a Sphinx documentation folder

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 AN.__init__Y 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 23 Jul 2012
30
31@author: mnagni
32'''
33import unittest
34from moles2gui.creationFactory import assembleMO_ResponsiblePartyInfo
35from json import loads
36from MolesManager.views.moles2gui import encodeCedaMoles2Json,\
37    decodeJson2CedaMoles, dictByID, _encodeCedaMoles2Adapter
38from MolesManager.codelist import getCLValue, MM_RoleValue
39
40
41class Test(unittest.TestCase):
42
43
44    def setUp(self):
45        #molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, sql_echo=True, session_event_manager=EVENTS_DB)     
46        #moles3Factory = Moles3EPBFactory(molesDB)
47        #self.epbRepo = EPBRepo(moles3Factory.createEPB(), None, None)
48        pass
49
50    def tearDown(self):
51        pass
52
53    def testValidatResponsibleParty1(self):
54        rp = assembleMO_ResponsiblePartyInfo()
55        jrp = encodeCedaMoles2Json(rp)
56       
57        #----------------------- test ------------------------
58        ordParty = dictByID(rp.party)
59        decJson = loads(jrp)
60        for party in decJson['party']:
61            self.assertEqual(party['name'], ordParty[party['id']].name, "Error")
62        #-----------------------------------------------------
63        decodeJson2CedaMoles(jrp, cedaMoleObj = rp)
64
65    def testValidatResponsibleParty2(self):
66        # Creates a MO_ResponsibleParty and modifies
67        newrp = assembleMO_ResponsiblePartyInfo() 
68        if len(newrp.party[0].contactInfo) > 0:
69            newrp.party[0].contactInfo[0].address.electronicMailAddress.append('mau@mau.net')
70        else:
71            newrp.party[1].contactInfo[0].address.electronicMailAddress.append('mau@mau.net')
72           
73        # Converts to json to simulate a modified incoming json from the page
74        jrp = encodeCedaMoles2Json(newrp)
75       
76        # Creates a MO_Responsible party to simulate the original responsibleParty
77        oldrp = assembleMO_ResponsiblePartyInfo()
78               
79        #----------------------- test ------------------------
80        # Updates the "original" using the modified json
81        decodeJson2CedaMoles(jrp, cedaMoleObj = oldrp)
82        # Now the oldrp should look equal to newrp
83        for newparty in newrp.party:
84            for oldparty in  oldrp.party:
85                if oldparty.id == newparty.id:
86                    self.assertTrue(len(oldparty.contactInfo) ==  len(newparty.contactInfo), "Error")
87                    if len(oldparty.contactInfo) == 0:
88                        continue
89                    for email in oldparty.contactInfo[0].address.electronicMailAddress:
90                        self.assertTrue(email in newparty.contactInfo[0].address.electronicMailAddress, "Error")
91        #-----------------------------------------------------
92
93    def testVvalidatResponsibleParty3(self):
94        rp = assembleMO_ResponsiblePartyInfo(role = getCLValue(MM_RoleValue.cl_pointofcontact))
95        adapter = _encodeCedaMoles2Adapter(rp)
96       
97        #----------------------- test ------------------------
98        for party in adapter.party:
99            self.assertTrue(len(party.helpString) > 0, "Error")
100        #-----------------------------------------------------
101       
102        jrp = encodeCedaMoles2Json(rp)
103        decodeJson2CedaMoles(jrp, cedaMoleObj = rp)
Note: See TracBrowser for help on using the repository browser.