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

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

Add new utility methods to determine default proxies to use - checking
environment variables to establish this - and checking the url to ensure the proxy is needed for it (i.e. excluding no_proxy conforming urls). Adjust codebase to use this - when doing simple url lookups and when opening normal urls.

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