Skip to content

Commit

Permalink
tests/integration: update some tests for updated error-messages
Browse files Browse the repository at this point in the history
I was in the process of cleaning up some error-messages, and it looks like
the docker-py tests were depending on strings that will be removed;

    =================================== FAILURES ===================================
    _____________ CreateContainerTest.test_create_with_restart_policy ______________
    tests/integration/api_container_test.py:126: in test_create_with_restart_policy
        assert 'You cannot remove ' in err
    E   AssertionError: assert 'You cannot remove ' in 'cannot remove container d11580f6078108691096ec8a23404a6bda9ad1d1b2bafe88b17d127a67728833: container is restarting: stop the container before removing or force remove'
    ____________________ ErrorsTest.test_api_error_parses_json _____________________
    tests/integration/errors_test.py:13: in test_api_error_parses_json
        assert 'You cannot remove a running container' in explanation
    E   AssertionError: assert 'You cannot remove a running container' in 'cannot remove container 4b90ce2e907dd0f99d0f561619b803e7a2a31809ced366c537874dd13f8a47ec: container is running: stop the container before removing or force remove'

This updates the tests to match on a string that will be present in both the
old and new error-messages, but added a "lower()", so that matching will be
done case-insensitive (Go errors generally should be lowercase).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Aug 14, 2023
1 parent 83e9322 commit 2c4f329
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/integration/api_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def test_create_with_restart_policy(self):
self.client.wait(id)
with pytest.raises(docker.errors.APIError) as exc:
self.client.remove_container(id)
err = exc.value.explanation
assert 'You cannot remove ' in err
err = exc.value.explanation.lower()
assert 'stop the container before removing' in err
self.client.remove_container(id, force=True)

def test_create_container_with_volumes_from(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/errors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_api_error_parses_json(self):
self.client.start(container['Id'])
with pytest.raises(APIError) as cm:
self.client.remove_container(container['Id'])
explanation = cm.value.explanation
assert 'You cannot remove a running container' in explanation
explanation = cm.value.explanation.lower()
assert 'stop the container before removing' in explanation
assert '{"message":' not in explanation
self.client.remove_container(container['Id'], force=True)

0 comments on commit 2c4f329

Please sign in to comment.