forked from ScottWales/threddsclient
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_catalog.py
83 lines (64 loc) · 2.27 KB
/
test_catalog.py
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
import pytest
from threddsclient import *
def test_tpac():
# cat = read_url('http://portal.sf.utas.edu.au/thredds/catalog.xml')
pass
def test_invalid_url():
with pytest.raises(requests.ConnectionError):
cat = read_url('http://example.invalid')
def test_null():
xml = """
"""
with pytest.raises(ValueError):
cat = read_xml(xml, 'http://example.test')
def test_empty():
xml = """
<catalog></catalog>
"""
cat = read_xml(xml, 'http://example.test')
assert len(cat.references) == 0
assert len(cat.datasets) == 0
def test_ref():
xml = """
<catalog><catalogRef name='' ID='foo' xlink:title='foo' /></catalog>
"""
cat = read_xml(xml, 'http://example.test')
assert len(cat.references) == 1
assert len(cat.datasets) == 0
def test_data():
xml = """
<catalog><dataset name='' ID='foo' urlPath='' /></catalog>
"""
cat = read_xml(xml, 'http://example.test')
assert len(cat.references) == 0
assert len(cat.datasets) == 1
def test_unidata_sample():
xml = """
<catalog xmlns="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.1" >
<service name="aggServer" serviceType="DODS" base="http://acd.ucar.edu/dodsC/" />
<dataset name="SAGE III Ozone Loss" urlPath="sage.nc">
<serviceName>aggServer</serviceName>
</dataset>
</catalog>
"""
cat = read_xml(xml, 'http://example.test/catalog.xml')
d = cat.datasets[0]
assert d.name == "SAGE III Ozone Loss"
def test_unidata_sample_1():
xml = """
<catalog xmlns="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.1" >
<service name="mcidasServer" serviceType="ADDE" base="http://thredds.ucar.edu/thredds/adde/" />
</catalog>
"""
cat = read_xml(xml, 'http://example.test')
assert cat.services[0].name == 'mcidasServer'
assert cat.services[0].url == 'http://thredds.ucar.edu/thredds/adde/'
assert cat.services[0].service_type == "ADDE"
def test_unidata_sample_2():
xml = """
<catalog xmlns="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.1" >
<service name="this" serviceType="DODS" base="dods/" />
</catalog>
"""
cat = read_xml(xml, 'http://example.test')
assert cat.services[0].url == 'http://example.test/dods/'