|
2 | 2 | import os |
3 | 3 |
|
4 | 4 | import boto.swf |
| 5 | +from click.testing import CliRunner |
| 6 | +from sure import expect |
5 | 7 | from vcr import VCR |
6 | 8 |
|
7 | 9 | import simpleflow.command # NOQA |
8 | 10 | from tests.utils import IntegrationTestCase |
9 | 11 |
|
| 12 | +from simpleflow.utils import json_dumps |
| 13 | + |
| 14 | +if False: |
| 15 | + from typing import List, Union |
| 16 | + from click.testing import Result |
| 17 | + |
| 18 | + |
10 | 19 | # Default SWF parameters |
11 | 20 | os.environ["AWS_DEFAULT_REGION"] = "us-east-1" |
12 | 21 | os.environ["SWF_DOMAIN"] = "TestDomain" |
@@ -70,3 +79,37 @@ def get_events(self, run_id): |
70 | 79 | events.extend(response['events']) |
71 | 80 | next_page = response.get('nextPageToken') |
72 | 81 | return events |
| 82 | + |
| 83 | + def invoke(self, command, arguments): |
| 84 | + # type: (str, Union(str, List[str])) -> Result |
| 85 | + if not hasattr(self, "runner"): |
| 86 | + self.runner = CliRunner() |
| 87 | + if isinstance(arguments, str): |
| 88 | + arguments = arguments.split(" ") |
| 89 | + print('simpleflow {} {}'.format(command, ' '.join(arguments))) |
| 90 | + return self.runner.invoke(command, arguments, catch_exceptions=False) |
| 91 | + |
| 92 | + def run_standalone(self, workflow_name, *args, **kwargs): |
| 93 | + input = json_dumps(dict(args=args, kwargs=kwargs)) |
| 94 | + result = self.invoke( |
| 95 | + simpleflow.command.cli, |
| 96 | + [ |
| 97 | + "standalone", |
| 98 | + "--workflow-id", |
| 99 | + str(self.workflow_id), |
| 100 | + "--input", |
| 101 | + input, |
| 102 | + "--nb-deciders", |
| 103 | + "2", |
| 104 | + "--nb-workers", |
| 105 | + "2", |
| 106 | + workflow_name, |
| 107 | + ], |
| 108 | + ) |
| 109 | + expect(result.exit_code).to.equal(0) |
| 110 | + lines = result.output.split("\n") |
| 111 | + start_line = [line for line in lines if line.startswith(self.workflow_id)][0] |
| 112 | + _, run_id = start_line.split(" ", 1) |
| 113 | + |
| 114 | + events = self.get_events(run_id) |
| 115 | + return events |
0 commit comments