class TestVersionExtraction(unittest.TestCase):
    def setUp(self):
        yaml_file = 'tests/test_data/complex_identifier_test.yaml'

        with open(
                'tests/test_data/esri_wms_35bd4e2ce8cd13e8697b03976ffe1ee6.txt',
                'r') as f:
            content = f.read()
        url = 'http://www.mapserver.com/cgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GETCAPABILITIES'

        self.identifier = Identify([yaml_file], content, url)
        self.identifier.identify()

        content = content.replace('\\n', '')
        self.parser = Parser(content)

    def test_identify_version(self):
        expected_version = '1.3.0'

        protocol_data = next(p for p in self.identifier.yaml
                             if p['name'] == 'OGC:WMS')
        returned_version = self.identifier._identify_version(
            protocol_data, self.parser)

        self.assertTrue(expected_version == returned_version)

    def test_no_parser(self):
        protocol_data = next(p for p in self.identifier.yaml
                             if p['name'] == 'OGC:WMS')
        returned_version = self.identifier._identify_version(
            protocol_data, None)
        self.assertTrue(not returned_version)
class TestVersionExtraction(unittest.TestCase):
    def setUp(self):
        yaml_file = 'tests/test_data/complex_identifier_test.yaml'

        with open('tests/test_data/esri_wms_35bd4e2ce8cd13e8697b03976ffe1ee6.txt', 'r') as f:
            content = f.read()
        url = 'http://www.mapserver.com/cgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GETCAPABILITIES'

        self.identifier = Identify([yaml_file], content, url)
        self.identifier.identify()

        content = content.replace('\\n', '')
        self.parser = Parser(content)

    def test_identify_version(self):
        expected_version = '1.3.0'

        protocol_data = next(p for p in self.identifier.yaml if p['name'] == 'OGC:WMS')
        returned_version = self.identifier._identify_version(protocol_data, self.parser)

        self.assertTrue(expected_version == returned_version)

    def test_no_parser(self):
        protocol_data = next(p for p in self.identifier.yaml if p['name'] == 'OGC:WMS')
        returned_version = self.identifier._identify_version(protocol_data, None)
        self.assertTrue(not returned_version)
class TestVersionCombined(unittest.TestCase):
    def setUp(self):
        yaml_file = 'tests/test_data/combined_version_identifier_test.yaml'

        content = '''<catalog xmlns="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0 http://www.unidata.ucar.edu/schemas/thredds/InvCatalog.1.0.2.xsd"
    version="1.0.2" name="Actinic Flux measurements during OASIS Barrow field intensive Spring 2009"></catalog>'''
        url = 'http://www.unidata.com/hyrax/thredds'

        self.parser = Parser(content)

        self.identifier = Identify([yaml_file], content, url)
        self.identifier.identify()

    def test_default_version(self):
        expected_version = '1.0.2'

        protocol_data = next(p for p in self.identifier.yaml
                             if p['name'] == 'UNIDATA')

        returned_version = self.identifier._identify_version(
            protocol_data, self.parser)

        self.assertTrue(returned_version)
        self.assertTrue(expected_version == returned_version)
class TestVersionCombined(unittest.TestCase):
    def setUp(self):
        yaml_file = 'tests/test_data/combined_version_identifier_test.yaml'

        content = '''<catalog xmlns="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0 http://www.unidata.ucar.edu/schemas/thredds/InvCatalog.1.0.2.xsd"
    version="1.0.2" name="Actinic Flux measurements during OASIS Barrow field intensive Spring 2009"></catalog>'''
        url = 'http://www.unidata.com/hyrax/thredds'

        self.parser = Parser(content)

        self.identifier = Identify([yaml_file], content, url)
        self.identifier.identify()

    def test_default_version(self):
        expected_version = '1.0.2'

        protocol_data = next(p for p in self.identifier.yaml if p['name'] == 'UNIDATA')

        returned_version = self.identifier._identify_version(protocol_data, self.parser)

        self.assertTrue(returned_version)
        self.assertTrue(expected_version == returned_version)
class TestVersionDefaults(unittest.TestCase):
    def setUp(self):
        yaml_file = 'tests/test_data/simple_identifier_test.yaml'

        content = '''<OpenSearch xmlns="http://a9.com/-/spec/opensearch/1.1/">
                        <element>OpenSearchDescription</element></OpenSearch>'''
        url = 'http://www.opensearch.com'

        self.identifier = Identify([yaml_file], content, url)
        self.identifier.identify()

    def test_default_version(self):
        expected_version = '1.1'

        protocol_data = next(p for p in self.identifier.yaml if p['name'] == 'OpenSearch')

        returned_version = self.identifier._identify_version(protocol_data, None)

        self.assertTrue(returned_version)
        self.assertTrue(expected_version == returned_version)
class TestVersionDefaults(unittest.TestCase):
    def setUp(self):
        yaml_file = 'tests/test_data/simple_identifier_test.yaml'

        content = '''<OpenSearch xmlns="http://a9.com/-/spec/opensearch/1.1/">
                        <element>OpenSearchDescription</element></OpenSearch>'''
        url = 'http://www.opensearch.com'

        self.identifier = Identify([yaml_file], content, url)
        self.identifier.identify()

    def test_default_version(self):
        expected_version = '1.1'

        protocol_data = next(p for p in self.identifier.yaml
                             if p['name'] == 'OpenSearch')

        returned_version = self.identifier._identify_version(
            protocol_data, None)

        self.assertTrue(returned_version)
        self.assertTrue(expected_version == returned_version)