|
| 1 | +# Copyright ScyllaDB, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import unittest |
| 16 | +from cassandra.protocol import TruncateError |
| 17 | + |
| 18 | + |
| 19 | +class TruncateErrorTest(unittest.TestCase): |
| 20 | + """ |
| 21 | + Test TruncateError exception behavior |
| 22 | + """ |
| 23 | + |
| 24 | + def test_truncate_error_message_includes_server_message(self): |
| 25 | + """ |
| 26 | + Verify that TruncateError includes the server-provided error message |
| 27 | + in addition to the generic summary. |
| 28 | + |
| 29 | + This addresses the issue where the error message was thought to be ignored. |
| 30 | + The server message should always be included in the error string representation. |
| 31 | + """ |
| 32 | + server_message = "unconfigured table test_table" |
| 33 | + error = TruncateError(code=0x1003, message=server_message, info=None) |
| 34 | + error_str = str(error) |
| 35 | + |
| 36 | + # Verify both the summary and server message are in the error string |
| 37 | + self.assertIn("Error during truncate", error_str, |
| 38 | + "Generic summary should be in error string") |
| 39 | + self.assertIn(server_message, error_str, |
| 40 | + "Server-provided message should be in error string") |
| 41 | + |
| 42 | + def test_truncate_error_code(self): |
| 43 | + """ |
| 44 | + Verify that TruncateError has the correct error code (0x1003) |
| 45 | + """ |
| 46 | + error = TruncateError(code=0x1003, message="test", info=None) |
| 47 | + self.assertEqual(error.code, 0x1003) |
| 48 | + self.assertEqual(error.error_code, 0x1003) |
| 49 | + |
| 50 | + def test_truncate_error_summary(self): |
| 51 | + """ |
| 52 | + Verify that TruncateError has the correct summary message |
| 53 | + """ |
| 54 | + error = TruncateError(code=0x1003, message="test", info=None) |
| 55 | + self.assertEqual(error.summary, "Error during truncate") |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == '__main__': |
| 59 | + unittest.main() |
0 commit comments