From 9a195bedad6d7b5edfbfa2354b7c77a1d0a7eb22 Mon Sep 17 00:00:00 2001 From: Dan Funk Date: Tue, 31 Dec 2019 11:31:30 -0500 Subject: [PATCH] Fixing some caching issues and places where the updates were not being processed completed. And updates to the docker file. --- Dockerfile | 6 ++++++ crc/api/file.py | 4 +++- crc/api/workflow.py | 3 +++ crc/static/bpmn/random_fact/random_fact.bpmn | 6 +++--- tests/test_api_files.py | 7 +++++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 284ca06f..ec4f1516 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,10 @@ RUN pipenv install --dev ENV FLASK_APP=./crc/__init__.py +# run migrations +CMD ["pipenv", "run", "flask", "db", "upgrade"] +CMD ["pipenv", "run", "flask", "load-example-data"] + # include rejoiner code (gets overriden by local changes) COPY . /crc-workflow/ @@ -26,3 +30,5 @@ CMD ["pipenv", "run", "python", "/crc-workflow/run.py"] # expose ports EXPOSE 5000 + + diff --git a/crc/api/file.py b/crc/api/file.py index b6752ea0..cb989fb6 100644 --- a/crc/api/file.py +++ b/crc/api/file.py @@ -38,6 +38,7 @@ def update_file_from_request(file_model): db.session.add(file_data_model) db.session.add(file_model) + db.session.commit() db.session.flush() # Assure the id is set on the model before returning it. @@ -74,7 +75,8 @@ def get_file(file_id): return send_file( io.BytesIO(file_data.data), attachment_filename=file_data.file_model.name, - mimetype=file_data.file_model.content_type + mimetype=file_data.file_model.content_type, + cache_timeout=-1 # Don't cache these files on the browser. ) diff --git a/crc/api/workflow.py b/crc/api/workflow.py index b9be5e8c..8ad759cd 100644 --- a/crc/api/workflow.py +++ b/crc/api/workflow.py @@ -14,8 +14,11 @@ def get_workflow(workflow_id): workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first() return schema.dump(workflow) + def delete(workflow_id): db.session.query(WorkflowModel).filter_by(id=workflow_id).delete() + db.session.commit() + def get_tasks(workflow_id): workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first() diff --git a/crc/static/bpmn/random_fact/random_fact.bpmn b/crc/static/bpmn/random_fact/random_fact.bpmn index 38ea7e86..4c039061 100644 --- a/crc/static/bpmn/random_fact/random_fact.bpmn +++ b/crc/static/bpmn/random_fact/random_fact.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_0ik56h0 @@ -14,7 +14,7 @@ - + @@ -33,7 +33,7 @@ - + diff --git a/tests/test_api_files.py b/tests/test_api_files.py index c95afd98..f89bb2a5 100644 --- a/tests/test_api_files.py +++ b/tests/test_api_files.py @@ -4,7 +4,7 @@ import unittest from datetime import datetime from crc import db -from crc.models import WorkflowSpecModel, FileModel, FileType, FileSchema +from crc.models import WorkflowSpecModel, FileModel, FileType, FileSchema, FileDataModel from tests.base_test import BaseTest @@ -68,7 +68,7 @@ class TestApiFiles(BaseTest, unittest.TestCase): file = db.session.query(FileModel).filter_by(workflow_spec_id = spec.id).first() data = {} - data['file'] = io.BytesIO(b"abcdef"), 'random_fact.bpmn' + data['file'] = io.BytesIO(b"hijklim"), 'random_fact.bpmn' rv = self.app.put('/v1.0/file/%i' % file.id, data=data, follow_redirects=True, content_type='multipart/form-data') @@ -83,6 +83,9 @@ class TestApiFiles(BaseTest, unittest.TestCase): self.assertEqual("application/octet-stream", file.content_type) self.assertEqual(spec.id, file.workflow_spec_id) + data_model = db.session.query(FileDataModel).filter_by(file_model_id = file.id).first() + self.assertEqual(b"hijklim", data_model.data) + def test_get_file(self): self.load_example_data() spec = db.session.query(WorkflowSpecModel).first()