Skip to content

Commit 0d0cd57

Browse files
committed
fixed model_repository.get_model_contents
1 parent 9ad3b8c commit 0d0cd57

File tree

6 files changed

+380
-5
lines changed

6 files changed

+380
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Unreleased
33
----------
44
-
55

6+
v1.2.4 (2019-9-20)
7+
------------------
8+
**Bugfixes**
9+
- `model_repository.get_model_contents` no longer raises an HTTP 406 error.
10+
611
v1.2.3 (2019-8-23)
712
------------------
813
**Changes**

src/sasctl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
55
# SPDX-License-Identifier: Apache-2.0
66

7-
__version__ = '1.2.3'
7+
__version__ = '1.2.4'
88
__author__ = 'SAS'
99
__credits__ = ['Yi Jian Ching, Lucas De Paula, James Kochuba, Peter Tobac, '
1010
'Chris Toth, Jon Walker']

src/sasctl/_services/model_repository.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ def get_model_contents(cls, model):
143143
"""
144144
link = cls.get_model_link(model, 'contents', refresh=True)
145145

146-
if link is not None:
147-
return get(link.get('href'),
148-
headers={'Accept': link.get('itemType', '*/*')})
146+
return cls.request_link(link, 'contents')
149147

150148
@classmethod
151149
def create_model(cls, model, project,

src/sasctl/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,9 @@ def get_link(obj, rel):
792792
return links[0]
793793
elif len(links) > 1:
794794
return links
795+
elif isinstance(obj, dict) and 'rel' in obj and obj['rel'] == rel:
796+
# Object is already a link, just return it
797+
return obj
795798

796799

797800
def request_link(obj, rel, **kwargs):
@@ -813,7 +816,6 @@ def request_link(obj, rel, **kwargs):
813816
if link is None:
814817
raise ValueError("Link '%s' not found in object %s." % (rel, obj))
815818

816-
817819
return request(link['method'], link['href'], **kwargs)
818820

819821

tests/cassettes/tests.integration.test_model_repository.TestAStoreModel.test_get_model_contents.json

Lines changed: 360 additions & 0 deletions
Large diffs are not rendered by default.

tests/integration/test_model_repository.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ def test_model_import(self, astore):
2626

2727
assert self.model_name == model.name
2828

29+
def test_get_model_contents(self):
30+
# Resolves https://github.com/sassoftware/python-sasctl/issues/33
31+
content = mr.get_model_contents(self.model_name)
32+
33+
assert isinstance(content, list)
34+
assert 'AstoreMetadata.json' in [str(c) for c in content]
35+
assert 'ModelProperties.json' in [str(c) for c in content]
36+
assert 'inputVar.json' in [str(c) for c in content]
37+
assert 'outputVar.json' in [str(c) for c in content]
38+
2939
def test_create_model_version(self):
3040
r = mr.create_model_version(self.model_name)
3141
assert r.modelVersionName == '2.0'

0 commit comments

Comments
 (0)