40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import io
|
|
import json
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
from tools.step_service.server import create_app
|
|
|
|
|
|
class StepServerTests(unittest.TestCase):
|
|
def test_rejects_missing_file(self):
|
|
app = create_app(mock.Mock())
|
|
client = app.test_client()
|
|
|
|
response = client.post("/save-step", data={"deletedPaths": "[]"})
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
def test_streams_generated_step(self):
|
|
worker = mock.Mock()
|
|
worker.trim_step_file.return_value = (b"STEPDATA", "edited.step")
|
|
app = create_app(worker)
|
|
client = app.test_client()
|
|
|
|
response = client.post(
|
|
"/save-step",
|
|
data={
|
|
"file": (io.BytesIO(b"INPUT"), "demo.step"),
|
|
"deletedPaths": json.dumps(["0/1"]),
|
|
},
|
|
content_type="multipart/form-data",
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.data, b"STEPDATA")
|
|
self.assertEqual(response.headers["Content-Disposition"], 'attachment; filename="edited.step"')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|