From 0e0642fab3145125104de151aee62a506dbc9904 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Thu, 16 Jan 2014 16:19:31 -0800 Subject: [PATCH] Use new context creation functions to attach context to a json structure. --- htsworkflow/submission/encoded.py | 11 +++++------ htsworkflow/submission/test/test_encoded.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/htsworkflow/submission/encoded.py b/htsworkflow/submission/encoded.py index 5072713..f113beb 100644 --- a/htsworkflow/submission/encoded.py +++ b/htsworkflow/submission/encoded.py @@ -109,7 +109,7 @@ class ENCODED: self.username = authenticators[0] self.password = authenticators[2] - def add_jsonld_context(self, tree, contexts, base): + def add_jsonld_context(self, tree, default_base): """Add contexts to various objects in the tree. tree is a json tree returned from the DCC's encoded database. @@ -118,11 +118,10 @@ class ENCODED: base, if supplied allows setting the base url that relative urls will be resolved against. """ - tree['@context'] = contexts[None] - tree['@context']['@base'] = base - self.add_jsonld_child_context(tree, contexts) + self.add_jsonld_child_context(tree, default_base) + self.add_jsonld_namespaces(tree['@context']) - def add_jsonld_child_context(self, obj, contexts): + def add_jsonld_child_context(self, obj, default_base): '''Add JSON-LD context to the encoded JSON. This is recursive because some of the IDs were relative URLs @@ -205,7 +204,7 @@ class ENCODED: ''' url = self.prepare_url(obj_id) json = self.get_json(obj_id, **kwargs) - self.add_jsonld_context(json, self.context, url) + self.add_jsonld_context(json, url) return json def get_object_type(self, obj): diff --git a/htsworkflow/submission/test/test_encoded.py b/htsworkflow/submission/test/test_encoded.py index 5e0e69b..21eed84 100644 --- a/htsworkflow/submission/test/test_encoded.py +++ b/htsworkflow/submission/test/test_encoded.py @@ -110,7 +110,7 @@ class TestEncoded(TestCase): url = encode.prepare_url('/libraries/ENCLB044ZZZ/?format=json&embed=False') schema_url = encode.get_schema_url(obj) - encode.add_jsonld_context(obj, encode.context, url) + encode.add_jsonld_context(obj, url) self.assertEqual(obj['biosample']['@context']['@base'], bio_base) self.assertEqual(obj['@context']['@vocab'], schema_url) -- 2.30.2