mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-23 05:08:32 +00:00
Added a File class, that we wrap around the FileModel so the api endpoints don't change, but File no longer holds refences to versions or dates of the file_data model, we figure this out based on a clean database structure. The ApprovalFile is directly related to the file_data_model - so no chance that a reviewer would review the incorrect version of a file.py Noticed that our FileType enum called "bpmn" "bpmm", hope this doesn't screw someone up. Workflows are directly related to the data_models that create the workflow spec it needs. So the files should always be there. There are no more hashes, and thus no more hash errors where it can't find the files to rebuild the workflow.py Not much to report here, other than I broke every single test in the system at one point. So I'm super concerned about this, and will be testing it a lot before creating the pull request.
74 lines
3.8 KiB
Python
74 lines
3.8 KiB
Python
from tests.base_test import BaseTest
|
|
from crc.services.file_service import FileService
|
|
from crc.services.workflow_processor import WorkflowProcessor
|
|
|
|
|
|
class TestFileService(BaseTest):
|
|
"""Largely tested via the test_file_api, and time is tight, but adding new tests here."""
|
|
|
|
def test_add_file_from_task_increments_version_and_replaces_on_subsequent_add(self):
|
|
self.load_example_data()
|
|
self.create_reference_document()
|
|
workflow = self.create_workflow('file_upload_form')
|
|
processor = WorkflowProcessor(workflow)
|
|
task = processor.next_task()
|
|
irb_code = "UVACompl_PRCAppr" # The first file referenced in pb required docs.
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
name="anything.png", content_type="text",
|
|
binary_data=b'1234', irb_doc_code=irb_code)
|
|
# Add the file again with different data
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
name="anything.png", content_type="text",
|
|
binary_data=b'5678', irb_doc_code=irb_code)
|
|
|
|
file_models = FileService.get_workflow_files(workflow_id=workflow.id)
|
|
self.assertEquals(1, len(file_models))
|
|
|
|
file_data = FileService.get_workflow_data_files(workflow_id=workflow.id)
|
|
self.assertEquals(1, len(file_data))
|
|
self.assertEquals(2, file_data[0].version)
|
|
|
|
|
|
def test_add_file_from_form_increments_version_and_replaces_on_subsequent_add_with_same_name(self):
|
|
self.load_example_data()
|
|
self.create_reference_document()
|
|
workflow = self.create_workflow('file_upload_form')
|
|
processor = WorkflowProcessor(workflow)
|
|
task = processor.next_task()
|
|
irb_code = "UVACompl_PRCAppr" # The first file referenced in pb required docs.
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
irb_doc_code=irb_code,
|
|
name="anything.png", content_type="text",
|
|
binary_data=b'1234')
|
|
# Add the file again with different data
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
irb_doc_code=irb_code,
|
|
name="anything.png", content_type="text",
|
|
binary_data=b'5678')
|
|
|
|
file_models = FileService.get_workflow_files(workflow_id=workflow.id)
|
|
self.assertEquals(1, len(file_models))
|
|
|
|
file_data = FileService.get_workflow_data_files(workflow_id=workflow.id)
|
|
self.assertEquals(1, len(file_data))
|
|
self.assertEquals(2, file_data[0].version)
|
|
|
|
def test_add_file_from_form_allows_multiple_files_with_different_names(self):
|
|
self.load_example_data()
|
|
self.create_reference_document()
|
|
workflow = self.create_workflow('file_upload_form')
|
|
processor = WorkflowProcessor(workflow)
|
|
task = processor.next_task()
|
|
irb_code = "UVACompl_PRCAppr" # The first file referenced in pb required docs.
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
irb_doc_code=irb_code,
|
|
name="anything.png", content_type="text",
|
|
binary_data=b'1234')
|
|
# Add the file again with different data
|
|
FileService.add_workflow_file(workflow_id=workflow.id,
|
|
irb_doc_code=irb_code,
|
|
name="a_different_thing.png", content_type="text",
|
|
binary_data=b'5678')
|
|
file_models = FileService.get_workflow_files(workflow_id=workflow.id)
|
|
self.assertEquals(2, len(file_models))
|