Skip to content

Commit

Permalink
Merge ec7b9a7 into aef48e3
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Oct 27, 2018
2 parents aef48e3 + ec7b9a7 commit c18b08d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## 0.0.5

* The `metadata` property of `ExtensionVersion` normalizes the contents of `extension.json` to provide consistent access.

## 0.0.4 (2018-06-27)

* The `metadata` property of `ExtensionVersion` is cached.
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -27,9 +27,9 @@
author = 'Open Contracting Partnership'

# The short X.Y version
version = '0.0.4'
version = '0.0.5'
# The full version, including alpha/beta/rc tags
release = '0.0.4'
release = '0.0.5'


# -- General configuration ---------------------------------------------------
Expand Down
17 changes: 16 additions & 1 deletion ocdsextensionregistry/extension_version.py
Expand Up @@ -17,6 +17,7 @@ def __init__(self, data):
self.version = data['Version']
self.base_url = data['Base URL']
self.download_url = data['Download URL']
self._metadata = {}
self._file_cache = {}

def update(self, other):
Expand Down Expand Up @@ -61,7 +62,21 @@ def metadata(self):
"""
Retrieves and returns the extension's extension.json file as a dict.
"""
return json.loads(self.remote('extension.json'))
if not self._metadata:
self._metadata = json.loads(self.remote('extension.json'))

for field in ('name', 'description', 'documentationUrl'):
# Add required fields.
if field not in self._metadata:
self._metadata[field] = {}
# Add language maps.
if isinstance(self._metadata[field], str):
self._metadata[field] = {'en': self._metadata[field]}

if 'compatibility' not in self._metadata or isinstance(self._metadata['compatibility'], str):
self._metadata['compatibility'] = ['1.1']

return self._metadata

@property
def repository_full_name(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@

setup(
name='ocdsextensionregistry',
version='0.0.4',
version='0.0.5',
author='James McKinney',
author_email='james@slashpoundbang.com',
url='https://github.com/open-contracting/extension_registry.py',
Expand Down
11 changes: 11 additions & 0 deletions tests/test_extension_version.py
Expand Up @@ -90,6 +90,17 @@ def test_metadata():
assert 'description' in result


def test_metadata_defaults():
download_url = 'https://api.github.com/repos/open-contracting/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']


def test_repository_full_name():
obj = ExtensionVersion(arguments())
result = obj.repository_full_name
Expand Down

0 comments on commit c18b08d

Please sign in to comment.