2020-02-29 22:22:38 +00:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
|
|
|
from tests.base_test import BaseTest
|
2020-05-22 19:30:22 +00:00
|
|
|
from crc import app
|
2020-02-29 22:22:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestStudyApi(BaseTest):
|
|
|
|
|
|
|
|
def test_render_markdown(self):
|
|
|
|
template = "My name is {{name}}"
|
|
|
|
data = {"name": "Dan"}
|
|
|
|
rv = self.app.get('/v1.0/render_markdown?template=%s&data=%s' %
|
|
|
|
(template, json.dumps(data)))
|
|
|
|
self.assert_success(rv)
|
|
|
|
self.assertEqual("My name is Dan", rv.get_data(as_text=True))
|
|
|
|
|
|
|
|
def test_render_docx(self):
|
|
|
|
filepath = os.path.join(app.root_path, '..', 'tests', 'data', 'table.docx')
|
2020-03-03 18:50:22 +00:00
|
|
|
template_data = {"hippa": [
|
|
|
|
{"option": "Name", "selected": True, "stored": ["Record at UVA", "Stored Long Term"]},
|
2020-02-29 22:22:38 +00:00
|
|
|
{"option": "Address", "selected": False},
|
|
|
|
{"option": "Phone", "selected": True, "stored": ["Send or Transmit outside of UVA"]}]}
|
|
|
|
with open(filepath, 'rb') as f:
|
2020-05-22 19:30:22 +00:00
|
|
|
file_data = {'file': (f, 'my_new_file.bpmn'), 'data': json.dumps(template_data)}
|
|
|
|
rv = self.app.put('/v1.0/render_docx',
|
2020-02-29 22:22:38 +00:00
|
|
|
data=file_data, follow_redirects=True,
|
|
|
|
content_type='multipart/form-data')
|
|
|
|
self.assert_success(rv)
|
2020-05-22 19:30:22 +00:00
|
|
|
self.assertIsNotNone(rv.data)
|
2020-06-05 18:08:46 +00:00
|
|
|
self.assertEqual('application/octet-stream', rv.content_type)
|
2020-03-03 20:30:42 +00:00
|
|
|
|
|
|
|
def test_list_scripts(self):
|
|
|
|
rv = self.app.get('/v1.0/list_scripts')
|
|
|
|
self.assert_success(rv)
|
|
|
|
scripts = json.loads(rv.get_data(as_text=True))
|
|
|
|
self.assertTrue(len(scripts) > 1)
|
|
|
|
self.assertIsNotNone(scripts[0]['name'])
|
|
|
|
self.assertIsNotNone(scripts[0]['description'])
|