@@ -66,6 +66,47 @@ def test_table(mock_engine: AsyncEngine) -> None:
6666 }
6767
6868
69+ async def test_binary (
70+ base : DeclarativeBase , aiohttp_client : Callable [[web .Application ], Awaitable [TestClient ]],
71+ login : _Login
72+ ) -> None :
73+ class TestModel (base ): # type: ignore[misc,valid-type]
74+ __tablename__ = "test"
75+ id : Mapped [int ] = mapped_column (primary_key = True )
76+ binary : Mapped [bytes ]
77+
78+ app = web .Application ()
79+ engine = create_async_engine ("sqlite+aiosqlite:///:memory:" )
80+ db = async_sessionmaker (engine , expire_on_commit = False )
81+ async with engine .begin () as conn :
82+ await conn .run_sync (base .metadata .create_all )
83+ async with db .begin () as sess :
84+ sess .add (TestModel (binary = b"foo" ))
85+ sess .add (TestModel (binary = b"\x01 \xFF \x02 " ))
86+
87+ schema : aiohttp_admin .Schema = {
88+ "security" : {
89+ "check_credentials" : check_credentials ,
90+ "secure" : False
91+ },
92+ "resources" : ({"model" : SAResource (engine , TestModel )},)
93+ }
94+ app ["admin" ] = aiohttp_admin .setup (app , schema )
95+
96+ admin_client = await aiohttp_client (app )
97+ assert admin_client .app
98+ h = await login (admin_client )
99+
100+ url = app ["admin" ].router ["test_get_one" ].url_for ()
101+ async with admin_client .get (url , params = {"id" : 1 }, headers = h ) as resp :
102+ assert resp .status == 200
103+ assert await resp .json () == {"data" : {"id" : 1 , "binary" : "foo" }}
104+
105+ async with admin_client .get (url , params = {"id" : 2 }, headers = h ) as resp :
106+ assert resp .status == 200
107+ assert await resp .json () == {"data" : {"id" : 2 , "binary" : "\x01 �\x02 " }}
108+
109+
69110def test_fk (base : type [DeclarativeBase ], mock_engine : AsyncEngine ) -> None :
70111 class TestModel (base ): # type: ignore[misc,valid-type]
71112 __tablename__ = "dummy"
0 commit comments