Skip to content

Commit f4ac9c7

Browse files
author
Kevin Hannegan
committed
update tests, story api client
1 parent 9f58096 commit f4ac9c7

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

presalytics/lib/exceptions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ def __init__(self, message=None, status_code=None):
6363
message = "Status Code: {0}".format(status_code)
6464
else:
6565
if status_code:
66-
message = message + ". Status Code: {0}".format(status_code)
66+
try:
67+
message = message.decode('utf-8')
68+
except Exception:
69+
pass
70+
message = str(message) + ". Status Code: {0}".format(status_code)
6771
super().__init__(message)
6872

6973

sub_packages/story/spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
SPEC = {
1010
"update": True,
1111
"update_type": "patch",
12-
"endpoint": "{0}/no_tags_spec".format(host),
12+
"endpoint": "{0}/story/no_tags_spec".format(host),
1313
"package_name": "presalytics_story",
1414
"package_url": "https://github.com/presalytics/story-python-client.git",
1515
"readme_path": os.path.join(os.path.dirname(os.path.realpath(__file__)), "README.md"),

test/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from functools import lru_cache
2+
import presalytics
3+
4+
@lru_cache(maxsize=None)
5+
def get_test_client():
6+
client = presalytics.Client()
7+
return client

test/files/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
PRESALYTICS = {
88
'USERNAME': os.environ['PRESALYTICS_USERNAME'],
99
'PASSWORD': os.environ['PRESALYTICS_PASSWORD'],
10+
'CLIENT_ID': os.environ.get('CLIENT_ID'),
11+
'CLIENT_SECRET': os.environ.get('CLIENT_SECRET'),
1012
'HOSTS': {}
1113
}
1214

test/star.pptx

35.1 KB
Binary file not shown.

test/test_components.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import presalytics
77
import io
88
import lxml
9+
from test import get_test_client
910
if typing.TYPE_CHECKING:
1011
from presalytics.client.presalytics_story import Story, OoxmlDocument
1112
from presalytics.client.presalytics_ooxml_automation.models import ChartChartDataDTO, TableTableDataDTO
@@ -15,10 +16,8 @@ class TestComponents(unittest.TestCase):
1516
"""
1617
Test module features thatr render stories to dashboards or other formats
1718
"""
18-
def setUp(self):
19-
pass
2019

21-
def test_render_matplotlib_plot(self):
20+
def test_render_matploytlib_plot(self):
2221
presalytics.autodiscover_paths.append('test/files')
2322
presalytics.COMPONENTS = presalytics.story.components.ComponentRegistry(autodiscover_paths=presalytics.autodiscover_paths)
2423
test_file = os.path.join(os.path.dirname(__file__), 'files', 'matplotlib-outline.yaml')
@@ -33,8 +32,7 @@ def test_xml_widget(self):
3332
story = presalytics.create_story_from_ooxml_file(tmp_filename)
3433
outline = presalytics.StoryOutline.load(story.outline)
3534
old_widget = outline.pages[0].widgets[0]
36-
client = presalytics.Client()
37-
childs = client.ooxml_automation.documents_childobjects_get_id(old_widget.data["document_ooxml_id"])
35+
childs = get_test_client().ooxml_automation.documents_childobjects_get_id(old_widget.data["document_ooxml_id"])
3836
endpoint_map = presalytics.OoxmlEndpointMap.shape()
3937
object_type = endpoint_map.get_object_type()
4038
info = next(x for x in childs if x.object_type == object_type)
@@ -67,7 +65,7 @@ def test_xml_widget(self):
6765

6866
presalytics.COMPONENTS.register(widget)
6967
story.outline = outline.dump()
70-
client.story.story_id_put(story.id, story)
68+
get_test_client().story.story_id_put(story.id, story)
7169
html = presalytics.Revealer(outline).package_as_standalone().decode('utf-8')
7270
self.assertIsInstance(html, str)
7371
os.remove(tmp_filename)
@@ -89,8 +87,7 @@ def test_bytesio_upload(self):
8987
with open(test_file, 'rb') as f:
9088
_bytes = io.BytesIO(f.read())
9189

92-
client = presalytics.Client()
93-
story = presalytics.story_post_file_bytes(client, _bytes, "testfile.pptx")
90+
story = presalytics.story_post_file_bytes(get_test_client(), _bytes, "testfile.pptx")
9491
from presalytics.client.presalytics_story.models.story import Story
9592
self.assertIsInstance(story, Story)
9693

@@ -123,11 +120,10 @@ def test_chart_update(self):
123120
document: "OoxmlDocument"
124121

125122
test_file = os.path.join(os.path.dirname(__file__), "files", "bubblechart.pptx")
126-
client = presalytics.Client()
127-
story = client.story.story_post_file(file=[test_file])
128-
story_detailed = client.story.story_id_get(story.id, include_relationships=True)
123+
story = get_test_client().story.story_post_file(file=[test_file])
124+
story_detailed = get_test_client().story.story_id_get(story.id, include_relationships=True)
129125
document = story_detailed.ooxml_documents[0]
130-
object_tree = client.ooxml_automation.documents_childobjects_get_id(document.ooxml_automation_id)
126+
object_tree = get_test_client().ooxml_automation.documents_childobjects_get_id(document.ooxml_automation_id)
131127
endpoint_map = presalytics.OoxmlEndpointMap.chart()
132128
object_type = endpoint_map.get_object_type()
133129
chart_id = next(entity.entity_id for entity in object_tree if entity.object_type == object_type)
@@ -170,11 +166,10 @@ def test_table_update(self):
170166
dto: "TableTableDataDTO"
171167

172168
test_file = os.path.join(os.path.dirname(__file__), "files", "table.pptx")
173-
client = presalytics.Client()
174-
story = client.story.story_post_file(file=[test_file])
175-
story_detailed = client.story.story_id_get(story.id, include_relationships=True)
169+
story = get_test_client().story.story_post_file(file=[test_file])
170+
story_detailed = get_test_client().story.story_id_get(story.id, include_relationships=True)
176171
document = story_detailed.ooxml_documents[0]
177-
object_tree = client.ooxml_automation.documents_childobjects_get_id(document.ooxml_automation_id)
172+
object_tree = get_test_client().ooxml_automation.documents_childobjects_get_id(document.ooxml_automation_id)
178173
endpoint_map = presalytics.OoxmlEndpointMap.table()
179174
object_type = endpoint_map.get_object_type()
180175
table_id = next(entity.entity_id for entity in object_tree if entity.object_type == object_type)

0 commit comments

Comments
 (0)