diff --git a/obspy/clients/fdsn/client.py b/obspy/clients/fdsn/client.py index 667dc8d830a..b2fe87a7bd4 100644 --- a/obspy/clients/fdsn/client.py +++ b/obspy/clients/fdsn/client.py @@ -288,6 +288,7 @@ def set_credentials(self, user, password): :type password: str :param password: Password for given user name. """ + self.user = user self._set_opener(user, password) def set_eida_token(self, token): diff --git a/obspy/clients/fdsn/tests/test_client.py b/obspy/clients/fdsn/tests/test_client.py index 84529d2f9ab..b3a17355386 100644 --- a/obspy/clients/fdsn/tests/test_client.py +++ b/obspy/clients/fdsn/tests/test_client.py @@ -282,6 +282,27 @@ def test_url_building_with_auth(self): "queryauth?net=BW") self.assertEqual(got, expected) + def test_set_credentials(self): + """ + Test for issue #2146 + + When setting credentials not during `__init__` but using + `set_credentials`, waveform queries should still properly go to + "queryauth" endpoint. + """ + client = Client(base_url="IRIS", user_agent=USER_AGENT) + user = "nobody@iris.edu" + password = "anonymous" + client.set_credentials(user=user, password=password) + got = client._build_url("dataselect", "query", {'net': "BW"}) + expected = ("http://service.iris.edu/fdsnws/dataselect/1/" + "queryauth?net=BW") + self.assertEqual(got, expected) + # more basic test: check that set_credentials has set Client.user + # (which is tested when checking which endpoint to use, query or + # queryauth) + self.assertEqual(client.user, user) + def test_service_discovery_iris(self): """ Tests the automatic discovery of services with the IRIS endpoint. The