Exemplo n.º 1
0
    def test_common_case_no_op(self):
        workflow = Workflow.create_and_init()
        step = workflow.tabs.first().steps.create(order=1, module_id_name="x")

        with tempfile_context() as path:
            # Write two storedobjects
            path.write_text("abc123")
            create_stored_object(workflow.id, step.id, path)
            path.write_text("def456")
            create_stored_object(workflow.id, step.id, path)

        delete_old_files_to_enforce_storage_limits(step=step)
        self.assertEqual(step.stored_objects.count(), 2)
Exemplo n.º 2
0
    def test_common_case_no_op(self):
        workflow = Workflow.create_and_init()
        wf_module = workflow.tabs.first().wf_modules.create(order=1,
                                                            module_id_name="x")

        with tempfile_context() as path:
            # Write two storedobjects
            path.write_text("abc123")
            create_stored_object(workflow.id, wf_module.id, path)
            path.write_text("def456")
            create_stored_object(workflow.id, wf_module.id, path)

        enforce_storage_limits(wf_module)
        self.assertEqual(wf_module.stored_objects.count(), 2)
Exemplo n.º 3
0
    def test_always_leave_one(self):
        # ... and we also test that we can delete _multiple_ objects to make
        # way for a single one
        workflow = Workflow.create_and_init()
        step = workflow.tabs.first().steps.create(order=1, module_id_name="x")

        with tempfile_context() as path:
            # Write four storedobjects
            path.write_text("10 bytes..")
            create_stored_object(workflow.id, step.id, path)
            path.write_text("30 bytes......................")
            so2 = create_stored_object(workflow.id, step.id, path)  # newest

        delete_old_files_to_enforce_storage_limits(step=step)
        self.assertEqual(
            list(step.stored_objects.values_list("id", flat=True)), [so2.id])
Exemplo n.º 4
0
    def test_delete_oldest(self):
        # ... and we also test that we can delete _multiple_ objects to make
        # way for a single one
        workflow = Workflow.create_and_init()
        wf_module = workflow.tabs.first().wf_modules.create(order=1,
                                                            module_id_name="x")

        with tempfile_context() as path:
            # Write four storedobjects
            path.write_text("10 bytes..")
            create_stored_object(workflow.id, wf_module.id, path)
            path.write_text("20 bytes............")
            create_stored_object(workflow.id, wf_module.id, path)
            path.write_text("40 bytes................................")
            so3 = create_stored_object(workflow.id, wf_module.id, path)
            path.write_text("30 bytes......................")
            so4 = create_stored_object(workflow.id, wf_module.id,
                                       path)  # newest

        enforce_storage_limits(wf_module)
        self.assertEqual(
            list(
                wf_module.stored_objects.order_by("-stored_at").values_list(
                    "id", flat=True)),
            [so4.id, so3.id],
        )