Changeset 4629


Ignore:
Timestamp:
15/12/08 09:38:26 (11 years ago)
Author:
cbyrom
Message:

Extend and update test suite for ndgUtils code - adding new package
to test lib code + new test data and improved test constants to
centralise test data.

Location:
exist/trunk/python/ndgutilstests
Files:
3 added
4 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgutilstests/models/testatom.py

    r4488 r4629  
    88from ndgUtils.models.Atom import Atom, Link 
    99from ndgUtils.vocabtermdata import VocabTermData as VTD 
    10 from ndgUtils.models.utilities import getTripleData 
     10from ndgUtils.lib.utilities import getTripleData 
     11import ndgutilstests.testconstants as tc 
    1112 
    1213class testatom(unittest.TestCase): 
    13     validParams = ['OZONE MIXING RATIO (PPB ) | http://vocab.ndg.nerc.ac.uk/blah | OZONE', \ 
    14                    'ERROR FLAG (OZONE MIXING RATIO ) | http://vocab.ndg.nerc.ac.uk/blah | ERROR', \ 
    15                    'HYDROGEN PEROXIDE PPBV | http://vocab.ndg.nerc.ac.uk/blah | HYDROGEN', 
    16                    'CADMIUM >1.21 M DIAMETER (PMOL M-3) INSTRUMENTAL DETECTION LIMIT 0.132 NM'] 
    17      
    18     messyParams = ['OZONE MIXING RATIO &  (PPB     ) | http://vocab.ndg.nerc.ac.uk/blah | ozone', \ 
    19                    'ERROR FLAG (OZONE MIXING > RATIO  ) | http://vocab.ndg.nerc.ac.uk/blah | error', \ 
    20                    'Hydrogen Peroxide < ppbv | http://vocab.ndg.nerc.ac.uk/blah | hydrogen &'] 
    21  
    22     summaryText = 'this is a summary of the granulite' 
    23  
    24     csmlFile = '/db/moles_support/csml/csml_famous_control_month.xml' 
    25      
    26     logo = '/blah/blah/a_logo_icon.png' 
    27      
    28     title = 'this is a test granulite' 
    29      
    30     datasetID = 'famous_control_month' 
    31      
    32     id = 'tag:localhost:5000,2008-09-17:/view/badc.nerc.ac.uk__ATOM__' + datasetID 
    33      
    34     atomName = 'http://localhost:5000/view/badc.nerc.ac.uk__ATOM__' + datasetID 
    35      
    36     name = 'famous_control_month.atom' 
    37      
    38     xmlString = '<entry xmlns:georss="http://www.georss.org/georss/10" xmlns:gml="http://www.opengis.net/gml" ' + \ 
    39         'xmlns:moles="http://ndg.nerc.ac.uk/schema/moles2beta">' + \ 
    40         '<id>' + id + '</id>' + \ 
    41         '<title>' + title + '</title>' + \ 
    42             '<link href="' + atomName + '" rel="self"/>' + \ 
    43             '<link href="/db/moles_support/granuleAtom/' + datasetID + '_granule.moles" rel="related"/>' + \ 
    44             '<link href="http://badc.nerc.ac.uk/a-real-wms-endpoint" rel="http://vocab.ndg.nerc.ac.uk/term/P201/1/GCMDU026" title="WMS"/>' + \ 
    45             '<link href="http://badc.nerc.ac.uk/alternate" rel="alternate" title="alternate page"/>' + \ 
    46             '<link href="' + logo + '" title="' + VTD.TERM_DATA[VTD.LOGO_TERM].title + '" rel="logo"/>' + \ 
    47             '<author><name>Tiddeman, David</name><uri>www.cb.org</uri></author>' + \ 
    48             '<contributor><name>Brian Bandy</name><uri>www.cb.org</uri></contributor>' + \ 
    49             '<moles:entity type="granule"><moles:molesISO><moles:responsibleParties>' + \ 
    50                 '<moles:responsibleParty><name>calum byrom</name><uri>www.cb.org</uri><role>Metadata maintainer</role></moles:responsibleParty>' + \ 
    51                 '<moles:responsibleParty><name>dom lowe</name><uri>www.badc.rl.ac.uk</uri><role>Metadata maintainer</role></moles:responsibleParty>' + \ 
    52                 '</moles:responsibleParties><moles:datasetLanguage>English</moles:datasetLanguage>' + \ 
    53                 '<moles:providerID>badc.nerc.ac.uk</moles:providerID>' + \ 
    54                 '<moles:metadataLanguage>English</moles:metadataLanguage>' + \ 
    55                 '</moles:molesISO>' + \ 
    56             '</moles:entity>' + \ 
    57             '<category term="OZONE" scheme="http://vocab.ndg.nerc.ac.uk/blah" label="OZONE MIXING RATIO (PPB )"/>' + \ 
    58             '<category term="ERROR" scheme="http://vocab.ndg.nerc.ac.uk/blah" label="ERROR FLAG (OZONE MIXING RATIO )"/>' + \ 
    59             '<category term="HYDROGEN" scheme="http://vocab.ndg.nerc.ac.uk/blah" label="HYDROGEN PEROXIDE PPBV"/>' + \ 
    60             '<category term="" scheme="" label="CADMIUM &gt;1.21 M DIAMETER (PMOL M-3) INSTRUMENTAL DETECTION LIMIT 0.132 NM"/>' + \ 
    61             '<summary>' + summaryText + '</summary>' + \ 
    62             '<content src="' + csmlFile + '" type="application/xml"/>' + \ 
    63             '<published>2008-06-17T10:15:19</published>' + \ 
    64             '<moles:temporalRange>2792-12-16 0:0:0.0/2992-11-16 0:0:0.0</moles:temporalRange>' + \ 
    65             '<georss:where><gml:Envelope><gml:lowerCorner>-90.0 -90.0</gml:lowerCorner><gml:upperCorner>360.0 5505.29980469</gml:upperCorner></gml:Envelope></georss:where>' + \ 
    66         '</entry>' 
    67          
    68     validAuthor = 'Tiddeman, David' 
    69     validAuthors = [validAuthor + ' | www.cb.org', \ 
    70                         'Brian Bandy | www.cb.org'] 
    71          
    72     validGranuleAuthors = ['calum byrom | www.cb.org | Metadata maintainer', \ 
    73                         'dom lowe | www.badc.rl.ac.uk | Metadata maintainer'] 
    74  
    75     validLinks = ['http://badc.nerc.ac.uk/a-real-wms-endpoint | WMS | http://vocab.ndg.nerc.ac.uk/term/P201/1/GCMDU026',\ 
    76                   'http://badc.nerc.ac.uk/alternate | alternate page | alternate', 
    77                   '/blah/blah/a_logo_icon.png | logo | LOGO - NOT YET SET UP', 
    78                   '/db/moles_support/granuleAtom/famous_control_month_granule.moles'] 
    79      
    80     minX = '-90.0' 
    81     minY = '-90.0' 
    82     maxX = '360.0' 
    83     maxY = '5505.29980469' 
    84     t1 = '2792-12-16 0:0:0.0' 
    85     t2 = '2992-11-16 0:0:0.0' 
    8614    VTD = VTD() 
    8715     
     
    10129        self.link2.rel = 'self' 
    10230 
    103          
    104          
     31                 
    10532    def testAddValidParameters(self): 
    106         self.atom.addParameters(self.validParams) 
    107         self.assertEqual(self.atom.parameters[0].term, getTripleData(self.validParams[0])[2]) 
    108         self.assertEqual(self.atom.parameters[1].term, getTripleData(self.validParams[1])[2]) 
    109         self.assertEqual(self.atom.parameters[2].term, getTripleData(self.validParams[2])[2]) 
     33        self.atom.addParameters(tc.validParams) 
     34        self.assertEqual(self.atom.parameters[0].term, getTripleData(tc.validParams[0])[2]) 
     35        self.assertEqual(self.atom.parameters[1].term, getTripleData(tc.validParams[1])[2]) 
     36        self.assertEqual(self.atom.parameters[2].term, getTripleData(tc.validParams[2])[2]) 
    11037         
    11138         
    11239    def testAddMessyParameters(self): 
    113         self.atom.addParameters(self.messyParams) 
     40        self.atom.addParameters(tc.messyParams) 
    11441        self.assertEqual(self.atom.parameters[0].term, 'OZONE') 
    11542        self.assertEqual(self.atom.parameters[1].term, 'ERROR') 
    116         self.assertEqual(self.atom.parameters[2].term, 'HYDROGEN &AMP;') 
     43        self.assertEqual(self.atom.parameters[2].term, 'HYDROGEN &amp;AMP;') 
    11744        self.assertEqual(self.atom.parameters[2].scheme, 'http://vocab.ndg.nerc.ac.uk/blah') 
    118         self.assertEqual(self.atom.parameters[2].label.lower(), 'Hydrogen Peroxide &lt; ppbv'.lower()) 
     45        self.assertEqual(self.atom.parameters[2].label.lower(), 'Hydrogen Peroxide &amp;lt; ppbv'.lower()) 
    11946         
    12047    def testFromString(self): 
    121         self.atom.fromString(self.xmlString) 
     48        self.atom.fromString(tc.xmlString) 
    12249         
    12350        self.assertNotEqual(self.atom.author, None) 
    124         self.assertEqual(self.validAuthor, self.atom.author.name) 
     51        self.assertEqual(tc.validAuthor, self.atom.author.name) 
    12552         
    12653        self.assertEqual(len(self.atom.parameters), 4) 
     
    12855        for param in self.atom.parameters: 
    12956            foundIt = False 
    130             for validParam in self.validParams: 
     57            for validParam in tc.validParams: 
    13158                if (validParam.startswith(param.term)): 
    13259                    foundIt = True 
     
    14774        for link in self.atom.relatedLinks: 
    14875            foundIt = False 
    149             for validLink in self.validLinks: 
     76            for validLink in tc.validLinks: 
    15077                if (validLink.startswith(link.href)): 
    15178                    foundIt = True 
     
    15481            self.assertEqual(True, foundIt, "Cound not find link (%s) in valid related link list" %link.href) 
    15582 
    156         self.assertEqual(self.atom.summary[0], self.summaryText) 
    157         self.assertEqual(self.atom.csmlFile, self.csmlFile) 
    158         self.assertEqual(self.atom.cdmlFile, None) 
    159         self.assertEqual(self.atom.title, self.title) 
    160         self.assertEqual(self.atom.getLogos()[0].href, self.logo) 
    161         self.assertEqual(self.atom.datasetID, self.datasetID) 
    162         self.assertEqual(self.atom.minX, self.minX) 
    163         self.assertEqual(self.atom.minY, self.minY) 
    164         self.assertEqual(self.atom.maxX, self.maxX) 
    165         self.assertEqual(self.atom.maxY, self.maxY) 
    166         self.assertEqual(self.atom.t1, self.t1) 
    167         self.assertEqual(self.atom.t2, self.t2) 
     83        self.assertEqual(tc.summaryText, self.atom.summary[0]) 
     84        self.assertEqual(tc.csmlFile, self.atom.csmlFile) 
     85        self.assertEqual(None, self.atom.cdmlFile) 
     86        self.assertEqual(tc.title, self.atom.title) 
     87        self.assertEqual(tc.logo, self.atom.getLogos()[0].href) 
     88        self.assertEqual(tc.datasetID, self.atom.datasetID) 
     89        self.assertEqual(tc.minX, self.atom.minX) 
     90        self.assertEqual(tc.minY, self.atom.minY) 
     91        self.assertEqual(tc.maxX, self.atom.maxX) 
     92        self.assertEqual(tc.maxY, self.atom.maxY) 
     93        self.assertEqual(tc.t1, self.atom.t1) 
     94        self.assertEqual(tc.t2, self.atom.t2) 
    16895         
    16996        # date when the granule was first ingested 
     
    17198            self.fail("No published date found")  
    17299 
    173         self.assertEqual(self.atom.atomName,self.name) 
     100        self.assertEqual(tc.name, self.atom.atomName) 
    174101         
    175102 
    176103    def testImportExport(self): 
    177         self.atom.fromString(self.xmlString) 
     104        self.atom.fromString(tc.xmlString) 
    178105        xml = self.atom.toPrettyXML() 
    179106        # NB, this is a naive test as ordering of sibling elements changes as does addition of new line characters 
     
    183110        inputs = { 
    184111                  'atomTypeID': VTD.ACTIVITY_TERM, 
    185                   'title': self.title 
     112                  'title': tc.title 
    186113                  } 
    187114        a = Atom(**inputs) 
    188         self.assertEqual(self.title, a.title) 
     115        self.assertEqual(tc.title, a.title) 
    189116        self.assertEqual(VTD.ACTIVITY_TERM, a.atomTypeID) 
    190117        self.assertEqual(VTD.TERM_DATA[VTD.ACTIVITY_TERM].title, a.atomTypeName) 
    191118 
    192119    def testaddUniqueRelatedLinks(self): 
    193         self.atom.fromString(self.xmlString) 
     120        self.atom.fromString(tc.xmlString) 
    194121        linkNo = len(self.atom.relatedLinks) 
    195122        self.atom.addUniqueRelatedLinks(self.link) 
     
    198125 
    199126    def testAddMultipeDifferentRelatedLinks(self): 
    200         self.atom.fromString(self.xmlString) 
     127        self.atom.fromString(tc.xmlString) 
    201128        linkNo = len(self.atom.relatedLinks) 
    202129        self.atom.addUniqueRelatedLinks(self.link) 
     
    210137 
    211138    def testAddMultipeDifferentRelatedLinksSimultaneously(self): 
    212         self.atom.fromString(self.xmlString) 
     139        self.atom.fromString(tc.xmlString) 
    213140        linkNo = len(self.atom.relatedLinks) 
    214141        link2 = copy.deepcopy(self.link) 
     
    225152 
    226153    def testAddMultipleUniqueRelatedLinks(self): 
    227         self.atom.fromString(self.xmlString) 
     154        self.atom.fromString(tc.xmlString) 
    228155        linkNo = len(self.atom.relatedLinks) 
    229156        self.atom.addUniqueRelatedLinks(self.link) 
     
    235162 
    236163    def testRemoveRelatedLinks(self): 
    237         self.atom.fromString(self.xmlString) 
     164        self.atom.fromString(tc.xmlString) 
    238165        linkNo = len(self.atom.relatedLinks) 
    239166        self.atom.addUniqueRelatedLinks(self.link) 
     
    245172 
    246173    def testRemoveMultipleRelatedLinks(self): 
    247         self.atom.fromString(self.xmlString) 
     174        self.atom.fromString(tc.xmlString) 
    248175        linkNo = len(self.atom.relatedLinks) 
    249176        link2 = copy.deepcopy(self.link) 
Note: See TracChangeset for help on using the changeset viewer.