예제 #1
0
def test_get_access_ur(monkeypatch):
    assert 'http://some.url' == cadc_core.get_access_url('http://some.url')

    def get(url, **kwargs):
        class ServiceResponse(object):
            def __init__(self):
                self.text = 'ivo://cadc.nrc.ca/mytap = http://my.org/mytap'

            def raise_for_status(self):
                pass

        class CapabilitiesResponse(object):
            def __init__(self):
                caps_file = data_path('tap_caps.xml')
                self.text = open(caps_file, 'r').read()

            def raise_for_status(self):
                pass

        if url == conf.CADC_REGISTRY_URL:
            return ServiceResponse()
        else:
            return CapabilitiesResponse()

    # don't know why the decorator doesnt work here
    monkeypatch.setattr(cadc_core.requests, 'get', get)
    monkeypatch.setattr(cadc_core.get_access_url, 'caps', {})
    assert 'http://my.org/mytap' == cadc_core.get_access_url('mytap')

    assert \
        'https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/tap/tables' == \
        cadc_core.get_access_url('mytap', 'ivo://ivoa.net/std/VOSI#tables-1.1')
예제 #2
0
def test_get_access_url():
    # testing implementation of requests.get method:
    def get(url, **kwargs):
        class ServiceResponse(object):
            def __init__(self):
                self.text = 'ivo://cadc.nrc.ca/mytap = http://my.org/mytap'

            def raise_for_status(self):
                pass

        class CapabilitiesResponse(object):
            def __init__(self):
                caps_file = data_path('tap_caps.xml')
                self.text = open(caps_file, 'r').read()

            def raise_for_status(self):
                pass
        if url == conf.CADC_REGISTRY_URL:
            return ServiceResponse()
        else:
            return CapabilitiesResponse()

    # now use it in testing
    with patch.object(cadc_core.requests, 'get', get):
        cadc_core.get_access_url.caps = {}
        assert 'http://my.org/mytap' == cadc_core.get_access_url('mytap')
        assert 'https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/argus/tables' == \
            cadc_core.get_access_url('mytap',
                                     'ivo://ivoa.net/std/VOSI#tables-1.1')
예제 #3
0
def test_get_access_ur(monkeypatch):
    assert 'http://some.url' == cadc_core.get_access_url('http://some.url')

    def get(self, method, url, **kwargs):
        class ServiceResponse(object):
            def __init__(self):
                self.text = 'ivo://cadc.nrc.ca/mytap = http://my.org/mytap'

            def raise_for_status(self):
                pass

        class CapabilitiesResponse(object):
            def __init__(self):
                caps_file = data_path('tap_caps.xml')
                self.text = open(caps_file, 'r').read()

            def raise_for_status(self):
                pass
        if url == conf.CADC_REGISTRY_URL:
            return ServiceResponse()
        else:
            return CapabilitiesResponse()

    # don't know why the decorator doesnt work here
    monkeypatch.setattr(cadc_core.BaseQuery, '_request', get)
    monkeypatch.setattr(cadc_core.get_access_url, 'caps', {})
    assert 'http://my.org/mytap' == cadc_core.get_access_url('mytap')

    assert \
        'https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/tap/tables' == \
        cadc_core.get_access_url('mytap', 'ivo://ivoa.net/std/VOSI#tables-1.1')