コード例 #1
0
    def test_adding_flow(self):

        def execute_first_step(data):
            pass

        def add_flow_callback(request):
            body = json.loads(request.body)
            self.assertDictEqual(
                body,
                {'instance': {'url': 'http://localhost:5000', 'name': 'testSlims'},
                 'flow':
                    {'id': 'myFlow',
                     'name': 'My flow in python',
                     'usage': 'CONTENT_MANAGEMENT',
                     'steps': [
                         {'hidden': False,
                          'name': 'first step',
                          'input': {'parameters': [{'type': 'STRING', 'name': 'text', 'label': 'Text'}]},
                          'process': {'route': 'myFlow/0', 'asynchronous': False},
                          'output': {'parameters': [{'type': 'FILE', 'name': 'file'}]}
                          }
                     ],
                     'pythonApiFlow': True
                     }
                 })

            return (200, {}, json.dumps({}))

        responses.add_callback(
            responses.POST,
            'http://localhost:9999/rest/external/',
            callback=add_flow_callback,
            content_type='application/json',
        )

        slims = Slims("testSlims", "http://localhost:9999", "admin", "admin")
        slims.add_flow(
            flow_id="myFlow",
            name="My flow in python",
            usage="CONTENT_MANAGEMENT",
            steps=[
                Step(
                    name="first step",
                    action=execute_first_step,
                    input=[
                        text_input("text", "Text")
                    ],
                    output=[
                        file_output()
                    ]
                )
            ],
            testing=True)
コード例 #2
0
    def test_fail(self):
        def execute_first_step(flow_run):
            raise Exception("went wrong")

        step = Step(name="first step",
                    action=execute_first_step,
                    input=[text_input("text", "Text")],
                    output=[file_output()])

        flow_run = FlowRun(None, None, None)
        flow_run._update_status = MagicMock()
        flow_run.log = MagicMock()

        self.assertRaises(StepExecutionException, step.execute, flow_run)

        flow_run._update_status.assert_called_with(Status.FAILED)
コード例 #3
0
    def test_success(self):
        def execute_first_step(flow_run):
            print("Do Nothing")

        step = Step(name="first step",
                    action=execute_first_step,
                    input=[text_input("text", "Text")],
                    output=[file_output()])

        flow_run = FlowRun(None, None, {})
        flow_run._update_status = MagicMock()
        flow_run.log = MagicMock()

        step.execute(flow_run)

        flow_run._update_status.assert_called_with(Status.DONE)
from slims.slims import Slims
from slims.step import Step, file_output
from slims.output import file_value


def execute():
    # Make sure the path to the file exists
    return file_value('C:/Users/User/Downloads/file.txt')


slims = Slims("slims",
              url="http://127.0.0.1:9999/",
              token="devToken",
              local_host="0.0.0.0",
              local_port=5000)

slims.add_flow(flow_id="FLOW_0001",
               name="Download an file from server",
               usage="CONTENT_MANAGEMENT",
               steps=[
                   Step(name="This downloads a file.",
                        action=execute,
                        output=[file_output()])
               ])