Пример #1
0
    def test_single_sncl_single_dc(
        self, client, service_args, content_type_text, method, params_or_data
    ):
        def create_expected_response(service="dataselect"):
            if service == "station":
                return [
                    create_url("eida.ethz.ch", service_args),
                    b"CH HASLI -- LHZ 1999-06-16T00:00:00.000001",
                    b"",
                ]
            return [
                create_url("eida.ethz.ch", service_args),
                b"CH HASLI -- LHZ 2020-01-01T00:00:00 2020-01-02T00:00:00",
                b"",
            ]

        req_kwargs = create_request_kwargs(
            method, params_or_data, **service_args
        )
        resp = getattr(client, method)(EIDAWS_ROUTING_PATH_QUERY, **req_kwargs)

        assert resp.status_code == 200
        assert resp.headers["Content-Type"] == content_type_text
        assert (
            b"\n".join(create_expected_response(**service_args)) == resp.data
        )
Пример #2
0
    def test_station(
        self, client, level_args, content_type_text, method, params_or_data
    ):
        def create_expected_response(level):
            service_args = {"service": "station"}
            if level == "network":
                return [
                    create_url("eida.ethz.ch", service_args),
                    b"CH * * * 1980-01-01T00:00:00.000001",
                    b"",
                ]
            elif level == "station":
                return [
                    create_url("eida.ethz.ch", service_args),
                    b"CH HASLI * * 1999-01-19T00:00:00.000001",
                    b"",
                ]
            else:
                return [
                    create_url("eida.ethz.ch", service_args),
                    b"CH HASLI -- LHZ 1999-01-19T00:00:00.000001 "
                    b"1999-06-15T23:59:59.999999",
                    b"CH HASLI -- LHZ 1999-06-16T00:00:00.000001",
                    b"",
                ]

        req_kwargs = create_request_kwargs(
            method, params_or_data, **level_args, service="station"
        )
        resp = getattr(client, method)(EIDAWS_ROUTING_PATH_QUERY, **req_kwargs)

        assert resp.status_code == 200
        assert resp.headers["Content-Type"] == content_type_text
        assert b"\n".join(create_expected_response(**level_args)) == resp.data
Пример #3
0
    def test_vnets(
        self, client, content_type_text, service_args, method, params_or_data
    ):
        def create_expected_response(service="dataselect"):
            if service == "station":
                return [
                    create_url("eida.ethz.ch", service_args),
                    b"CH GRIMS -- HHZ 2011-11-09T00:00:00.000001 "
                    b"2015-10-30T10:49:59.999999",
                    b"",
                ]

            return [
                create_url("eida.ethz.ch", service_args),
                b"CH GRIMS -- HHZ 2012-01-01T00:00:00 2012-01-02T00:00:00",
                b"",
            ]

        req_kwargs = create_request_kwargs(
            method,
            params_or_data,
            **service_args,
        )
        resp = getattr(client, method)(EIDAWS_ROUTING_PATH_QUERY, **req_kwargs)

        assert resp.status_code == 200
        assert resp.headers["Content-Type"] == content_type_text
        assert (
            b"\n".join(create_expected_response(**service_args)) == resp.data
        )
Пример #4
0
    def test_single_sncl_merged(
        self, client, content_type_json, method, params_or_data
    ):
        expected_response = [
            {
                "network": "CH",
                "station": "HASLI",
                "location": "",
                "channel": "LHZ",
                "starttime": "1999-01-19T00:00:00",
                "endtime": "2021-01-01T00:00:00",
                "restrictedStatus": "open",
            },
        ]

        req_kwargs = create_request_kwargs(
            method,
            params_or_data,
        )
        resp = getattr(client, method)(
            EIDAWS_STATIONLITE_PATH_QUERY, **req_kwargs
        )

        assert resp.status_code == 200
        assert resp.headers["Content-Type"] == content_type_json
        assert expected_response == json.loads(resp.data)
Пример #5
0
    def test_keywordparser_invalid_args(
        self, client, content_type_text, method, params_or_data
    ):
        req_kwargs = create_request_kwargs(
            method, params_or_data, **{"foo": "bar"}
        )
        resp = getattr(client, method)(EIDAWS_ROUTING_PATH_QUERY, **req_kwargs)

        assert resp.status_code == 400
        assert resp.headers["Content-Type"] == content_type_text
        assert resp.data.startswith(b"\nError 400: Bad request\n")
Пример #6
0
    def test_no_content(
        self, client, service_args, content_type_text, method, params_or_data
    ):
        req_kwargs = create_request_kwargs(
            method, params_or_data, **service_args
        )
        resp = getattr(client, method)(EIDAWS_ROUTING_PATH_QUERY, **req_kwargs)

        assert resp.status_code == 204
        assert resp.headers["Content-Type"] == content_type_text
        assert b"" == resp.data
Пример #7
0
    def test_multi_sncl_single_dc_access(
        self, client, access_args, content_type_text, method, params_or_data
    ):
        service_arg = {"service": "dataselect"}

        def create_expected_response(access="any"):
            if access == "open":
                return [
                    create_url("eida.ethz.ch", service_arg),
                    b"CH HASLI -- HHZ 2008-01-01T00:00:00 2008-01-02T00:00:00",
                    b"",
                ]

            elif access == "closed":
                return [
                    create_url(
                        "eida.ethz.ch",
                        service_arg,
                        method_token=FDSNWS_QUERYAUTH_METHOD_TOKEN,
                    ),
                    b"CH GUT -- HHZ 2008-01-01T00:00:00 2008-01-02T00:00:00",
                    b"",
                ]

            elif access == "any":
                return [
                    create_url("eida.ethz.ch", service_arg),
                    b"CH HASLI -- HHZ 2008-01-01T00:00:00 2008-01-02T00:00:00",
                    b"",
                    create_url(
                        "eida.ethz.ch",
                        service_arg,
                        method_token=FDSNWS_QUERYAUTH_METHOD_TOKEN,
                    ),
                    b"CH GUT -- HHZ 2008-01-01T00:00:00 2008-01-02T00:00:00",
                    b"",
                ]

            raise ValueError(f"Invalid access: {access}")

        req_kwargs = create_request_kwargs(
            method,
            params_or_data,
            **access_args,
            **service_arg,
        )
        resp = getattr(client, method)(EIDAWS_ROUTING_PATH_QUERY, **req_kwargs)

        assert resp.status_code == 200
        assert resp.headers["Content-Type"] == content_type_text
        assert b"\n".join(create_expected_response(**access_args)) == resp.data
Пример #8
0
    def test_multi_sncl_merged(
        self, client, content_type_json, sort_response, method, params_or_data
    ):
        expected_response = [
            {
                "network": "CH",
                "station": "GRIMS",
                "location": "",
                "channel": "LHZ",
                "starttime": "2016-01-01T00:00:00",
                "endtime": "2018-01-01T00:00:00",
                "restrictedStatus": "open",
            },
            {
                "network": "Z3",
                "station": "A051A",
                "location": "",
                "channel": "LHZ",
                "starttime": "2016-01-01T00:00:00",
                "endtime": "2018-01-01T00:00:00",
                "restrictedStatus": "closed",
            },
        ]

        req_kwargs = create_request_kwargs(
            method,
            params_or_data,
        )
        resp = getattr(client, method)(
            EIDAWS_STATIONLITE_PATH_QUERY, **req_kwargs
        )

        assert resp.status_code == 200
        assert resp.headers["Content-Type"] == content_type_json
        assert sort_response(expected_response) == sort_response(
            json.loads(resp.data)
        )