示例#1
0
    def should_throw_exception_when_request_fails(mock_httpconn):
        mock_connection = mock_httpconn.return_value
        mock_connection.getresponse.return_value = MockResponse(400, '')

        with pytest.raises(RequestException) as e:
            get_station_metadata('1234')
        assert_equal('METADATA_RETRIEVAL', e.value.error_code)
        def should_retry_request_3_more_times_before_giving_up_if_search_did_not_return_results(
                mock_httpconn):
            # Looks like occasionally FMI api returns Java exception response when doing completely valid
            # searches... We should handle it properly and just try again couple of times and hope it goes away.
            mock_connection = mock_httpconn.return_value
            mock_connection.getresponse.return_value = MockResponse(
                200, etree.tostring(search_exception_response))

            with pytest.raises(RequestException) as e:
                get_station_metadata('1234')
            assert_equal('METADATA_RETRIEVAL', e.value.error_code)
            assert_equal(4, mock_connection.getresponse.call_count
                         )  # Should have tried in total 4 times
示例#3
0
    def get_catalogue_of_station(self, fmisid):
        # Add extra metadata for each dataset which are required for queries and translations
        # in short data which is not provided by catalogue service. See supported_queries.json
        datasets = fmicatalogservice.get_station_metadata(fmisid)
        augmented = []
        for ds in datasets:
            for sq in self._supported_queries:
                if re.search(sq['id'], ds['identifier']):
                    augmented.append({**ds, **sq})
                    break

        return augmented
        def should_return_proper_data_after_first_failed_request(
                mock_httpconn):
            # Looks like occasionally FMI api returns Java exception response when doing completely valid
            # searches... We should handle it properly and just try again couple of times and hope it goes away.
            mock_connection = mock_httpconn.return_value

            # Mocked responses. Note that the first one is the exception response
            mock_connection.getresponse.side_effect = [
                MockResponse(200, etree.tostring(search_exception_response)),
                MockResponse(200, etree.tostring(lammi_catalog_metadata))
            ]

            result = get_station_metadata('1234')
            assert_equal(2, mock_connection.getresponse.call_count)
示例#5
0
    def should_do_request_to_catalog_service_with_provided_query_params_and_return_data(
            mock_httpconn):
        mock_connection = mock_httpconn.return_value
        mock_connection.getresponse.return_value = MockResponse(
            200, etree.tostring(lammi_catalog_metadata))

        result = get_station_metadata('1234')
        assert_equal(1, mock_connection.getresponse.call_count)

        for i, record in enumerate(EXPECTED_LAMMI_CATALOG_METADATA):
            assert_equal(result[i]['latitude'], record['latitude'])
            assert_equal(result[i]['longitude'], record['longitude'])
            assert_equal(result[i]['link'], record['link'])
            assert_equal(result[i]['identifier'], record['identifier'])
            assert_equal(result[i]['title_fi'], record['title_fi'])
            assert result[i]['starttime'] == record['starttime']
            assert result[i]['endtime'] == record['endtime']
示例#6
0
    def should_throw_exception_when_request_returns_empty_list(mock_parse):
        mock_parse.return_value = []

        with pytest.raises(NoDataSetsException) as e:
            get_station_metadata('1234')
        assert_equal('NODATASETS', e.value.error_code)