# Path: fmiapi/fmicatalogservice.py
# def get_station_metadata(fmisid):
#     result = _parse_data(_retrieve_metadata_by_fmisid(fmisid))
#     if len(result) == 0:
#         raise NoDataSetsException(fmisid)
#     return result
# 
# Path: fmiapi/fmierrors.py
# class RequestException(Exception):
# 
#     def __init__(self, text, error_code, html=""):
#         self.error_code = 0
#         self.message = text
#         self.error_code = error_code
#         self.html = html
# 
#     def __str__(self):
#         if self.html != "":
#             return self.html
#         else:
#             return self.message
# 
# class NoDataSetsException(Exception):
# 
#     def __init__(self, fmisid):
#         self.message = "No data sets found for {}".format(fmisid)
#         self.error_code = "NODATASETS"
# 
#     def __str__(self):
#         return self.message


from fmiapi.fmicatalogservice import get_station_metadata
from tests.fmiapi.testdata.expected_data import EXPECTED_LAMMI_CATALOG_METADATA
from tests.testUtils import *
from tests.fmiapi.commonmocks import *
from unittest import mock
from lxml import etree
from fmiapi.fmierrors import RequestException, NoDataSetsException
import pytest


def describe_fmi_catalog_service():
    lammi_catalog_metadata = load_xml('./tests/fmiapi/testdata/lammi_catalog_metadata.xml')
    search_exception_response = load_xml('./tests/fmiapi/testdata/search_exception_response.xml')

    @mock.patch('http.client.HTTPConnection', spec=True)
    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))


# Path: fmiapi/fmicatalogservice.py
# def get_station_metadata(fmisid):
#     result = _parse_data(_retrieve_metadata_by_fmisid(fmisid))
#     if len(result) == 0:
#         raise NoDataSetsException(fmisid)
#     return result
# 
# Path: fmiapi/fmierrors.py
# class RequestException(Exception):
# 
#     def __init__(self, text, error_code, html=""):
#         self.error_code = 0
#         self.message = text
#         self.error_code = error_code
#         self.html = html
# 
#     def __str__(self):
#         if self.html != "":
#             return self.html
#         else:
#             return self.message
# 
# class NoDataSetsException(Exception):
# 
#     def __init__(self, fmisid):
#         self.message = "No data sets found for {}".format(fmisid)
#         self.error_code = "NODATASETS"
# 
#     def __str__(self):
#         return self.message


# Path: tests/fmiapi/test_fmicatalogservice.py
from fmiapi.fmicatalogservice import get_station_metadata
from tests.fmiapi.testdata.expected_data import EXPECTED_LAMMI_CATALOG_METADATA
from tests.testUtils import *
from tests.fmiapi.commonmocks import *
from unittest import mock
from lxml import etree
from fmiapi.fmierrors import RequestException, NoDataSetsException
import pytest



def describe_fmi_catalog_service():
    lammi_catalog_metadata = load_xml('./tests/fmiapi/testdata/lammi_catalog_metadata.xml')
    search_exception_response = load_xml('./tests/fmiapi/testdata/search_exception_response.xml')

    @mock.patch('http.client.HTTPConnection', spec=True)
    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')