Beispiel #1
0
 def test_fails_on_invalid_json(self):
     payload = Exception(
         "could not access anchore service (user=None url=http://localhost:8228/v1)"
     )
     result = utils.format_error_output(self.config, "policy", {}, payload)
     assert (
         result
         == "Error: could not access anchore service (user=None url=http://localhost:8228/v1)\n"
     )
Beispiel #2
0
 def test_invalid_account(self):
     result = utils.format_error_output(
         self.config,
         "account_delete",
         {},
         '{"message": "Invalid account state change requested"}',
     )
     assert "Error: Invalid account state change requested" in result
     assert (
         "NOTE: accounts must be disabled (anchore-cli account disable <account>)"
         in result
     )
Beispiel #3
0
 def test_state_change_is_valid(self):
     result = utils.format_error_output(self.config, "account_delete", {}, '{"message": "Unable to delete account"}')
     assert 'Error: Unable to delete account\n' == result
Beispiel #4
0
 def test_builds_valid_json_on_failure(self):
     result = utils.format_error_output(self.config, "policy", {}, 'invalid JSON!')
     assert result == '{\n    "message": "invalid JSON!"\n}'
Beispiel #5
0
 def test_loads_valid_json(self):
     result = utils.format_error_output(self.config, "policy", {}, '{"message": "valid JSON"}')
     assert result == '{\n    "message": "valid JSON"\n}'
Beispiel #6
0
 def test_detail_is_included(self):
     result = utils.format_error_output(self.config, "policy", {}, '{"detail": "\'id\' is missing"}')
     assert result == "Detail: 'id' is missing\n"
Beispiel #7
0
 def test_message_is_included(self):
     result = utils.format_error_output(self.config, "policy", {}, '{"message": "invalid input!"}')
     assert result == 'Error: invalid input!\n'
Beispiel #8
0
 def test_httpcode_is_included(self):
     result = utils.format_error_output(self.config, "policy", {}, '{"httpcode": 200}')
     assert result == 'HTTP Code: 200\n'
Beispiel #9
0
 def test_empty_json_fallsback(self):
     result = utils.format_error_output(self.config, "policy", {}, "{}")
     assert result == '{}'