|
5 | 5 | # https://developers.google.com/open-source/licenses/bsd |
6 | 6 |
|
7 | 7 |
|
| 8 | +import datetime |
8 | 9 | from unittest import mock |
9 | 10 |
|
10 | 11 | from django.db import NotSupportedError, connection, connections |
@@ -53,6 +54,50 @@ def test_quote_value_escapes_string(self): |
53 | 54 | "'\\\\\\'; DROP TABLE t; --'", |
54 | 55 | ) |
55 | 56 |
|
| 57 | + def test_quote_value_escapes_newlines_and_carriage_returns(self): |
| 58 | + schema_editor = DatabaseSchemaEditor(self.connection) |
| 59 | + self.assertEqual( |
| 60 | + schema_editor.quote_value("line1\nline2"), |
| 61 | + "'line1\\nline2'", |
| 62 | + ) |
| 63 | + self.assertEqual( |
| 64 | + schema_editor.quote_value("line1\r\nline2"), |
| 65 | + "'line1\\r\\nline2'", |
| 66 | + ) |
| 67 | + |
| 68 | + def test_quote_value_handles_none(self): |
| 69 | + schema_editor = DatabaseSchemaEditor(self.connection) |
| 70 | + self.assertEqual(schema_editor.quote_value(None), "NULL") |
| 71 | + |
| 72 | + def test_quote_value_handles_date_and_datetime(self): |
| 73 | + schema_editor = DatabaseSchemaEditor(self.connection) |
| 74 | + self.assertEqual( |
| 75 | + schema_editor.quote_value(datetime.date(2026, 9, 4)), |
| 76 | + "'2026-09-04'", |
| 77 | + ) |
| 78 | + self.assertEqual( |
| 79 | + schema_editor.quote_value(datetime.datetime(2026, 9, 4, 12, 0, 0)), |
| 80 | + "'2026-09-04 12:00:00'", |
| 81 | + ) |
| 82 | + |
| 83 | + def test_quote_value_handles_bytes(self): |
| 84 | + schema_editor = DatabaseSchemaEditor(self.connection) |
| 85 | + self.assertEqual(schema_editor.quote_value(b"abc"), "b'abc'") |
| 86 | + self.assertEqual( |
| 87 | + schema_editor.quote_value(b"\x00'\\\n\xff"), |
| 88 | + "b'\\x00\\x27\\x5c\\x0a\\xff'", |
| 89 | + ) |
| 90 | + |
| 91 | + def test_quote_value_booleans(self): |
| 92 | + schema_editor = DatabaseSchemaEditor(self.connection) |
| 93 | + self.assertEqual(schema_editor.quote_value(True), "TRUE") |
| 94 | + self.assertEqual(schema_editor.quote_value(False), "FALSE") |
| 95 | + |
| 96 | + def test_prepare_default_delegates_to_quote_value(self): |
| 97 | + schema_editor = DatabaseSchemaEditor(self.connection) |
| 98 | + self.assertEqual(schema_editor.prepare_default("o'brien"), "'o\\'brien'") |
| 99 | + self.assertEqual(schema_editor.prepare_default(True), "TRUE") |
| 100 | + |
56 | 101 | def test_skip_default(self): |
57 | 102 | """ |
58 | 103 | Tries skipping default as Cloud spanner doesn't support it. |
|
0 commit comments