File: wof_test.py

package info (click to toggle)
python-ulmo 0.8.4%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,100 kB
  • sloc: python: 6,752; makefile: 145
file content (305 lines) | stat: -rw-r--r-- 11,891 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import ulmo
import test_util


def test_core_get_sites_waterml_1_0():
    WSDL_URL = 'http://hydroportal.cuahsi.org/muddyriver/cuahsi_1_0.asmx?WSDL'
    get_sites_file = 'cuahsi/wof/get_sites_muddyriver_1_0.xml'
    with test_util.mocked_suds_client('1.0', dict(GetSitesXml=get_sites_file)):
        sites = ulmo.cuahsi.wof.get_sites(WSDL_URL)
    assert len(sites) == 14


def test_core_get_sites_waterml_1_1():
    WSDL_URL = 'http://hydroportal.cuahsi.org/ipswich/cuahsi_1_1.asmx?WSDL'
    get_sites_file = 'cuahsi/wof/get_sites_ipswich_1_1.xml'
    with test_util.mocked_suds_client('1.1', dict(GetSites=get_sites_file)):
        sites = ulmo.cuahsi.wof.get_sites(WSDL_URL)
    assert len(sites) == 34


def test_core_get_site_info_waterml_1_0():
    WSDL_URL = 'http://hydroportal.cuahsi.org/muddyriver/cuahsi_1_0.asmx?WSDL'
    site_info_file = 'cuahsi/wof/get_site_info_muddyriver_14_1_0.xml'
    with test_util.mocked_suds_client('1.0', dict(GetSiteInfo=site_info_file)):
        site_info = ulmo.cuahsi.wof.get_site_info(WSDL_URL, 'MuddyRiver:MuddyRiver_14')
    assert site_info['code'] == 'MuddyRiver_14'
    assert site_info['network'] == 'MuddyRiver'
    assert 'MR:MuddyRiver_ACID' in site_info['series']
    assert 'MR:MuddyRiver_pH' in site_info['series']
    assert 'MR:MuddyRiver_ZN' in site_info['series']
    assert len(site_info['series']) == 27
    site_info['series']['MR:MuddyRiver_ACID']['variable']['units'] == {
        'abbreviation': 'degC',
        'code': '96',
        'name': 'degree celsius',
        'type': 'Temperature',
    }


def test_core_get_site_info_waterml_1_1():
    WSDL_URL = 'http://hydroportal.cuahsi.org/ipswich/cuahsi_1_1.asmx?WSDL'
    site_info_file = 'cuahsi/wof/get_site_info_ipswich_MMB_1_1.xml'
    with test_util.mocked_suds_client('1.1', dict(GetSiteInfo=site_info_file)):
        site_info = ulmo.cuahsi.wof.get_site_info(WSDL_URL, 'ipswich:MMB')
    assert site_info['code'] == 'MMB'
    assert site_info['network'] == 'ipswich'
    assert 'ipswich:Temp' in site_info['series']
    assert 'ipswich:DO' in site_info['series']
    assert len(site_info['series']) == 3
    site_info['series']['ipswich:Temp']['variable']['units'] == {
        'abbreviation': 'degC',
        'code': '96',
        'name': 'degree celsius',
        'type': 'Temperature',
    }


def test_core_get_values_waterml_1_0():
    WSDL_URL = 'http://hydroportal.cuahsi.org/muddyriver/cuahsi_1_0.asmx?WSDL'
    get_values_file = 'cuahsi/wof/get_values_1_0_MuddyRiver_MuddyRiver_14_MR_MuddyRiver_ACID.xml'
    with test_util.mocked_suds_client('1.0', dict(GetValues=get_values_file)):
        values = ulmo.cuahsi.wof.get_values(
            WSDL_URL, 'MuddyRiver:MuddyRiver_14', 'MR:MuddyRiver_ACID')
    assert len(values['values']) == 28
    assert values['methods'] == {
        '0': {
            'id': '0',
            'description': 'No method specified',
        }
    }
    assert values['sources'] == {
        '1': {
            'address': '400 Snell Engineering Center\n,Boston, MA 02115',
            'contact_name': 'Ferdi L. Hellweger',
            'description': 'Muddy River Water Quality Monitoring',
            'email': 'ferdi@coe.neu.edu',
            'id': '1',
            'link': 'http://www.muddyrivermmoc.org/index.html',
            'organization': 'Northeastern University',
            'phone': '(617) 373-3992',
            'type_of_contact': 'main',
        }
    }


def test_core_get_values_start_and_end_parsing():
    WSDL_URL = 'http://hydroportal.cuahsi.org/muddyriver/cuahsi_1_0.asmx?WSDL'
    file_template = 'cuahsi/wof/get_values_1_0_MuddyRiver_MuddyRiver_14_MR_MuddyRiver_ACID_%(start)s_%(end)s.xml'

    start_ends = [
        ('2006-07-21', '2008-04-04'),
        ('2008-01-01', None),
        (None, '2007-03-13'),
    ]

    for start, end in start_ends:
        get_values_file = file_template % {'start': start, 'end': end}
        with test_util.mocked_suds_client('1.0', dict(GetValues=get_values_file)):
            values = ulmo.cuahsi.wof.get_values(
                WSDL_URL, 'MuddyRiver:MuddyRiver_14', 'MR:MuddyRiver_ACID',
                start=start, end=end)

            assert len(values['values']) > 0
            timestamps = [value.get('datetime') for value in values['values']]
            if start:
                for timestamp in timestamps:
                    assert timestamp > start

            if end:
                for timestamp in timestamps:
                    assert timestamp < end


def test_core_get_values_waterml_1_1():
    WSDL_URL = 'http://hydroportal.cuahsi.org/ipswich/cuahsi_1_1.asmx?WSDL'
    get_values_file = 'cuahsi/wof/get_values_1_1_ipswich_MMB_ipswich_Temp.xml'
    with test_util.mocked_suds_client('1.1', dict(GetValues=get_values_file)):
        values = ulmo.cuahsi.wof.get_values(WSDL_URL, 'ipswich:MMB', 'ipswich:Temp')
    assert len(values['values']) == 112
    assert values['values'][0] == {
        'censor_code': 'nc',
        'date_time_utc': '1997-08-24T15:35:00.383',
        'datetime': '1997-08-24T09:35:00',
        'method_code': '2',
        'quality_control_level_code': '3',
        'source_code': '1',
        'time_offset': '-06:00',
        'value': '19',
    }
    assert values['censor_codes'] == {
        'nc': {
            'censor_code': 'nc',
            'description': 'not censored',
        }
    }
    assert values['methods'] == {
        '2': {
            'code': '2',
            'description': '6" Glass Thermometer, Centigrade Scale',
            'id': '2',
        }
    }
    assert values['sources'] == {
        '1': {
            'abstract': 'The Ipswich River Watershed Associations (IRWA) RiverWatch water quality monitoring program, in operation since 1997, enlists volunteers to collect data on the health of the Ipswich River and its tributaries. Volunteers monitor according to a state-approved monitoring plan that ensures that the data they collect is of good quality. The goals of the program are to document River conditions in order to identify water quality problems (including adequate river flow) and to use this data to develop solutions to observed problems.',
            'address': 'P.O. Box 576, 143 County Rd.\n,Ipswich, MA 01938-2557',
            'citation': 'RiverWatch Water Quality Volunteer Monitoring Program Annual Results Reports. http://ipswichriver.org/resources/monitoring-data/',
            'code': '1',
            'contact_name': 'Ryan ODonnell',
            'description': 'The Ipswich River Watershed Association (IRWA) is the voice of the Ipswich River. IRWA works to protect nature and make sure that there is enough clean water for people, fish and wildlife, today and for our children and theirs.',
            'email': 'rodonnell@ipswichriver.org',
            'id': '1',
            'link': 'http://www.ipswichriver.org',
            'metadata_link': 'http://ipswich-river.org/resources/monitoring-data/',
            'organization': 'Ipswich River Watershed Association',
            'phone': '978-412-8200',
            'profile_version': 'Unknown',
            'title': 'Ipswich River RiverWatch Program',
            'topic_category': 'inlandWaters',
            'type_of_contact': 'main',
        }
    }


def test_core_get_variable_info_waterml_single_1_0():
    WSDL_URL = 'http://hydroportal.cuahsi.org/muddyriver/cuahsi_1_0.asmx?WSDL'
    get_variable_info_file = 'cuahsi/wof/get_variable_info_1_0_MR_MuddyRiver_ACID.xml'
    with test_util.mocked_suds_client('1.0', dict(GetVariableInfo=get_variable_info_file)):
        variable_info = ulmo.cuahsi.wof.get_variable_info(WSDL_URL, 'MR:MuddyRiver_ACID')
    assert variable_info == {
        'code': 'MuddyRiver_ACID',
        'data_type': 'Sporadic',
        'general_category': 'Water Quality',
        'id': '16',
        'name': 'Acid neutralizing capacity',
        'no_data_value': '-9999',
        'sample_medium': 'Surface Water',
        'time': {
            'is_regular': False,
        },
        'units': {
            'abbreviation': 'mg/L',
            'code': '199',
            'name': 'milligrams per liter',
        },
        'value_type': 'Sample',
        'vocabulary': 'MR'
    }


def test_core_get_variable_info_waterml_all_1_0():
    WSDL_URL = 'http://hydroportal.cuahsi.org/muddyriver/cuahsi_1_0.asmx?WSDL'
    get_variable_info_file = 'cuahsi/wof/get_variable_info_1_0_MR_all.xml'
    with test_util.mocked_suds_client('1.0', dict(GetVariableInfo=get_variable_info_file)):
        variable_info = ulmo.cuahsi.wof.get_variable_info(WSDL_URL)

    check_includes = [
        'MR:MuddyRiver_ACID',
        'MR:MuddyRiver_FC',
        'MR:MuddyRiver_FCOLOR',
        'MR:MuddyRiver_pH',
    ]

    for check in check_includes:
        assert check in variable_info

    assert variable_info['MR:MuddyRiver_ACID'] == {
        'code': 'MuddyRiver_ACID',
        'data_type': 'Sporadic',
        'general_category': 'Water Quality',
        'id': '16',
        'name': 'Acid neutralizing capacity',
        'no_data_value': '-9999',
        'sample_medium': 'Surface Water',
        'time': {
            'is_regular': False,
        },
        'units': {
            'abbreviation': 'mg/L',
            'code': '199',
            'name': 'milligrams per liter',
        },
        'value_type': 'Sample',
        'vocabulary': 'MR'
    }


def test_core_get_variable_info_waterml_single_1_1():
    WSDL_URL = 'http://hydroportal.cuahsi.org/ipswich/cuahsi_1_1.asmx?WSDL'
    get_variable_info_file = 'cuahsi/wof/get_variable_info_1_1_ipswich_Temp.xml'
    with test_util.mocked_suds_client('1.1', dict(GetVariableInfo=get_variable_info_file)):
        variable_info = ulmo.cuahsi.wof.get_variable_info(WSDL_URL, 'ipswich:Temp')

    assert variable_info == {
        'code': 'Temp',
        'data_type': 'Sporadic',
        'general_category': 'Water Quality',
        'id': '3',
        'name': 'Temperature',
        'no_data_value': '-9999',
        'sample_medium': 'Surface Water',
        'speciation': 'Not Applicable',
        'units': {
            'abbreviation': 'degC',
            'code': '96',
            'name': 'degree celsius',
            'type': 'Temperature',
        },
        'time': {
            'interval': '0',
            'is_regular': True,
            'units': {
                'abbreviation': 'month',
                'code': '106',
                'name': 'month',
                'type': 'Time',
            },
        },
        'value_type': 'Sample',
        'vocabulary': 'ipswich',
    }


def test_core_get_variable_info_waterml_all_1_1():
    WSDL_URL = 'http://hydroportal.cuahsi.org/ipswich/cuahsi_1_1.asmx?WSDL'
    get_variable_info_file = 'cuahsi/wof/get_variable_info_1_1_ipswich_all.xml'
    with test_util.mocked_suds_client('1.1', dict(GetVariableInfo=get_variable_info_file)):
        variable_info = ulmo.cuahsi.wof.get_variable_info(WSDL_URL)

    check_includes = [
        'ipswich:DO',
        'ipswich:PercDO',
        'ipswich:Temp',
    ]
    for check in check_includes:
        assert check in variable_info

    assert variable_info['ipswich:Temp'] == {
        'code': 'Temp',
        'data_type': 'Sporadic',
        'general_category': 'Water Quality',
        'id': '3',
        'name': 'Temperature',
        'no_data_value': '-9999',
        'sample_medium': 'Surface Water',
        'speciation': 'Not Applicable',
        'units': {
            'abbreviation': 'degC',
            'code': '96',
            'name': 'degree celsius',
            'type': 'Temperature',
        },
        'time': {
            'interval': '0',
            'is_regular': True,
            'units': {
                'abbreviation': 'month',
                'code': '106',
                'name': 'month',
                'type': 'Time',
            },
        },
        'value_type': 'Sample',
        'vocabulary': 'ipswich',
    }