def test_remote():
    obj = ExtensionVersion(arguments(**{'Download URL': None}))

    data = obj.remote('extension.json')
    # Repeat requests should return the same result.
    data = obj.remote('extension.json')

    assert json.loads(data)
def test_remote_download_url():
    obj = ExtensionVersion(arguments())

    data = obj.remote('extension.json')
    # Repeat requests should return the same result.
    data = obj.remote('extension.json')

    assert json.loads(data)
def test_remote_file_urls():
    url = 'https://raw.githubusercontent.com/open-contracting-extensions/ocds_coveredBy_extension/master/release-schema.json'  # noqa: E501

    obj = ExtensionVersion(arguments(**{'Download URL': None}), file_urls={'release-schema.json': url})

    data = obj.remote('release-schema.json')
    # Repeat requests should return the same result.
    data = obj.remote('release-schema.json')

    print(data)
    assert 'coveredBy' in json.loads(data)['definitions']['Tender']['properties']
def test_remote_directory(tmpdir):
    file = tmpdir.join('extension.json')
    file.write('{"key": "value"}')

    obj = ExtensionVersion(arguments(**{'Download URL': None}))
    obj.download_url = Path(tmpdir).as_uri()

    data = obj.remote('extension.json')
    # Repeat requests should return the same result.
    data = obj.remote('extension.json')

    assert json.loads(data) == {'key': 'value'}
def test_remote_codelists_only_download_url():
    args = dict.fromkeys(['Id', 'Date', 'Version', 'Base URL', 'Download URL'])
    args['Download URL'] = 'https://api.github.com/repos/contratacionesabiertas/ocds_publicNotices_extension/zipball/master'  # noqa: E501

    obj = ExtensionVersion(args)

    assert obj.remote('release-schema.json', default='{}') == '{}'
def test_remote_codelists_only_base_url():
    args = dict.fromkeys(['Id', 'Date', 'Version', 'Base URL', 'Download URL'])
    args['Base URL'] = 'https://raw.githubusercontent.com/contratacionesabiertas/ocds_publicNotices_extension/master/'

    obj = ExtensionVersion(args)

    assert obj.remote('release-schema.json', default='{}') == '{}'
def test_remote_download_url_nonexistent():
    obj = ExtensionVersion(arguments())
    with pytest.raises(DoesNotExist) as excinfo:
        obj.remote('nonexistent')

    assert str(excinfo.value) == "File 'nonexistent' does not exist in location==v1.1.3"
def test_remote_nonexistent():
    obj = ExtensionVersion(arguments(**{'Download URL': None}))
    with pytest.raises(requests.exceptions.HTTPError) as excinfo:
        obj.remote('nonexistent')

    assert str(excinfo.value) == "404 Client Error: Not Found for url: https://raw.githubusercontent.com/open-contracting-extensions/ocds_location_extension/v1.1.3/nonexistent"  # noqa: E501