1 | """ |
---|
2 | Constants to use in the various test cases |
---|
3 | |
---|
4 | NERC 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 |
---|
11 | License, version 1.0 or later.""" |
---|
12 | __contact__ = "b.n.lawrence@rl.ac.uk" |
---|
13 | __revision__ = '$Id: $' |
---|
14 | |
---|
15 | from ndg.common.src.clients.xmldb.eXist.eXistConnector import eXistConnector as ec |
---|
16 | from ndg.common.src.models.vocabtermdata import VocabTermData as VTD |
---|
17 | import os, datetime |
---|
18 | |
---|
19 | BASE_DIR = 'unittests' |
---|
20 | |
---|
21 | def 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 |
---|
34 | parentDir = '..' + os.sep |
---|
35 | TEST_DATA_DIR = getTestDataDir('testdata' + os.sep) |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | DBCONFIG_FILE = TEST_DATA_DIR + 'exist.config' |
---|
40 | TEST_GRANULITE = TEST_DATA_DIR + 'example.granulite' |
---|
41 | |
---|
42 | NDG_CONFIG_FILE = TEST_DATA_DIR + 'ndgDiscovery.config' |
---|
43 | DIF_FILE = TEST_DATA_DIR + 'dataent_NDSC_DIF.xml' |
---|
44 | |
---|
45 | GRANULITE_TITLE = 'this is a new test granulite' |
---|
46 | GRANULITE_TIME_AXIS = 'time0' |
---|
47 | GRANULITE_CDML_DATASETID = 'test_hadgem1_dataset' |
---|
48 | GRANULITE_PROVIDER_ID = 'badc.nerc.ac.uk' |
---|
49 | GRANULITE_DATASETID = 'calum_data_set' |
---|
50 | GRANULITE_LOGO = 'http:/blah/blah/a_logo_icon.png' |
---|
51 | GRANULITE_AUTHOR_NAME = 'calum byrom' |
---|
52 | GRANULITE_AUTHOR_URI = 'www.cb.org' |
---|
53 | GRANULITE_AUTHOR_ROLE = 'Data migrator' |
---|
54 | GRANULITE_T1 = '1996-4-19' |
---|
55 | GRANULITE_T2 = '1998-9-22' |
---|
56 | |
---|
57 | VALID_DISCOVERY_URL = 'http://ndgbeta.badc.rl.ac.uk/view/badc.nerc.ac.uk__NDG-B1__dataent_hadisst' |
---|
58 | VALID_RETRIEVE_URL = 'http://ndgbeta.badc.rl.ac.uk/retrieve/badc.nerc.ac.uk__NDG-B1__dataent_hadisst' |
---|
59 | |
---|
60 | VALID_REPOSITORY = "chinook.badc.rl.ac.uk" |
---|
61 | VALID_PROVIDER_ID = 'badc.nerc.ac.uk' |
---|
62 | VALID_MOLES_DOC_ID = 'dataent_hadisst' |
---|
63 | VALID_NDGA_DOC_ID = 'COAPEC_500YrRun_wholerun_annual_atmos' |
---|
64 | VALID_NUMSIM_DOC_ID = 'HadGEM1_CodeBase' |
---|
65 | VALID_ATOM_DOC_ID = 'dataent_11679938403412067' |
---|
66 | |
---|
67 | VALID_DISCOVERY_PROVIDER_ID = "csl.gov.uk" |
---|
68 | VALID_DISCOVERY_DOC_ID = "csl.gov.uk__1" |
---|
69 | |
---|
70 | validParams = ['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 | |
---|
75 | messyParams = ['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 | |
---|
79 | summaryText = 'this is a summary of the granulite' |
---|
80 | |
---|
81 | csmlFile = '/db/moles_support/csml/csml_famous_control_month.xml' |
---|
82 | |
---|
83 | logo = '/blah/blah/a_logo_icon.png' |
---|
84 | |
---|
85 | title = 'this is a test granulite' |
---|
86 | |
---|
87 | datasetID = 'famous_control_month_test_file' |
---|
88 | |
---|
89 | id = 'tag:localhost:5000,2008-09-17:/view/badc.nerc.ac.uk__ATOM__' + datasetID |
---|
90 | |
---|
91 | atomName = 'http://localhost:5000/view/badc.nerc.ac.uk__ATOM__' + datasetID |
---|
92 | |
---|
93 | name = datasetID + '.atom' |
---|
94 | |
---|
95 | VTD = VTD() |
---|
96 | T1 = '2792-12-16' |
---|
97 | T2 = '2992-11-16' |
---|
98 | minX = '-90.0' |
---|
99 | minY = '-90.0' |
---|
100 | maxX = '360.0' |
---|
101 | maxY = '5505.29980469' |
---|
102 | ABBREVIATION = 'BLAH' |
---|
103 | VALID_EMAIL = 'dt@bob.org' |
---|
104 | INVALID_EMAIL = 'dt.bob.org' |
---|
105 | INVALID_FILE = 'blah.txt' |
---|
106 | createdDate = datetime.datetime.today().strftime("%Y-%m-%dT%H_%M_%S") |
---|
107 | |
---|
108 | MOLES_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 | |
---|
121 | xmlString = '<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 | |
---|
143 | invalidEmailXmlString = xmlString.replace(VALID_EMAIL, INVALID_EMAIL) |
---|
144 | |
---|
145 | INVALID_TITLE = '\xa2' |
---|
146 | invalidXmlString = '<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 | |
---|
174 | validAuthor = 'Tiddeman, David' |
---|
175 | validAuthors = [validAuthor + ' | www.cb.org', \ |
---|
176 | 'Brian Bandy | www.cb.org'] |
---|
177 | |
---|
178 | validGranuleAuthors = ['calum byrom | www.cb.org | Metadata maintainer', \ |
---|
179 | 'dom lowe | www.badc.rl.ac.uk | Metadata maintainer'] |
---|
180 | |
---|
181 | validLinks = ['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 | |
---|