Skip to content

Commit

Permalink
Allow testing actors with config models (oamg#559)
Browse files Browse the repository at this point in the history
Currently, when tested actor runs and tries to access workflow
config, it fails with WorkflowConfigNotAvailable. Apart from
feeding the actor a mock config model, we need to also make
it aware it should us the config.
  • Loading branch information
Rezney authored and jmikovic committed Sep 11, 2019
1 parent a0ecbf1 commit ba51863
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/source/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def test_actor_execution(current_actor_context):
assert current_actor_context.consume(ProducedExampleModel)[0].value == 3
```

In case your actor uses `ConfigModel` for consuming workflow specific configuration, run the actor in the test as:

```python
current_actor_context.run(config_model=ConfigModel(os_release=OSRelease()))
```

#### Fixtures

The unit testing support was first implemented with the help of
Expand Down
12 changes: 10 additions & 2 deletions leapp/snactor/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,21 @@ def feed(self, *models):
for model in models:
self._messaging.feed(model, self)

def run(self):
def run(self, config_model=None):
"""
Execute the current actor.
:param config_model: Config model for the actor to consume.
:type config_model: Config model instance derived from :py:class:`leapp.models.Model`
:return: None
"""
self._actor(messaging=self._messaging).run()
config_model_cls = config_model.__class__ if config_model else None
if config_model:
self._messaging.feed(config_model, self)
# we have to make messaging system aware of config model being used as this is normally done by workflow
self._messaging._config_models = (config_model_cls,)
# the same as above applies here for actor
self._actor(messaging=self._messaging, config_model=config_model_cls).run()

def messages(self):
"""
Expand Down

0 comments on commit ba51863

Please sign in to comment.