Changeset 4641 for exist


Ignore:
Timestamp:
15/12/08 14:23:40 (11 years ago)
Author:
cbyrom
Message:

Improve test suite, allowing referenced artefacts to be properly set
up and removed before and after tests + set global logging + adjust
file references + add required data files + simplify and fix some tests.

Location:
exist/trunk/python/ndgutilstests
Files:
3 added
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgutilstests/lib/testatomvalidator.py

    r4630 r4641  
    99import ndgutilstests.testconstants as tc 
    1010from ndgUtils.models.Atom import Atom 
    11 import ndgUtils.lib.existdbclient as dbc 
    1211from ndgUtils.vocabtermdata import VocabTermData as VTD 
    1312 
     
    2524        self.v.setAtom(self.atom) 
    2625         
    27     def offtestSetNoneAtom(self): 
     26    def testSetNoneAtom(self): 
    2827        self.assertRaises(ValueError, self.v.setAtom, None) 
    2928         
    30     def offtestSetDodgyAtom(self): 
     29    def testSetDodgyAtom(self): 
    3130        self.assertRaises(ValueError, self.v.setAtom, []) 
    3231         
    33     def offtestSetAtom(self): 
     32    def testSetAtom(self): 
    3433        try: 
    3534            self.v.setAtom(self.atom) 
     
    3736            self.fail("An exception shouldn't have been thrown") 
    3837             
    39     def offtestValidateAtom(self): 
     38    def testValidateAtom(self): 
    4039        try: 
    4140            errors = self.v.validateAtom() 
     
    4443 
    4544 
    46     def offtestValidateLinks(self): 
     45    def testValidateLinks(self): 
    4746        try: 
    4847            self.v._AtomValidator__validateLinks() 
     
    9897            self.fail("An exception shouldn't have been thrown") 
    9998             
    100     def offtestInvalidValidateAtom(self): 
     99    def testInvalidValidateAtom(self): 
    101100        self.__setInvalidAtom() 
    102101        try: 
     
    106105            self.assertEqual(ValidationError.BASE_MESSAGE, e.message) 
    107106            self.assertNotEqual(None, e.unpack_errors()) 
    108             self.assertTrue(isinstance(self.v.errors, e.unpack_errors())) 
     107            self.assertTrue(isinstance(self.v.errors, dict)) 
     108            if not self.v.errors: 
     109                self.fail("Validation errors should have been detected") 
    109110        except Exception, e: 
    110111            self.fail("A validation exception should have been thrown") 
    111112 
    112113 
    113     def offtestInvalidValidateLinks(self): 
     114    def testInvalidValidateLinks(self): 
    114115        self.__setInvalidAtom() 
    115116        try: 
     
    141142            self.assertNotEquals(None, self.v.errors) 
    142143            self.assertTrue(isinstance(self.v.errors, dict)) 
    143             print self.v.errors 
    144144            if not self.v.errors: 
    145145                self.fail("Schema validation errors should have been detected") 
     
    154154            self.assertNotEquals(None, self.v.errors) 
    155155            self.assertTrue(isinstance(self.v.errors, dict)) 
    156             print self.v.errors 
    157156            if not self.v.errors: 
    158157                self.fail("Atom content errors should have been detected") 
     
    168167            self.assertNotEquals(None, self.v.errors) 
    169168            self.assertTrue(isinstance(self.v.errors, dict)) 
    170             print self.v.errors 
    171169            if not self.v.errors: 
    172170                self.fail("Unicode errors should have been detected") 
     171            self.assertTrue(self.v.errors['title'].startswith(self.v.ILLEGAL_UNICODE_MESSAGE)) 
    173172        except Exception, e: 
    174173            self.fail("A validation exception should have been thrown") 
  • exist/trunk/python/ndgutilstests/lib/testgranulite.py

    r4630 r4641  
    55Tessella 
    66''' 
    7 import unittest 
     7import unittest, logging 
     8logging.basicConfig(level=logging.DEBUG,\ 
     9                    format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s') 
     10 
    811from ndgUtils.lib.granulite import granulite 
    912from utilities import db_funcs 
     
    2225        self.g = granulite(tc.TEST_GRANULITE) 
    2326 
    24     def offtestProcessGranulite(self): 
     27    def testProcessGranulite(self): 
    2528        try: 
    2629            atom = self.g.processGranulite() 
     
    3033            self.assertEqual('-3.33984375', atom.maxX) 
    3134            self.assertEqual('-17.578125', atom.maxY) 
    32         except: 
     35            atomPath = atom.getDefaultCollectionPath() + atom.atomName 
     36            self.dbc = dbc.eXistDBClient(configFile = tc.DBCONFIG_FILE, setUpDB = True) 
     37            self.dbc.deleteEXistFile(atomPath) 
     38        except Exception, e: 
     39            import pdb 
     40            pdb.set_trace() 
    3341            self.fail("An exception should not have been thrown") 
    3442         
    35     def offtestProcessCSMLOrCDMLFile(self): 
     43    def testProcessCSMLOrCDMLFile(self): 
    3644        try: 
    3745            atom = self.g.processCSMLOrCDMLFile() 
     
    4149         
    4250         
    43     def offtestGetSectionName(self): 
     51    def testGetSectionName(self): 
    4452        sectionName = "parameters" 
    4553        foundName = self.g._granulite__getSectionName(sectionName + "::") 
    4654        self.assertEqual(sectionName, foundName) 
    4755         
    48     def offtestGetInvalidSectionName(self): 
     56    def testGetInvalidSectionName(self): 
    4957        sectionName = "parameters" 
    5058        foundName = self.g._granulite__getSectionName(sectionName) 
    5159        self.assertEqual(None, foundName) 
    5260         
    53     def offtestInitialiseGranule(self): 
     61    def testInitialiseGranule(self): 
    5462        self.g._granulite__initialiseGranule() 
    5563        self.assertNotEqual(None, self.g._atom) 
     
    6068         
    6169 
    62     def offtestGetGranuliteDetails(self): 
     70    def testGetGranuliteDetails(self): 
    6371        details = self._initGranule() 
    6472        self.assertEqual(tc.GRANULITE_TITLE, details['granule_info'][0].split('|')[2].strip()) 
     
    6674        self.assertEqual(tc.GRANULITE_CDML_DATASETID, details['cdml_file'][0].split('|')[1].strip()) 
    6775 
    68     def offtestApplyCoreGranuliteDetails(self): 
     76    def testApplyCoreGranuliteDetails(self): 
    6977        details = self._initGranule() 
    7078        self.g.ingestGranuliteFiles = False # don't worry about reading in CSML/CDML data 
     
    7482        self.assertEqual(tc.GRANULITE_PROVIDER_ID, self.g._atom.ME.providerID) 
    7583 
    76     def offtestApplyGranuliteDetails(self): 
     84    def testApplyGranuliteDetails(self): 
    7785        details = self._initGranule() 
    7886        self.g.ingestGranuliteFiles = False # don't worry about reading in CSML/CDML data 
     
    8896         
    8997 
    90     def offtestExtractSpatialData(self): 
     98    def testExtractSpatialData(self): 
    9199        self._initGranule() 
    92100        self.g._extractSpatialData("POLYGON((-8.26171875 -11.25,-9.140625 -17.40234375,-3.33984375 -17.578125,-3.1640625 -12.65625,-8.26171875 -11.25))") 
     
    97105 
    98106 
    99     def offtestUpdateDataEntity(self): 
     107    def testUpdateDataEntity(self): 
    100108        # firstly create a DE to use 
    101109        atom = Atom(VTD.DE_TERM) 
  • exist/trunk/python/ndgutilstests/lib/testutilities.py

    r4630 r4641  
    118118        self.assertEqual((w,e),(10.,20.)) 
    119119  
    120  
    121     def testNormaliseLongitude(self): 
    122         w,e=1,359 
    123         w,e=normaliseLongitude(w,e) 
    124         self.assertEqual((w,e),(-179.,179.)) 
    125         w,e=190,200 
    126         w,e=normaliseLongitude(w,e) 
    127         self.assertEqual((w,e),(-170.,-160.)) 
    128         w,e=10,20 
    129         w,e=normaliseLongitude(w,e) 
    130         self.assertEqual((w,e),(10.,20.)) 
    131          
    132120if __name__=="__main__": 
    133121    unittest.main() 
  • exist/trunk/python/ndgutilstests/models/testatom.py

    r4629 r4641  
    5050        self.assertNotEqual(self.atom.author, None) 
    5151        self.assertEqual(tc.validAuthor, self.atom.author.name) 
    52          
    53         self.assertEqual(len(self.atom.parameters), 4) 
     52        self.assertEqual(3, len(self.atom.parameters)) 
    5453         
    5554        for param in self.atom.parameters: 
     
    9190        self.assertEqual(tc.maxX, self.atom.maxX) 
    9291        self.assertEqual(tc.maxY, self.atom.maxY) 
    93         self.assertEqual(tc.t1, self.atom.t1) 
    94         self.assertEqual(tc.t2, self.atom.t2) 
     92        self.assertEqual(tc.T1, self.atom.t1) 
     93        self.assertEqual(tc.T2, self.atom.t2) 
    9594         
    9695        # date when the granule was first ingested 
  • exist/trunk/python/ndgutilstests/noseTests.py

    r4488 r4641  
    1313__revision__ = '$Id: $' 
    1414 
    15 import nose 
     15import nose, logging 
     16logging.basicConfig(level=logging.DEBUG,\ 
     17                    format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s') 
     18 
    1619nose.main() 
  • exist/trunk/python/ndgutilstests/test_DocumentRetrieve.py

    r4488 r4641  
    1818import testconstants as tc 
    1919from ndgUtils.ndgObject import ndgObject as no 
     20import ndgUtils.lib.existdbclient as dbc 
    2021 
    2122logging.basicConfig(level=logging.DEBUG, 
     
    2324 
    2425class TestCase(unittest.TestCase):  
     26 
     27    def setUp(self): 
     28        ''' 
     29        set up data used in the tests. 
     30        ''' 
     31 
     32 
     33    def tearDown(self): 
     34        ''' 
     35        tidy up any artifacts from the tests 
     36        ''' 
     37 
    2538     
    2639    def testHTTPget(self): 
     
    90103                         
    91104    def testGetAtom(self): 
     105        self.createdAtom = tc.createAtomInEXist(tc.xmlString) 
     106        self.dbc = dbc.eXistDBClient(configFile = tc.DBCONFIG_FILE, setUpDB = True) 
    92107        dr = DocumentRetrieve.DocumentRetrieve(tc.VALID_REPOSITORY) 
    93108        doc = dr.get(tc.VALID_PROVIDER_ID, no.ATOM_DOC_TYPE, \ 
    94                      tc.VALID_ATOM_DOC_ID, targetCollection = ATOM_COLLECTION) 
    95         self.assertNotEquals(doc.find(tc.VALID_ATOM_DOC_ID), -1) 
     109                     self.createdAtom.datasetID, targetCollection = ATOM_COLLECTION) 
     110        self.assertNotEquals(doc.find(self.createdAtom.datasetID), -1) 
     111        atomPath = self.createdAtom.getDefaultCollectionPath() + self.createdAtom.atomName 
     112        self.dbc.deleteEXistFile(atomPath) 
    96113                         
    97114    def testGetInvalidAtom(self): 
     
    101118                         
    102119    def testGetAtomBackup(self): 
     120        self.createdAtom = tc.createAtomInEXist(tc.xmlString) 
     121        self.dbc = dbc.eXistDBClient(configFile = tc.DBCONFIG_FILE, setUpDB = True) 
     122        self.createdAtom = tc.createAtomInEXist(tc.xmlString) 
    103123        dr = DocumentRetrieve.DocumentRetrieve(tc.VALID_REPOSITORY) 
    104124        doc = dr.get(tc.VALID_PROVIDER_ID, no.ATOM_BACKUP_DOC_TYPE, \ 
    105                      tc.VALID_ATOM_DOC_ID, targetCollection = ATOM_BACKUP_COLLECTION) 
    106         self.assertNotEquals(doc.find(tc.VALID_ATOM_DOC_ID), -1) 
     125                     self.createdAtom.datasetID, targetCollection = ATOM_BACKUP_COLLECTION) 
     126        self.assertNotEquals(doc.find(self.createdAtom.datasetID), -1) 
     127        atomPath = self.createdAtom.getDefaultCollectionPath() + self.createdAtom.atomName 
     128        self.dbc.deleteEXistFile(atomPath) 
    107129         
  • exist/trunk/python/ndgutilstests/test_ndgRetrieve.py

    r4488 r4641  
    1818import unittest, os, logging, ConfigParser 
    1919import testconstants as tc 
     20import ndgUtils.lib.existdbclient as dbc 
    2021 
    2122logging.basicConfig(level=logging.DEBUG, 
     
    8081    def testRetrieveAtom(self): 
    8182        '''Get an atom document ''' 
     83        self.createdAtom = tc.createAtomInEXist(tc.xmlString) 
     84        self.dbc = dbc.eXistDBClient(configFile = tc.DBCONFIG_FILE, setUpDB = True) 
     85        self.createdAtom = tc.createAtomInEXist(tc.xmlString) 
    8286        doc= tc.VALID_PROVIDER_ID + "__" + no.ATOM_DOC_TYPE + \ 
    83             "__" + tc.VALID_ATOM_DOC_ID 
     87            "__" + self.createdAtom.datasetID 
    8488        uri=no(doc) 
    8589        status,xml=ndgRetrieve(uri,self.c, discovery=0) 
    8690        self.assertEqual(status,1) 
    87         self.assertNotEqual(xml.find(tc.VALID_ATOM_DOC_ID), -1) 
     91        self.assertNotEqual(xml.find(self.createdAtom.datasetID), -1) 
     92        atomPath = self.createdAtom.getDefaultCollectionPath() + self.createdAtom.atomName 
     93        self.dbc.deleteEXistFile(atomPath) 
    8894         
    8995    def testRetrieveInvalidAtom(self): 
     
    97103    def testRetrieveAtomBackup(self): 
    98104        '''Get a backed up atom document ''' 
     105        self.createdAtom = tc.createAtomInEXist(tc.xmlString) 
     106        self.dbc = dbc.eXistDBClient(configFile = tc.DBCONFIG_FILE, setUpDB = True) 
     107        self.createdAtom = tc.createAtomInEXist(tc.xmlString) 
    99108        doc= tc.VALID_PROVIDER_ID + "__" + no.ATOM_BACKUP_DOC_TYPE + \ 
    100             "__" + tc.VALID_ATOM_DOC_ID 
     109            "__" + self.createdAtom.datasetID 
    101110        uri=no(doc) 
    102111        status,xml=ndgRetrieve(uri,self.c, discovery=0) 
    103112        self.assertEqual(status,1) 
    104         self.assertNotEqual(xml.find(tc.VALID_ATOM_DOC_ID), -1) 
     113        self.assertNotEqual(xml.find(self.createdAtom.datasetID), -1) 
     114        atomPath = self.createdAtom.getDefaultCollectionPath() + self.createdAtom.atomName 
     115        self.dbc.deleteEXistFile(atomPath) 
    105116         
    106117if __name__=="__main__": 
  • exist/trunk/python/ndgutilstests/testconstants.py

    r4628 r4641  
    1919DBCONFIG_FILE = "exist.config" 
    2020 
    21 TEST_GRANULITE = '..\\testdata\\example.granulite' 
     21TEST_GRANULITE = '../testdata/example.granulite' 
    2222GRANULITE_TITLE = 'this is a new test granulite' 
    2323GRANULITE_TIME_AXIS = 'time0' 
     
    5959title = 'this is a test granulite' 
    6060 
    61 datasetID = 'famous_control_month' 
     61datasetID = 'famous_control_month_test_file' 
    6262 
    6363id = 'tag:localhost:5000,2008-09-17:/view/badc.nerc.ac.uk__ATOM__' + datasetID 
     
    6565atomName = 'http://localhost:5000/view/badc.nerc.ac.uk__ATOM__' + datasetID 
    6666 
    67 name = 'famous_control_month.atom' 
     67name = datasetID + '.atom' 
    6868 
    6969VTD = VTD() 
     
    8282        '<link href="http://badc.nerc.ac.uk/a-real-wms-endpoint" rel="http://vocab.ndg.nerc.ac.uk/term/P201/1/GCMDU026" title="WMS"/>' + \ 
    8383        '<link href="http://badc.nerc.ac.uk/alternate" rel="http://vocab.ndg.nerc.ac.uk/term/C110/6/GD" title="alternate page"/>' + \ 
    84         '<link href="' + logo + '" title="' + VTD.TERM_DATA[VTD.LOGO_TERM].title + '" rel="http://vocab.ndg.nerc.ac.uk/term/C110/6/GD"/>' + \ 
     84        '<link href="' + logo + '" title="' + VTD.TERM_DATA[VTD.LOGO_TERM].title + '" rel="http://vocab.ndg.nerc.ac.uk/term/C110/6/GD/Logo"/>' + \ 
    8585        '<author><name>Tiddeman, David</name><uri>www.cb.org</uri></author>' + \ 
    8686        '<contributor><name>Brian Bandy</name><uri>www.cb.org</uri></contributor>' + \ 
     
    101101        '<published>2008-06-17T10:15:19</published>' + \ 
    102102        '<moles:temporalRange>' + T1 + '/' + T2 + '</moles:temporalRange>' + \ 
    103         '<georss:where><gml:Envelope><gml:lowerCorner>' + minX + ' ' + maxX + '</gml:lowerCorner><gml:upperCorner>' + minY + ' ' + maxY + '</gml:upperCorner></gml:Envelope></georss:where>' + \ 
     103        '<georss:where><gml:Envelope><gml:lowerCorner>' + minX + ' ' + minY + '</gml:lowerCorner><gml:upperCorner>' + maxX + ' ' + maxY + '</gml:upperCorner></gml:Envelope></georss:where>' + \ 
    104104    '</entry>' 
    105105 
  • exist/trunk/python/ndgutilstests/testdata/example.granulite

    r4629 r4641  
    33# (which are stored alongside the CDML file) - so you cannot  
    44# specify both at the same time here 
    5 ..\\testdata\\cdml_hadgem1_aecan-apa.xml | hadgem1_dataset | time0 
     5../testdata/test_cdml_hadgem1_aecan-apa.xml | test_hadgem1_dataset | time0 
    66 
    77#csml_file:: 
Note: See TracChangeset for help on using the changeset viewer.