Test character field handling with various dodgy/edge-case strings.
(db)
| 106 | @pytest.mark.asyncio |
| 107 | @test.requireCapability(dialect=NotEQ("mssql")) |
| 108 | async def test_char_fuzz(db): |
| 109 | """Test character field handling with various dodgy/edge-case strings.""" |
| 110 | conn = db.db() |
| 111 | |
| 112 | for char in DODGY_STRINGS: |
| 113 | # print(repr(char)) |
| 114 | if "\x00" in char and conn.capabilities.dialect in ["postgres"]: |
| 115 | # PostgreSQL doesn't support null values as text. Ever. So skip these. |
| 116 | continue |
| 117 | |
| 118 | # Create |
| 119 | obj1 = await CharFields.create(char=char) |
| 120 | |
| 121 | # Get-by-pk, and confirm that reading is correct |
| 122 | obj2 = await CharFields.get(pk=obj1.pk) |
| 123 | assert char == obj2.char |
| 124 | |
| 125 | # Update data using a queryset, confirm that update is correct |
| 126 | await CharFields.filter(pk=obj1.pk).update(char="a") |
| 127 | await CharFields.filter(pk=obj1.pk).update(char=char) |
| 128 | obj3 = await CharFields.get(pk=obj1.pk) |
| 129 | assert char == obj3.char |
| 130 | |
| 131 | # Filter by value in queryset, and confirm that it fetched the right one |
| 132 | obj4 = await CharFields.get(pk=obj1.pk, char=char) |
| 133 | assert obj1.pk == obj4.pk |
| 134 | assert char == obj4.char |
| 135 | |
| 136 | # LIKE statements are not strict, so require all of these to match |
| 137 | obj5 = await CharFields.get( |
| 138 | pk=obj1.pk, |
| 139 | char__startswith=char, |
| 140 | char__endswith=char, |
| 141 | char__contains=char, |
| 142 | char__istartswith=char, |
| 143 | char__iendswith=char, |
| 144 | char__icontains=char, |
| 145 | ) |
| 146 | assert obj1.pk == obj5.pk |
| 147 | assert char == obj5.char |
| 148 | |
| 149 | # Filter by a function |
| 150 | obj6 = ( |
| 151 | await CharFields.annotate(upper_char=Upper("char")) |
| 152 | .filter(id=obj1.pk, upper_char=Upper("char")) |
| 153 | .first() |
| 154 | ) |
| 155 | assert obj1.pk == obj6.pk |
| 156 | assert char == obj6.char |
nothing calls this directly
no test coverage detected
searching dependent graphs…