Skip to content

Commit

Permalink
testing: use new vcr/network_test distinction in tests, add 2 networked
Browse files Browse the repository at this point in the history
fdsn tests
  • Loading branch information
megies committed Apr 5, 2017
1 parent 507f40b commit 28b3f68
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 11 deletions.
3 changes: 2 additions & 1 deletion obspy/clients/arclink/tests/test_client.py
Expand Up @@ -12,13 +12,14 @@
import unittest

import numpy as np
from vcr import vcr, VCRSystem
from vcr import VCRSystem

from obspy import read
from obspy.clients.arclink import Client
from obspy.clients.arclink.client import ArcLinkException
from obspy.core.utcdatetime import UTCDateTime
from obspy.core.util import AttribDict, NamedTemporaryFile
from obspy.core.util.decorator import vcr


orig_sleep = time.sleep
Expand Down
3 changes: 2 additions & 1 deletion obspy/clients/arclink/tests/test_decrypt.py
Expand Up @@ -11,12 +11,13 @@
import unittest

import numpy as np
from vcr import vcr, VCRSystem
from vcr import VCRSystem

from obspy.clients.arclink import Client, decrypt
from obspy.clients.arclink.client import DCID_KEY_FILE, ArcLinkException
from obspy.core.utcdatetime import UTCDateTime
from obspy.core.util import NamedTemporaryFile
from obspy.core.util.decorator import vcr


orig_sleep = time.sleep
Expand Down
3 changes: 1 addition & 2 deletions obspy/clients/earthworm/tests/test_client.py
Expand Up @@ -8,11 +8,10 @@

import unittest

from vcr import vcr

from obspy import read
from obspy.core.utcdatetime import UTCDateTime
from obspy.core.util import NamedTemporaryFile
from obspy.core.util.decorator import vcr
from obspy.clients.earthworm import Client


Expand Down
55 changes: 52 additions & 3 deletions obspy/clients/fdsn/tests/test_client.py
Expand Up @@ -24,11 +24,11 @@

import lxml
import requests
from vcr import vcr

from obspy import UTCDateTime, read, read_inventory
from obspy.core.compatibility import mock
from obspy.core.util.base import NamedTemporaryFile
from obspy.core.util.decorator import network_test, vcr
from obspy.clients.fdsn import Client
from obspy.clients.fdsn.client import build_url, parse_simple_xml
from obspy.clients.fdsn.header import (DEFAULT_USER_AGENT, URL_MAPPINGS,
Expand Down Expand Up @@ -286,11 +286,13 @@ def test_url_building_with_auth(self):
"queryauth?net=BW")
self.assertEqual(got, expected)

def test_service_discovery_iris(self):
def test_service_discovery_iris_preloaded_cache(self):
"""
Tests the automatic discovery of services with the IRIS endpoint. The
test parameters are taken from IRIS' website.
This is checking the pre-loaded service discovery cache.
This will have to be adjusted once IRIS changes their implementation.
"""
client = self.client
Expand Down Expand Up @@ -326,6 +328,53 @@ def test_service_discovery_iris(self):
# WADL.
)))

@network_test
def test_service_discovery_iris(self):
"""
Tests the automatic discovery of services with the IRIS endpoint. The
test parameters are taken from IRIS' website.
This is doing actual service discovery rather than using the pre-loaded
service discovery cache.
This will have to be adjusted once IRIS changes their implementation.
"""
# Clear the pre-loaded cache
Client._Client__service_discovery_cache.clear()

client = Client('IRIS')
self.assertEqual(set(client.services.keys()),
set(("dataselect", "event", "station",
"available_event_contributors",
"available_event_catalogs")))

# The test sets are copied from the IRIS webpage.
self.assertEqual(
set(client.services["dataselect"].keys()),
set(("starttime", "endtime", "network", "station", "location",
"channel", "quality", "minimumlength", "longestonly")))
self.assertEqual(
set(client.services["station"].keys()),
set(("starttime", "endtime", "startbefore", "startafter",
"endbefore", "endafter", "network", "station", "location",
"channel", "minlatitude", "maxlatitude", "minlongitude",
"maxlongitude", "latitude", "longitude", "minradius",
"maxradius", "level", "includerestricted", "format",
"includeavailability", "updatedafter", "matchtimeseries")))
self.assertEqual(
set(client.services["event"].keys()),
set(("starttime", "endtime", "minlatitude", "maxlatitude",
"minlongitude", "maxlongitude", "latitude", "longitude",
"maxradius", "minradius", "mindepth", "maxdepth",
"minmagnitude", "maxmagnitude",
"magnitudetype", "format",
"catalog", "contributor", "limit", "offset", "orderby",
"updatedafter", "includeallorigins", "includeallmagnitudes",
"includearrivals", "eventid",
"originid" # XXX: This is currently just specified in the
# WADL.
)))

# Also check an exemplary value in more detail.
minradius = client.services["event"]["minradius"]
self.assertEqual(minradius["default_value"], 0.0)
Expand Down Expand Up @@ -1090,7 +1139,7 @@ def test_redirection(self):
# Just make sure something is being downloaded.
self.assertTrue(bool(len(inv.networks)))

@vcr
@network_test
def test_redirection_auth(self):
"""
Tests the redirection of GET and POST requests using authentication.
Expand Down
2 changes: 1 addition & 1 deletion obspy/clients/iris/tests/test_client.py
Expand Up @@ -10,10 +10,10 @@
import unittest

import numpy as np
from vcr import vcr

from obspy.core.utcdatetime import UTCDateTime
from obspy.core.util import NamedTemporaryFile
from obspy.core.util.decorator import vcr
from obspy.clients.iris import Client


Expand Down
2 changes: 1 addition & 1 deletion obspy/clients/neic/tests/test_client.py
Expand Up @@ -8,9 +8,9 @@

import unittest

from vcr import vcr

from obspy.core.utcdatetime import UTCDateTime
from obspy.core.util.decorator import vcr
from obspy.clients.neic import Client


Expand Down
2 changes: 1 addition & 1 deletion obspy/clients/seishub/tests/test_client.py
Expand Up @@ -10,9 +10,9 @@
import unittest

import numpy as np
from vcr import vcr

from obspy.core import AttribDict, UTCDateTime
from obspy.core.util.decorator import vcr
from obspy.clients.seishub import Client


Expand Down
2 changes: 1 addition & 1 deletion obspy/clients/syngine/tests/test_client.py
Expand Up @@ -11,11 +11,11 @@
import unittest

import numpy as np
from vcr import vcr

import obspy
from obspy.core.compatibility import mock
from obspy.core.util.base import NamedTemporaryFile
from obspy.core.util.decorator import vcr
from obspy.clients.syngine import Client
from obspy.clients.base import DEFAULT_TESTING_USER_AGENT, ClientHTTPException

Expand Down

0 comments on commit 28b3f68

Please sign in to comment.