Skip to content

Commit

Permalink
Merge c7ac28b into b11bbf6
Browse files Browse the repository at this point in the history
  • Loading branch information
sonofmun committed Apr 10, 2019
2 parents b11bbf6 + c7ac28b commit 9d10d34
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 2019-04-10 2.1.1dev0 @sonofmun

- Corrected JSON.Std export for metadata to include all objects for a predicate

### 2018-06-25 2.0.8 @sonofmun

- Corrected error on the empty references exception from 2.0.7
Expand Down
2 changes: 1 addition & 1 deletion MyCapytain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"""

__version__ = "2.1.0dev0"
__version__ = "2.1.1dev0"
7 changes: 6 additions & 1 deletion MyCapytain/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ def __export__(self, output=Mimetypes.JSON.Std, only=None, exclude=None, **kwarg
if predicate not in out:
out[predicate] = {}
if isinstance(object, Literal):
out[predicate][object.language] = object.title()
if object.language in out[predicate]:
if isinstance(out[predicate][object.language], str):
out[predicate][object.language] = [out[predicate][object.language]]
out[predicate][object.language].append(object.title())
else:
out[predicate][object.language] = object.title()
del graph
return out

Expand Down
16 changes: 15 additions & 1 deletion tests/common/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from rdflib.namespace import DC
from MyCapytain.common.metadata import Metadata
from MyCapytain.common.constants import RDF_NAMESPACES, Mimetypes
from unittest import TestCase
Expand Down Expand Up @@ -134,4 +135,17 @@ def test_export_exclude(self):
{
'https://w3id.org/dts/api#description': {'fre': 'Subtitle', 'eng': 'Subtitle'}
}
)
)

def test_export_multiple_values_JSON(self):
m = Metadata()
m.add(DC.contributor, "Me", lang="eng")
m.add(DC.contributor, "You", lang="eng")
m.add(DC.contributor, "Ich", lang="deu")
m.add(DC.contributor, "Du", lang="deu")

self.assertCountEqual(
m.export(Mimetypes.JSON.Std),
{'http://purl.org/dc/elements/1.1/contributor': {'deu': ['Du', 'Ich'],
'eng': ['Me', 'You']}}
)

0 comments on commit 9d10d34

Please sign in to comment.