コード例 #1
0
def test_update_ignore_private_properties():
    obj = ExtensionVersion(arguments())
    other = ExtensionVersion(arguments())
    other._files = {'key': 'value'}
    obj.update(other)

    assert obj._files is None
コード例 #2
0
def test_get_latest_version_dated():
    versions = [
        ExtensionVersion(arguments(**{'Version': '1'})),
        ExtensionVersion(arguments(**{'Date': None})),
        ExtensionVersion(arguments(**{'Date': '1000-01-01'})),
    ]

    assert get_latest_version(versions).version == '1'
コード例 #3
0
def test_get_latest_version_dateless():
    versions = [
        ExtensionVersion(arguments(**{'Date': None})),
        ExtensionVersion(arguments(**{
            'Date': None,
            'Version': '1'
        })),
    ]

    with pytest.raises(UnknownLatestVersion) as excinfo:
        get_latest_version(versions)

    assert str(excinfo.value) == ''
コード例 #4
0
def test_codelists_without_metadata_or_download_url():
    base_url = 'https://raw.githubusercontent.com/open-contracting-extensions/ocds_location_extension/v1.1/'
    download_url = None
    obj = ExtensionVersion(arguments(**{'Base URL': base_url, 'Download URL': download_url}))
    result = obj.codelists

    assert result == {}
コード例 #5
0
def test_schemas():
    download_url = 'https://github.com/open-contracting-extensions/ocds_location_extension/archive/master.zip'
    obj = ExtensionVersion(arguments(**{'Download URL': download_url}))
    result = obj.schemas

    assert len(result) == 1
    assert 'Location' in result['release-schema.json']['definitions']
コード例 #6
0
def test_update():
    obj = ExtensionVersion(arguments())
    obj.update(Extension({'Id': 'location', 'Category': 'item', 'Core': 'true'}))

    assert obj.id == 'location'
    assert obj.category == 'item'
    assert obj.core is True
コード例 #7
0
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='{}') == '{}'
コード例 #8
0
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='{}') == '{}'
コード例 #9
0
def test_codelists():
    obj = ExtensionVersion(arguments())
    result = obj.codelists

    assert len(result) == 2
    assert result['locationGazetteers.csv'].fieldnames == ['Category', 'Code', 'Title', 'Description', 'Source',
                                                           'URI Pattern']
コード例 #10
0
def test_codelists_with_CR_newlines():
    download_url = 'https://api.github.com/repos/open-contracting-extensions/ocds_bid_extension/zipball/v1.1'
    obj = ExtensionVersion(arguments(**{'Download URL': download_url}))
    result = obj.codelists

    assert len(result) == 2
    assert result['bidStatistics.csv'].fieldnames == ['Category', 'Code', 'Title', 'Description', 'Min', 'Max',
                                                      'Required by']
コード例 #11
0
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)
コード例 #12
0
def test_codelists_without_metadata():
    download_url = 'https://api.github.com/repos/open-contracting-extensions/ocds_location_extension/zipball/v1.1'
    obj = ExtensionVersion(arguments(**{'Download URL': download_url}))
    result = obj.codelists

    assert len(result) == 1
    assert result['locationGazeteers.csv'].fieldnames == ['Category', 'Code', 'Title', 'Description', 'Source',
                                                          'URI_Pattern']
コード例 #13
0
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)
コード例 #14
0
def test_files():
    obj = ExtensionVersion(arguments())
    data = obj.files

    assert 'LICENSE' in data

    # This method should not parse file contents.
    for value in data.values():
        assert isinstance(value, (bytes, str))
コード例 #15
0
def test_init():
    args = arguments()
    obj = ExtensionVersion(args)

    assert obj.id == args['Id']
    assert obj.date == args['Date']
    assert obj.version == args['Version']
    assert obj.base_url == args['Base URL']
    assert obj.download_url == args['Download URL']
コード例 #16
0
def test_schemas_without_metadata():
    download_url = 'https://api.github.com/repos/open-contracting-extensions/ocds_location_extension/zipball/v1.1'
    obj = ExtensionVersion(arguments(**{'Download URL': download_url}))
    result = obj.schemas

    assert len(result) == 3
    assert result['record-package-schema.json'] == {}
    assert result['release-package-schema.json'] == {}
    assert 'Location' in result['release-schema.json']['definitions']
コード例 #17
0
def test_metadata_old_format():
    # See https://raw.githubusercontent.com/open-contracting-extensions/ocds_location_extension/v1.1/extension.json
    download_url = 'https://api.github.com/repos/open-contracting-extensions/ocds_location_extension/zipball/v1.1'
    obj = ExtensionVersion(arguments(**{'Download URL': download_url}))
    result = obj.metadata

    assert result['name']['en'] == 'Location'
    assert result['description']['en'] == 'Communicates the location of proposed or executed contract delivery.'
    assert result['documentationUrl'] == {}
    assert result['compatibility'] == ['1.1']
コード例 #18
0
def test_schemas_without_metadata_or_download_url():
    base_url = 'https://raw.githubusercontent.com/open-contracting-extensions/ocds_location_extension/v1.1/'
    download_url = None
    obj = ExtensionVersion(arguments(**{'Base URL': base_url, 'Download URL': download_url}))
    result = obj.schemas

    assert len(result) == 3
    assert result['record-package-schema.json'] == {}
    assert result['release-package-schema.json'] == {}
    assert 'Location' in result['release-schema.json']['definitions']
コード例 #19
0
def test_as_dict():
    args = arguments()
    obj = ExtensionVersion(args)

    assert obj.as_dict() == {
        'id': args['Id'],
        'date': args['Date'],
        'version': args['Version'],
        'base_url': args['Base URL'],
        'download_url': args['Download URL'],
    }
コード例 #20
0
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']
コード例 #21
0
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'}
コード例 #22
0
def test_repository_url():
    obj = ExtensionVersion(arguments())
    result = obj.repository_url

    assert result == '[email protected]:open-contracting-extensions/ocds_location_extension.git'
コード例 #23
0
def test_get_url_file_urls():
    url = 'https://example.com/release-schema.json'

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

    assert obj.get_url('release-schema.json') == url
コード例 #24
0
def test_get_url():
    obj = ExtensionVersion(arguments())

    url = 'https://raw.githubusercontent.com/open-contracting-extensions/ocds_location_extension/v1.1.3/extension.json'

    assert obj.get_url('extension.json') == url
コード例 #25
0
def test_repository_name():
    obj = ExtensionVersion(arguments())
    result = obj.repository_name

    assert result == 'ocds_location_extension'
コード例 #26
0
def test_repr(args, expected):
    obj = ExtensionVersion(args)

    assert repr(obj) == expected
コード例 #27
0
def test_repository_user():
    obj = ExtensionVersion(arguments())
    result = obj.repository_user

    assert result == 'open-contracting-extensions'
コード例 #28
0
def test_repository_html_page():
    obj = ExtensionVersion(arguments())
    result = obj.repository_html_page

    assert result == 'https://github.com/open-contracting-extensions/ocds_location_extension'
コード例 #29
0
def test_get_latest_version_one():
    versions = [
        ExtensionVersion(arguments(**{'Version': '1'})),
    ]

    assert get_latest_version(versions).version == '1'
コード例 #30
0
def test_repository_full_name():
    obj = ExtensionVersion(arguments())
    result = obj.repository_full_name

    assert result == 'open-contracting-extensions/ocds_location_extension'