@@ -1336,14 +1336,124 @@ def test_qb_poly_07(self):
13361336 self .assertIsInstance (c , default .Chocolate )
13371337
13381338 def test_qb_array_agg_01 (self ):
1339- from models .orm import default , std
1339+ from models .orm_qb import default , std
13401340
13411341 agg = std .array_agg (default .User )
13421342 unpack = std .array_unpack (agg )
13431343
13441344 res = self .client .query (unpack )
13451345 self .assertEqual (len (res ), 6 )
13461346
1347+ def test_qb_cast_array_01 (self ):
1348+ # array[scalar] to array[scalar]
1349+ from models .orm_qb import std
1350+
1351+ result = self .client .get (
1352+ std .array [std .str ].cast (
1353+ std .array [std .int64 ](
1354+ [std .int64 (1 ), std .int64 (2 ), std .int64 (3 )]
1355+ )
1356+ )
1357+ )
1358+ self .assertEqual (result , ["1" , "2" , "3" ])
1359+
1360+ def test_qb_cast_array_02 (self ):
1361+ # array[enum] to array[scalar]
1362+ from models .orm_qb import default , std
1363+
1364+ result = self .client .get (
1365+ std .array [std .str ].cast (
1366+ std .array [default .Color ](
1367+ [
1368+ default .Color .Red ,
1369+ default .Color .Green ,
1370+ default .Color .Blue ,
1371+ ]
1372+ )
1373+ )
1374+ )
1375+ self .assertEqual (result , ["Red" , "Green" , "Blue" ])
1376+
1377+ def test_qb_cast_array_03 (self ):
1378+ # array[scalar] to array[enum]
1379+ from models .orm_qb import default , std
1380+
1381+ result = self .client .get (
1382+ std .array [default .Color ].cast (
1383+ std .array [std .str ](
1384+ [std .str ("Red" ), std .str ("Green" ), std .str ("Blue" )]
1385+ )
1386+ )
1387+ )
1388+ self .assertEqual (
1389+ result ,
1390+ [default .Color .Red , default .Color .Green , default .Color .Blue ],
1391+ )
1392+
1393+ def test_qb_cast_array_04 (self ):
1394+ # array[tuple] to array[tuple]
1395+ from models .orm_qb import default , std
1396+
1397+ result = self .client .get (
1398+ std .array [std .tuple [std .int64 , default .Color ]].cast (
1399+ std .array [std .tuple [std .str , std .str ]](
1400+ [
1401+ std .tuple [std .str , std .str ](
1402+ [std .str ("1" ), std .str ("Red" )]
1403+ ),
1404+ std .tuple [std .str , std .str ](
1405+ [std .str ("2" ), std .str ("Green" )]
1406+ ),
1407+ std .tuple [std .str , std .str ](
1408+ [std .str ("3" ), std .str ("Blue" )]
1409+ ),
1410+ ]
1411+ )
1412+ )
1413+ )
1414+ self .assertEqual (
1415+ result ,
1416+ [
1417+ (1 , default .Color .Red ),
1418+ (2 , default .Color .Green ),
1419+ (3 , default .Color .Blue ),
1420+ ],
1421+ )
1422+
1423+ def test_qb_cast_tuple_01 (self ):
1424+ # unnamed tuple to unnamed tuple
1425+ from models .orm_qb import default , std
1426+
1427+ result = self .client .get (
1428+ std .tuple [
1429+ std .int64 , default .Color , std .str , std .array [std .int64 ]
1430+ ].cast (
1431+ std .tuple [std .str , std .str , default .Color , std .array [std .str ]](
1432+ (
1433+ std .str ("1" ),
1434+ std .str ("Red" ),
1435+ default .Color .Green ,
1436+ std .array [std .str ](
1437+ [std .str ("2" ), std .str ("3" ), std .str ("4" )]
1438+ ),
1439+ )
1440+ )
1441+ )
1442+ )
1443+ self .assertEqual (result , (1 , default .Color .Red , "Green" , [2 , 3 , 4 ]))
1444+
1445+ def test_qb_cast_range_01 (self ):
1446+ # range to range
1447+ from gel .datatypes import range as _range
1448+ from models .orm_qb import std
1449+
1450+ result = self .client .get (
1451+ std .range [std .int64 ].cast (
1452+ std .range [std .int32 ](std .int32 (1 ), std .int32 (9 ))
1453+ )
1454+ )
1455+ self .assertEqual (result , _range .Range (std .int64 (1 ), std .int64 (9 )))
1456+
13471457
13481458class TestQueryBuilderModify (tb .ModelTestCase ):
13491459 """This test suite is for data manipulation using QB."""
@@ -1561,113 +1671,3 @@ def test_qb_cast_scalar_03(self):
15611671
15621672 result = self .client .get (default .Color .cast (std .str ("Red" )))
15631673 self .assertEqual (result , default .Color .Red )
1564-
1565- def test_qb_cast_array_01 (self ):
1566- # array[scalar] to array[scalar]
1567- from models .orm import std
1568-
1569- result = self .client .get (
1570- std .array [std .str ].cast (
1571- std .array [std .int64 ](
1572- [std .int64 (1 ), std .int64 (2 ), std .int64 (3 )]
1573- )
1574- )
1575- )
1576- self .assertEqual (result , ["1" , "2" , "3" ])
1577-
1578- def test_qb_cast_array_02 (self ):
1579- # array[enum] to array[scalar]
1580- from models .orm import default , std
1581-
1582- result = self .client .get (
1583- std .array [std .str ].cast (
1584- std .array [default .Color ](
1585- [
1586- default .Color .Red ,
1587- default .Color .Green ,
1588- default .Color .Blue ,
1589- ]
1590- )
1591- )
1592- )
1593- self .assertEqual (result , ["Red" , "Green" , "Blue" ])
1594-
1595- def test_qb_cast_array_03 (self ):
1596- # array[scalar] to array[enum]
1597- from models .orm import default , std
1598-
1599- result = self .client .get (
1600- std .array [default .Color ].cast (
1601- std .array [std .str ](
1602- [std .str ("Red" ), std .str ("Green" ), std .str ("Blue" )]
1603- )
1604- )
1605- )
1606- self .assertEqual (
1607- result ,
1608- [default .Color .Red , default .Color .Green , default .Color .Blue ],
1609- )
1610-
1611- def test_qb_cast_array_04 (self ):
1612- # array[tuple] to array[tuple]
1613- from models .orm import default , std
1614-
1615- result = self .client .get (
1616- std .array [std .tuple [std .int64 , default .Color ]].cast (
1617- std .array [std .tuple [std .str , std .str ]](
1618- [
1619- std .tuple [std .str , std .str ](
1620- [std .str ("1" ), std .str ("Red" )]
1621- ),
1622- std .tuple [std .str , std .str ](
1623- [std .str ("2" ), std .str ("Green" )]
1624- ),
1625- std .tuple [std .str , std .str ](
1626- [std .str ("3" ), std .str ("Blue" )]
1627- ),
1628- ]
1629- )
1630- )
1631- )
1632- self .assertEqual (
1633- result ,
1634- [
1635- (1 , default .Color .Red ),
1636- (2 , default .Color .Green ),
1637- (3 , default .Color .Blue ),
1638- ],
1639- )
1640-
1641- def test_qb_cast_tuple_01 (self ):
1642- # unnamed tuple to unnamed tuple
1643- from models .orm import default , std
1644-
1645- result = self .client .get (
1646- std .tuple [
1647- std .int64 , default .Color , std .str , std .array [std .int64 ]
1648- ].cast (
1649- std .tuple [std .str , std .str , default .Color , std .array [std .str ]](
1650- (
1651- std .str ("1" ),
1652- std .str ("Red" ),
1653- default .Color .Green ,
1654- std .array [std .str ](
1655- [std .str ("2" ), std .str ("3" ), std .str ("4" )]
1656- ),
1657- )
1658- )
1659- )
1660- )
1661- self .assertEqual (result , (1 , default .Color .Red , "Green" , [2 , 3 , 4 ]))
1662-
1663- def test_qb_cast_range_01 (self ):
1664- # range to range
1665- from gel .datatypes import range as _range
1666- from models .orm import std
1667-
1668- result = self .client .get (
1669- std .range [std .int64 ].cast (
1670- std .range [std .int32 ](std .int32 (1 ), std .int32 (9 ))
1671- )
1672- )
1673- self .assertEqual (result , _range .Range (std .int64 (1 ), std .int64 (9 )))
0 commit comments