@@ -310,7 +310,7 @@ def __init__(self, *args, **kwargs):
310
310
assert f1 .is_valid ()
311
311
312
312
f2 = FormForTestingIsValid (data2 )
313
- assert await sync_to_async ( f2 .is_valid ) ()
313
+ assert await f2 .ais_valid ()
314
314
315
315
obj = await f2 .asave ()
316
316
assert obj .character == char
@@ -965,25 +965,25 @@ def setup(self):
965
965
966
966
async def test_simple_unique (self ):
967
967
form = ProductForm ({"slug" : "teddy-bear-blue" })
968
- assert await sync_to_async ( form .is_valid ) ()
968
+ assert await form .ais_valid ()
969
969
obj = await form .asave ()
970
970
form = ProductForm ({"slug" : "teddy-bear-blue" })
971
- await sync_to_async ( form .full_clean )()
972
- assert len (form . errors ) == 1
973
- assert form . errors ["slug" ] == ["Product with this Slug already exists." ]
971
+ errors = await form .aerrors
972
+ assert len (errors ) == 1
973
+ assert errors ["slug" ] == ["Product with this Slug already exists." ]
974
974
form = ProductForm ({"slug" : "teddy-bear-blue" }, instance = obj )
975
- assert await sync_to_async ( form .is_valid ) ()
975
+ assert await form .ais_valid ()
976
976
977
977
async def test_unique_together (self ):
978
978
"""ModelForm test of unique_together constraint"""
979
979
form = PriceForm ({"price" : "6.00" , "quantity" : "1" })
980
- assert await sync_to_async ( form .is_valid ) ()
980
+ assert await form .ais_valid ()
981
981
await form .asave ()
982
982
form = PriceForm ({"price" : "6.00" , "quantity" : "1" })
983
- assert await sync_to_async ( form .is_valid ) () is False
984
- await sync_to_async ( form .full_clean )()
985
- assert len (form . errors ) == 1
986
- assert form . errors ["__all__" ] == [
983
+ assert await form .ais_valid () is False
984
+ errors = await form .aerrors
985
+ assert len (errors ) == 1
986
+ assert errors ["__all__" ] == [
987
987
"Price with this Price and Quantity already exists."
988
988
]
989
989
@@ -1044,15 +1044,13 @@ class Meta:
1044
1044
async def test_unique_null (self ):
1045
1045
title = "I May Be Wrong But I Doubt It"
1046
1046
form = BookForm ({"title" : title , "author" : self .writer .pk })
1047
- assert await sync_to_async ( form .is_valid ) ()
1047
+ assert await form .ais_valid ()
1048
1048
await form .asave ()
1049
1049
form = BookForm ({"title" : title , "author" : self .writer .pk })
1050
- assert await sync_to_async (form .is_valid )() is False
1051
- await sync_to_async (form .full_clean )()
1052
- assert len (form .errors ) == 1
1053
- assert form .errors ["__all__" ] == [
1054
- "Book with this Title and Author already exists."
1055
- ]
1050
+ assert await form .ais_valid () is False
1051
+ errors = await form .aerrors
1052
+ assert len (errors ) == 1
1053
+ assert errors ["__all__" ] == ["Book with this Title and Author already exists." ]
1056
1054
form = BookForm ({"title" : title })
1057
1055
assert form .is_valid ()
1058
1056
await form .asave ()
@@ -1079,12 +1077,12 @@ def test_inherited_unique(self):
1079
1077
async def test_inherited_unique_together (self ):
1080
1078
title = "Boss"
1081
1079
form = BookForm ({"title" : title , "author" : self .writer .pk })
1082
- assert await sync_to_async ( form .is_valid ) ()
1080
+ assert await form .ais_valid ()
1083
1081
await form .asave ()
1084
1082
form = DerivedBookForm (
1085
1083
{"title" : title , "author" : self .writer .pk , "isbn" : "12345" }
1086
1084
)
1087
- assert await sync_to_async ( form .is_valid ) () is False
1085
+ assert await form .ais_valid () is False
1088
1086
assert len (form .errors ) == 1
1089
1087
assert form .errors ["__all__" ] == [
1090
1088
"Book with this Title and Author already exists."
@@ -1134,10 +1132,10 @@ def test_explicitpk_unspecified(self):
1134
1132
async def test_explicitpk_unique (self ):
1135
1133
"""Ensure keys and blank character strings are tested for uniqueness."""
1136
1134
form = ExplicitPKForm ({"key" : "key1" , "desc" : "" })
1137
- assert await sync_to_async ( form .is_valid ) ()
1135
+ assert await form .ais_valid ()
1138
1136
await form .asave ()
1139
1137
form = ExplicitPKForm ({"key" : "key1" , "desc" : "" })
1140
- assert await sync_to_async ( form .is_valid ) () is False
1138
+ assert await form .ais_valid () is False
1141
1139
if connection .features .interprets_empty_strings_as_nulls :
1142
1140
assert len (form .errors ) == 1
1143
1141
assert form .errors ["key" ] == ["Explicit pk with this Key already exists." ]
@@ -1397,7 +1395,7 @@ async def test_initial_values(self):
1397
1395
},
1398
1396
)
1399
1397
assertHTMLEqual (
1400
- await sync_to_async ( f . as_ul ) (),
1398
+ await f . aas_ul (),
1401
1399
"""
1402
1400
<li>Headline:
1403
1401
<input type="text" name="headline" value="Your headline here" maxlength="50"
@@ -1446,9 +1444,9 @@ async def test_initial_values(self):
1446
1444
)
1447
1445
art_id_1 = art .id
1448
1446
1449
- f = await sync_to_async ( ArticleForm ) (auto_id = False , instance = art )
1447
+ f = await ArticleForm . from_async (auto_id = False , instance = art )
1450
1448
assertHTMLEqual (
1451
- await sync_to_async ( f . as_ul ) (),
1449
+ await f . aas_ul (),
1452
1450
"""
1453
1451
<li>Headline:
1454
1452
<input type="text" name="headline" value="Test article" maxlength="50"
@@ -1481,7 +1479,7 @@ async def test_initial_values(self):
1481
1479
% (self .w_woodward .pk , self .w_royko .pk , self .c1 .pk , self .c2 .pk , self .c3 .pk ),
1482
1480
)
1483
1481
1484
- f = await sync_to_async ( ArticleForm ) (
1482
+ f = await ArticleForm . from_async (
1485
1483
{
1486
1484
"headline" : "Test headline" ,
1487
1485
"slug" : "test-headline" ,
@@ -1491,8 +1489,7 @@ async def test_initial_values(self):
1491
1489
},
1492
1490
instance = art ,
1493
1491
)
1494
- await sync_to_async (f .full_clean )()
1495
- assert f .errors == {}
1492
+ assert await f .aerrors == {}
1496
1493
assert f .is_valid ()
1497
1494
test_art = await f .asave ()
1498
1495
assert test_art .id == art_id_1
@@ -1521,7 +1518,7 @@ def formfield_for_dbfield(db_field, **kwargs):
1521
1518
)
1522
1519
form = ModelForm ()
1523
1520
assertHTMLEqual (
1524
- await sync_to_async ( form .as_ul ) (),
1521
+ await form .aas_ul (),
1525
1522
"""<li><label for="id_headline">Headline:</label>
1526
1523
<input id="id_headline" type="text" name="headline" maxlength="50" required></li>
1527
1524
<li><label for="id_categories">Categories:</label>
@@ -1640,9 +1637,9 @@ async def test_multi_fields(self):
1640
1637
)
1641
1638
await new_art .categories .aadd (await Category .objects .aget (name = "Entertainment" ))
1642
1639
assert [art async for art in new_art .categories .all ()] == [self .c1 ]
1643
- f = await sync_to_async ( ArticleForm ) (auto_id = False , instance = new_art )
1640
+ f = await ArticleForm . from_async (auto_id = False , instance = new_art )
1644
1641
assertHTMLEqual (
1645
- await sync_to_async ( f . as_ul ) (),
1642
+ await f . aas_ul (),
1646
1643
"""
1647
1644
<li>Headline:
1648
1645
<input type="text" name="headline" value="New headline" maxlength="50"
@@ -1760,7 +1757,7 @@ async def test_m2m_editing(self):
1760
1757
# Now, submit form data with no categories. This deletes the existing
1761
1758
# categories.
1762
1759
form_data ["categories" ] = []
1763
- f = await sync_to_async ( ArticleForm ) (form_data , instance = new_art )
1760
+ f = await ArticleForm . from_async (form_data , instance = new_art )
1764
1761
new_art = await f .asave ()
1765
1762
assert new_art .id == art_id_1
1766
1763
new_art = await Article .objects .aget (id = art_id_1 )
@@ -1826,7 +1823,7 @@ async def test_runtime_choicefield_populated(self):
1826
1823
await self .create_basic_data ()
1827
1824
f = ArticleForm (auto_id = False )
1828
1825
assertHTMLEqual (
1829
- await sync_to_async ( f . as_ul ) (),
1826
+ await f . aas_ul (),
1830
1827
'<li>Headline: <input type="text" name="headline" maxlength="50" required>'
1831
1828
"</li>"
1832
1829
'<li>Slug: <input type="text" name="slug" maxlength="50" required></li>'
@@ -1855,7 +1852,7 @@ async def test_runtime_choicefield_populated(self):
1855
1852
c4 = await Category .objects .acreate (name = "Fourth" , url = "4th" )
1856
1853
w_bernstein = await Writer .objects .acreate (name = "Carl Bernstein" )
1857
1854
assertHTMLEqual (
1858
- await sync_to_async ( f . as_ul ) (),
1855
+ await f . aas_ul (),
1859
1856
'<li>Headline: <input type="text" name="headline" maxlength="50" required>'
1860
1857
"</li>"
1861
1858
'<li>Slug: <input type="text" name="slug" maxlength="50" required></li>'
@@ -1984,7 +1981,7 @@ def __init__(self, *args, **kwargs):
1984
1981
"article" : "lorem ipsum" ,
1985
1982
}
1986
1983
form = MyForm (data )
1987
- assert await sync_to_async ( form .is_valid ) ()
1984
+ assert await form .ais_valid ()
1988
1985
article = await form .asave ()
1989
1986
assert article .writer == w
1990
1987
@@ -2264,7 +2261,7 @@ class Meta:
2264
2261
2265
2262
form = WriterProfileForm ()
2266
2263
assertHTMLEqual (
2267
- await sync_to_async ( form .as_p ) (),
2264
+ await form .aas_p (),
2268
2265
"""
2269
2266
<p><label for="id_writer">Writer:</label>
2270
2267
<select name="writer" id="id_writer" required>
@@ -2291,7 +2288,7 @@ class Meta:
2291
2288
2292
2289
form = WriterProfileForm (instance = instance )
2293
2290
assertHTMLEqual (
2294
- await sync_to_async ( form .as_p ) (),
2291
+ await form .aas_p (),
2295
2292
"""
2296
2293
<p><label for="id_writer">Writer:</label>
2297
2294
<select name="writer" id="id_writer" required>
0 commit comments