source: ndgCommon/trunk/ndg/common/unittests/testconstants.py @ 4810

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/unittests/testconstants.py@4844
Revision 4810, 9.7 KB checked in by cbyrom, 11 years ago (diff)

Create new class (and test suite) to do all the eXist DB setting up - and move this code from the
eXistdbclient to tidy things up.
Allow feed publishing to be done synch/asynch.
Improve loading of non-python resources - adding code to store the various schemata and indexes
required for setting up eXist
Improve parsing of atom URLs to allow browser host to change
Fix moles data in testconstants
Add tests for looking up associated atom data
Add indexing configuration files - to optimise atom processing in eXist + add code in initialiser class to set these up on eXist.
Add all the required schemata required for atom schema validation in eXist + add code in initialiser class to set these up on eXist;
this allows eXist to be ran without need of access beyond the firewall.

Line 
1"""
2Constants to use in the various test cases
3
4NERC Data Grid Project
5"""
6__author__ = "C Byrom - Tessella"
7__date__ = "03/09/08"
8__copyright__ = "(C) 2008 STFC & NERC"
9__license__ = \
10"""This software may be distributed under the terms of the Q Public
11License, version 1.0 or later."""
12__contact__ = "b.n.lawrence@rl.ac.uk"
13__revision__ = '$Id: $'
14
15from ndg.common.src.clients.xmldb.eXist.eXistConnector import eXistConnector as ec
16from ndg.common.src.models.vocabtermdata import VocabTermData as VTD
17import os, datetime
18
19BASE_DIR = 'unittests'
20
21def getTestDataDir(dir):
22    if os.path.exists(dir):
23        return dir
24
25    # avoid infinite recursions
26    if dir.count(parentDir) > 10:
27        raise SystemError("Could not find 'testdata' directory - with test config data\
28    - will not run tests until this has been set up correctly")
29   
30    return getTestDataDir(parentDir + dir)
31   
32# NB, directories depend on whether we're running on unix/windows or
33# whether we use nose to run the tests of python unit tests
34parentDir = '..' + os.sep
35TEST_DATA_DIR = getTestDataDir('testdata' + os.sep)
36   
37
38
39DBCONFIG_FILE = TEST_DATA_DIR + 'exist.config'
40TEST_GRANULITE = TEST_DATA_DIR + 'example.granulite'
41
42NDG_CONFIG_FILE = TEST_DATA_DIR + 'ndgDiscovery.config'
43DIF_FILE = TEST_DATA_DIR + 'dataent_NDSC_DIF.xml'
44
45GRANULITE_TITLE = 'this is a new test granulite'
46GRANULITE_TIME_AXIS = 'time0'
47GRANULITE_CDML_DATASETID = 'test_hadgem1_dataset'
48GRANULITE_PROVIDER_ID = 'badc.nerc.ac.uk'
49GRANULITE_DATASETID = 'calum_data_set'
50GRANULITE_LOGO = 'http:/blah/blah/a_logo_icon.png'
51GRANULITE_AUTHOR_NAME = 'calum byrom'
52GRANULITE_AUTHOR_URI = 'www.cb.org'
53GRANULITE_AUTHOR_ROLE = 'Data migrator'
54GRANULITE_T1 = '1996-4-19'
55GRANULITE_T2 = '1998-9-22'
56
57VALID_DISCOVERY_URL = 'http://ndgbeta.badc.rl.ac.uk/view/badc.nerc.ac.uk__NDG-B1__dataent_hadisst'
58VALID_RETRIEVE_URL = 'http://ndgbeta.badc.rl.ac.uk/retrieve/badc.nerc.ac.uk__NDG-B1__dataent_hadisst'
59
60VALID_REPOSITORY = "chinook.badc.rl.ac.uk"
61VALID_PROVIDER_ID = 'badc.nerc.ac.uk'
62VALID_MOLES_DOC_ID = 'dataent_hadisst'
63VALID_NDGA_DOC_ID = 'COAPEC_500YrRun_wholerun_annual_atmos'
64VALID_NUMSIM_DOC_ID = 'HadGEM1_CodeBase'
65VALID_ATOM_DOC_ID = 'dataent_11679938403412067'
66
67VALID_DISCOVERY_PROVIDER_ID = "csl.gov.uk"
68VALID_DISCOVERY_DOC_ID = "csl.gov.uk__1"       
69
70validParams = ['OZONE MIXING RATIO (PPB ) | http://vocab.ndg.nerc.ac.uk/blah | OZONE', \
71               'ERROR FLAG (OZONE MIXING RATIO ) | http://vocab.ndg.nerc.ac.uk/blah | ERROR', \
72               'HYDROGEN PEROXIDE PPBV | http://vocab.ndg.nerc.ac.uk/blah | HYDROGEN',
73               'CADMIUM >1.21 M DIAMETER (PMOL M-3) INSTRUMENTAL DETECTION LIMIT 0.132 NM']
74
75messyParams = ['OZONE MIXING RATIO &  (PPB     ) | http://vocab.ndg.nerc.ac.uk/blah | ozone', \
76               'ERROR FLAG (OZONE MIXING > RATIO  ) | http://vocab.ndg.nerc.ac.uk/blah | error', \
77               'Hydrogen Peroxide < ppbv | http://vocab.ndg.nerc.ac.uk/blah | hydrogen &']
78
79summaryText = 'this is a summary of the granulite'
80
81csmlFile = '/db/moles_support/csml/csml_famous_control_month.xml'
82
83logo = '/blah/blah/a_logo_icon.png'
84
85title = 'this is a test granulite'
86
87datasetID = 'famous_control_month_test_file'
88
89id = 'tag:localhost:5000,2008-09-17:/view/badc.nerc.ac.uk__ATOM__' + datasetID
90
91atomName = 'http://localhost:5000/view/badc.nerc.ac.uk__ATOM__' + datasetID
92
93name = datasetID + '.atom'
94
95VTD = VTD()
96T1 = '2792-12-16'
97T2 = '2992-11-16'
98minX = '-90.0'
99minY = '-90.0'
100maxX = '360.0'
101maxY = '5505.29980469'
102ABBREVIATION = 'BLAH'
103VALID_EMAIL = 'dt@bob.org'
104INVALID_EMAIL = 'dt.bob.org'
105INVALID_FILE = 'blah.txt'
106createdDate = datetime.datetime.today().strftime("%Y-%m-%dT%H_%M_%S")
107
108MOLES_ENTITY_STRING = '<moles:entity type="granule"><moles:molesISO><moles:responsibleParties>' + \
109            '<moles:responsibleParty><moles:name>calum byrom</moles:name><moles:uri>www.cb.org</moles:uri><moles:role>Metadata maintainer</moles:role></moles:responsibleParty>' + \
110            '<moles:responsibleParty><moles:name>dom lowe</moles:name><moles:uri>www.badc.rl.ac.uk</moles:uri><moles:role>Metadata maintainer</moles:role></moles:responsibleParty>' + \
111            '</moles:responsibleParties><moles:datasetLanguage>English</moles:datasetLanguage>' + \
112            '<moles:datasetLanguage>English</moles:datasetLanguage>' + \
113            '<moles:metadataLanguage>English</moles:metadataLanguage>' + \
114            '<moles:abbreviation>' + ABBREVIATION + '</moles:abbreviation>' + \
115            '<moles:providerID>' + VALID_PROVIDER_ID + '</moles:providerID>' + \
116            '<moles:metadataLanguage>English</moles:metadataLanguage>' + \
117            '<moles:created>' + createdDate + '</moles:created>' + \
118            '</moles:molesISO>' + \
119        '</moles:entity>'
120       
121xmlString = '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss/10" xmlns:gml="http://www.opengis.net/gml" ' + \
122    'xmlns:moles="http://ndg.nerc.ac.uk/schema/moles2beta">' + \
123    '<id>' + id + '</id>' + \
124    '<title>' + title + '</title>' + \
125        '<link href="' + atomName + '" rel="self"/>' + \
126        '<link href="http://badc.nerc.ac.uk/a-real-wms-endpoint" rel="http://vocab.ndg.nerc.ac.uk/term/P201/1/GCMDU026" title="WMS"/>' + \
127        '<link href="http://badc.nerc.ac.uk/alternate" rel="http://vocab.ndg.nerc.ac.uk/term/C110/6/GD" title="alternate page"/>' + \
128        '<link href="' + logo + '" title="' + VTD.TERM_DATA[VTD.LOGO_TERM].title + '" rel="http://vocab.ndg.nerc.ac.uk/term/C110/6/GD/Logo"/>' + \
129        '<author><name>Tiddeman, David</name><email>' + VALID_EMAIL + '</email></author>' + \
130        '<contributor><name>Brian Bandy</name><email>bb@bb.org</email></contributor>' + \
131        MOLES_ENTITY_STRING + \
132        '<category term="OZONE" scheme="http://vocab.ndg.nerc.ac.uk/term/C110/6/GD" label="OZONE MIXING RATIO (PPB )"/>' + \
133        '<category term="ERROR" scheme="http://vocab.ndg.nerc.ac.uk/term/C110/6/GD" label="ERROR FLAG (OZONE MIXING RATIO )"/>' + \
134        '<category term="HYDROGEN" scheme="http://vocab.ndg.nerc.ac.uk/term/C110/6/GD" label="HYDROGEN PEROXIDE PPBV"/>' + \
135        '<category term="ATOM_TYPE" scheme="GRAN - NOT YET SET UP/None/GRANULE" label="GRANULE"></category>' + \
136        '<summary>' + summaryText + '</summary>' + \
137        '<content src="' + csmlFile + '" type="application/xml"/>' + \
138        '<published>2008-06-17T10:15:19</published>' + \
139        '<moles:temporalRange>' + T1 + '/' + T2 + '</moles:temporalRange>' + \
140        '<georss:where><gml:Envelope><gml:lowerCorner>' + minX + ' ' + minY + '</gml:lowerCorner><gml:upperCorner>' + maxX + ' ' + maxY + '</gml:upperCorner></gml:Envelope></georss:where>' + \
141    '</entry>'
142
143invalidEmailXmlString = xmlString.replace(VALID_EMAIL, INVALID_EMAIL)
144
145INVALID_TITLE = '\xa2'
146invalidXmlString = '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss/10" xmlns:gml="http://www.opengis.net/gml" ' + \
147    'xmlns:moles="http://ndg.nerc.ac.uk/schema/moles2beta">' + \
148    '<id>' + id + '</id>' + \
149        '<link href="' + atomName + '" rel="self"/>' + \
150        '<link href="http://badc.nerc.ac.uk/a-real-wms-endpoint" rel="http://vocab.ndg.nerc.ac.uk/term/P201/1/GCMDU026" title="WMS"/>' + \
151        '<link href="http://badc.nerc.ac.uk/alternate" rel="alternate" title="alternate page"/>' + \
152        '<link href="' + logo + '" title="' + VTD.TERM_DATA[VTD.LOGO_TERM].title + '" rel="' + VTD.LOGO_TERM + '"/>' + \
153        '<contributor><name>Brian Bandy</name><uri>www.cb.org</uri></contributor>' + \
154        '<moles:entity type="granule"><moles:molesISO><moles:responsibleParties>' + \
155            '<moles:responsibleParty><moles:name>calum byrom</moles:name><moles:uri>www.cb.org</moles:uri><moles:role>Metadata maintainer</moles:role></moles:responsibleParty>' + \
156            '<moles:responsibleParty><moles:name>dom lowe</moles:name><moles:uri>www.badc.rl.ac.uk</moles:uri><moles:role>Metadata maintainer</moles:role></moles:responsibleParty>' + \
157            '</moles:responsibleParties><moles:datasetLanguage>English</moles:datasetLanguage>' + \
158            '<moles:providerID>badc.nerc.ac.uk</moles:providerID>' + \
159            '<moles:metadataLanguage>English</moles:metadataLanguage>' + \
160            '</moles:molesISO>' + \
161        '</moles:entity>' + \
162        '<category term="OZONE" scheme="http://vocab.ndg.nerc.ac.uk/blah" label="OZONE MIXING RATIO (PPB )"/>' + \
163        '<category term="ERROR" scheme="http://vocab.ndg.nerc.ac.uk/blah" label="ERROR FLAG (OZONE MIXING RATIO )"/>' + \
164        '<category term="HYDROGEN" scheme="http://vocab.ndg.nerc.ac.uk/blah" label="HYDROGEN PEROXIDE PPBV"/>' + \
165        '<category term="ATOM_TYPE" scheme="GRAN - NOT YET SET UP/None/GRANULE" label="GRANULE"></category>' + \
166        '<summary>' + summaryText + '</summary>' + \
167        '<content src="' + csmlFile + '" type="application/xml"/>' + \
168        '<published>2008-06-17T10:15:19</published>' + \
169        '<moles:temporalRange>' + T1 + '/' + T2 + '</moles:temporalRange>' + \
170        '<georss:where><gml:Envelope><gml:lowerCorner>' + minX + ' ' + maxX + '</gml:lowerCorner><gml:upperCorner>' + minY + ' ' + maxY + '</gml:upperCorner></gml:Envelope></georss:where>' + \
171    '</entry>'
172
173   
174validAuthor = 'Tiddeman, David'
175validAuthors = [validAuthor + ' | www.cb.org', \
176                    'Brian Bandy | www.cb.org']
177   
178validGranuleAuthors = ['calum byrom | www.cb.org | Metadata maintainer', \
179                    'dom lowe | www.badc.rl.ac.uk | Metadata maintainer']
180
181validLinks = ['http://badc.nerc.ac.uk/a-real-wms-endpoint | WMS | http://vocab.ndg.nerc.ac.uk/term/P201/1/GCMDU026',\
182              'http://badc.nerc.ac.uk/alternate | alternate page | alternate',
183              '/blah/blah/a_logo_icon.png | logo | LOGO - NOT YET SET UP',
184              '/db/moles_support/granuleAtom/famous_control_month_granule.moles']
185
Note: See TracBrowser for help on using the repository browser.