|
145 | 145 | {
|
146 | 146 | "data": {
|
147 | 147 | "text/plain": [
|
148 |
| - "datetime.datetime(2024, 7, 17, 14, 0)" |
| 148 | + "datetime.datetime(2024, 7, 18, 14, 0)" |
149 | 149 | ]
|
150 | 150 | },
|
151 | 151 | "execution_count": null,
|
|
595 | 595 | " anno = p.annotation\n",
|
596 | 596 | " # Get the fields and types of type `anno`, if available\n",
|
597 | 597 | " d = _annotations(anno)\n",
|
598 |
| - " cargs = {k:_form_arg(k, v, d) for k,v in form2dict(form).items()}\n", |
| 598 | + " cargs = {k:_form_arg(k, v, d) for k,v in form2dict(form).items() if not d or k in d}\n", |
599 | 599 | " return anno(**cargs)"
|
600 | 600 | ]
|
601 | 601 | },
|
|
1033 | 1033 | {
|
1034 | 1034 | "data": {
|
1035 | 1035 | "text/plain": [
|
1036 |
| - "'2c25d03b-24f2-4946-833a-50ac832a1576'" |
| 1036 | + "'08b63b51-be3a-4f54-8d26-4cd27eb17c0d'" |
1037 | 1037 | ]
|
1038 | 1038 | },
|
1039 | 1039 | "execution_count": null,
|
|
1463 | 1463 | "outputs": [],
|
1464 | 1464 | "source": [
|
1465 | 1465 | "@app.post('/profile/me')\n",
|
1466 |
| - "def profile_update(username: str): return username" |
1467 |
| - ] |
1468 |
| - }, |
1469 |
| - { |
1470 |
| - "cell_type": "code", |
1471 |
| - "execution_count": null, |
1472 |
| - "id": "277b1db0", |
1473 |
| - "metadata": {}, |
1474 |
| - "outputs": [], |
1475 |
| - "source": [ |
1476 |
| - "# Working post request, this is our control\n", |
1477 |
| - "test_r(cli, '/profile/me', 'Alexis', 'post',\n", |
1478 |
| - " data={'username' : 'Alexis'})" |
1479 |
| - ] |
1480 |
| - }, |
1481 |
| - { |
1482 |
| - "cell_type": "code", |
1483 |
| - "execution_count": null, |
1484 |
| - "id": "93d18dfa", |
1485 |
| - "metadata": {}, |
1486 |
| - "outputs": [], |
1487 |
| - "source": [ |
1488 |
| - "# Failing post request due to missing required username parameter\n", |
1489 |
| - "try:\n", |
1490 |
| - " test_r(cli, '/profile/me', 'Alexis', 'post', data={})\n", |
1491 |
| - "except AssertionError as e:\n", |
1492 |
| - " assert \"Missing required field: username\" in str(e)" |
| 1466 | + "def profile_update(username: str): return username\n", |
| 1467 | + "\n", |
| 1468 | + "test_r(cli, '/profile/me', 'Alexis', 'post', data={'username' : 'Alexis'})\n", |
| 1469 | + "test_r(cli, '/profile/me', 'Missing required field: username', 'post', data={})" |
1493 | 1470 | ]
|
1494 | 1471 | },
|
1495 | 1472 | {
|
|
1517 | 1494 | "@dataclass\n",
|
1518 | 1495 | "class Bodie: a:int;b:str\n",
|
1519 | 1496 | "\n",
|
1520 |
| - "@rt(\"/bodie/{nm}/\")\n", |
| 1497 | + "@rt(\"/bodie/{nm}\")\n", |
1521 | 1498 | "async def post(nm:str, data:Bodie):\n",
|
1522 | 1499 | " res = asdict(data)\n",
|
1523 | 1500 | " res['nm'] = nm\n",
|
1524 | 1501 | " return res\n",
|
1525 | 1502 | "\n",
|
1526 | 1503 | "@app.post(\"/bodied/\")\n",
|
1527 |
| - "async def bodied(nm:str, data:dict): return data\n", |
| 1504 | + "async def bodied(data:dict): return data\n", |
1528 | 1505 | "\n",
|
1529 | 1506 | "nt = namedtuple('Bodient', ['a','b'])\n",
|
1530 | 1507 | "\n",
|
|
1549 | 1526 | "execution_count": null,
|
1550 | 1527 | "id": "48f0a45e",
|
1551 | 1528 | "metadata": {},
|
1552 |
| - "outputs": [ |
1553 |
| - { |
1554 |
| - "ename": "AssertionError", |
1555 |
| - "evalue": "==:\nNot Found\n{\"a\":1,\"b\":\"foo\",\"nm\":\"me\"}", |
1556 |
| - "output_type": "error", |
1557 |
| - "traceback": [ |
1558 |
| - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
1559 |
| - "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", |
1560 |
| - "Cell \u001b[0;32mIn[89], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m d \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mdict\u001b[39m(a\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m, b\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfoo\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 3\u001b[0m \u001b[43mtest_r\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcli\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m/bodie/me\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m{\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43ma\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m:1,\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mb\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m:\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfoo\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m,\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mnm\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m:\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mme\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m}\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mpost\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43md\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;66;03m# This test should not be working, as the \"nm\" arguement isn't provided and there isn't a default\u001b[39;00m\n\u001b[1;32m 5\u001b[0m test_r(cli, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/bodied/\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m{\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m:\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m1\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m,\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m:\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfoo\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m}\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpost\u001b[39m\u001b[38;5;124m'\u001b[39m, data\u001b[38;5;241m=\u001b[39md)\n", |
1561 |
| - "Cell \u001b[0;32mIn[66], line 3\u001b[0m, in \u001b[0;36mtest_r\u001b[0;34m(cli, path, exp, meth, hx, **kwargs)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtest_r\u001b[39m(cli, path, exp, meth\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mget\u001b[39m\u001b[38;5;124m'\u001b[39m, hx\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m hx: kwargs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mheaders\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhx-request\u001b[39m\u001b[38;5;124m'\u001b[39m:\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m1\u001b[39m\u001b[38;5;124m\"\u001b[39m}\n\u001b[0;32m----> 3\u001b[0m \u001b[43mtest_eq\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mgetattr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mcli\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmeth\u001b[49m\u001b[43m)\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpath\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtext\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexp\u001b[49m\u001b[43m)\u001b[49m\n", |
1562 |
| - "File \u001b[0;32m~/.virtualenvs/fasthtml/lib/python3.10/site-packages/fastcore-1.5.51-py3.10.egg/fastcore/test.py:37\u001b[0m, in \u001b[0;36mtest_eq\u001b[0;34m(a, b)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtest_eq\u001b[39m(a,b):\n\u001b[1;32m 36\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`test` that `a==b`\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m---> 37\u001b[0m \u001b[43mtest\u001b[49m\u001b[43m(\u001b[49m\u001b[43ma\u001b[49m\u001b[43m,\u001b[49m\u001b[43mb\u001b[49m\u001b[43m,\u001b[49m\u001b[43mequals\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m==\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", |
1563 |
| - "File \u001b[0;32m~/.virtualenvs/fasthtml/lib/python3.10/site-packages/fastcore-1.5.51-py3.10.egg/fastcore/test.py:27\u001b[0m, in \u001b[0;36mtest\u001b[0;34m(a, b, cmp, cname)\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`assert` that `cmp(a,b)`; display inputs and `cname or cmp.__name__` if it fails\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 26\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cname \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m: cname\u001b[38;5;241m=\u001b[39mcmp\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\n\u001b[0;32m---> 27\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m cmp(a,b),\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mcname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00ma\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00mb\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n", |
1564 |
| - "\u001b[0;31mAssertionError\u001b[0m: ==:\nNot Found\n{\"a\":1,\"b\":\"foo\",\"nm\":\"me\"}" |
1565 |
| - ] |
1566 |
| - } |
1567 |
| - ], |
| 1529 | + "outputs": [], |
1568 | 1530 | "source": [
|
1569 | 1531 | "d = dict(a=1, b='foo')\n",
|
1570 | 1532 | "\n",
|
1571 |
| - "test_r(cli, '/bodie/me', '{\"a\":1,\"b\":\"foo\",\"nm\":\"me\"}', 'post', data=d)\n", |
1572 |
| - "# This test should not be working, as the \"nm\" arguement isn't\n", |
1573 |
| - "# provided and there isn't a default\n", |
| 1533 | + "test_r(cli, '/bodie/me', '{\"a\":1,\"b\":\"foo\",\"nm\":\"me\"}', 'post', data=dict(a=1, b='foo', nm='me'))\n", |
1574 | 1534 | "test_r(cli, '/bodied/', '{\"a\":\"1\",\"b\":\"foo\"}', 'post', data=d)\n",
|
1575 | 1535 | "test_r(cli, '/bodie2/', 'a: 1; b: foo', 'post', data={'a':1})\n",
|
1576 | 1536 | "test_r(cli, '/bodient/', '{\"a\":\"1\",\"b\":\"foo\"}', 'post', data=d)\n",
|
|
1607 | 1567 | {
|
1608 | 1568 | "data": {
|
1609 | 1569 | "text/plain": [
|
1610 |
| - "'Cookie was set at time 23:41:43.695239'" |
| 1570 | + "'Cookie was set at time 16:31:31.377931'" |
1611 | 1571 | ]
|
1612 | 1572 | },
|
1613 | 1573 | "execution_count": null,
|
|
1648 | 1608 | "name": "stdout",
|
1649 | 1609 | "output_type": "stream",
|
1650 | 1610 | "text": [
|
1651 |
| - "Set to 2024-07-17 23:41:43.724183\n" |
| 1611 | + "Set to 2024-07-18 16:31:31.423484\n" |
1652 | 1612 | ]
|
1653 | 1613 | },
|
1654 | 1614 | {
|
1655 | 1615 | "data": {
|
1656 | 1616 | "text/plain": [
|
1657 |
| - "'Session time: 23:41:43.724183'" |
| 1617 | + "'Session time: 16:31:31.423484'" |
1658 | 1618 | ]
|
1659 | 1619 | },
|
1660 | 1620 | "execution_count": null,
|
|
1786 | 1746 | "#|hide\n",
|
1787 | 1747 | "import nbdev; nbdev.nbdev_export()"
|
1788 | 1748 | ]
|
| 1749 | + }, |
| 1750 | + { |
| 1751 | + "cell_type": "code", |
| 1752 | + "execution_count": null, |
| 1753 | + "id": "5d9d25c7", |
| 1754 | + "metadata": {}, |
| 1755 | + "outputs": [], |
| 1756 | + "source": [] |
1789 | 1757 | }
|
1790 | 1758 | ],
|
1791 | 1759 | "metadata": {
|
|
0 commit comments