-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#37] Explicitly handle transactions in the runner
- Loading branch information
1 parent
388dc94
commit a971f55
Showing
5 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from django.contrib.auth.models import User | ||
|
||
import pytest | ||
|
||
from testapp.configuration import UserConfigurationStep | ||
from tests.conftest import TestStep | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
@pytest.fixture() | ||
def yaml_file_with_valid_configuration(yaml_file_factory, test_step_valid_config): | ||
yaml_path = yaml_file_factory( | ||
{ | ||
"user_configuration_enabled": True, | ||
"user_configuration": { | ||
"username": "demo", | ||
"password": "secret", | ||
}, | ||
"some_extra_attrs": "should be allowed", | ||
} | ||
| test_step_valid_config | ||
) | ||
|
||
return yaml_path | ||
|
||
|
||
def test_runner_rolls_back_all_on_failing_step( | ||
runner_factory, yaml_file_with_valid_configuration, step_execute_mock | ||
): | ||
runner = runner_factory( | ||
steps=[UserConfigurationStep, TestStep], | ||
yaml_source=yaml_file_with_valid_configuration, | ||
) | ||
exc = Exception() | ||
step_execute_mock.side_effect = exc | ||
|
||
user_configuration_step_result, test_step_result = runner.execute_all() | ||
|
||
assert test_step_result.has_run | ||
assert test_step_result.run_exception is exc | ||
|
||
assert user_configuration_step_result.has_run | ||
assert user_configuration_step_result.run_exception is None | ||
assert User.objects.count() == 0 | ||
|
||
step_execute_mock.side_effect = None | ||
|
||
user_configuration_step_result, test_step_result = runner.execute_all() | ||
|
||
assert test_step_result.has_run | ||
assert test_step_result.run_exception is None | ||
|
||
assert user_configuration_step_result.has_run | ||
assert user_configuration_step_result.run_exception is None | ||
assert User.objects.count() == 1 |