database_url = 'sqlite:///test.db'
@pytest.mark.parametrize("database_url", DATABASE_URLS)
@async_adapter
async def test_datetime_field(database_url):
"""
Test DataTime columns, to ensure records are coerced to/from proper Python types.
"""
async with Database(database_url) as database:
async with database.transaction(force_rollback=True):
now = datetime.datetime.now().replace(microsecond=0)
# execute()
query = articles.insert()
values = {"title": "Hello, world", "published": now}
await database.execute(query, values)
# fetch_all()
query = articles.select()
results = await database.fetch_all(query=query)
assert len(results) == 1
> assert results[0]["title"] == "Hello, world"
E AssertionError: assert '2019-02-19 11:29:46.000000' == 'Hello, world'
E - 2019-02-19 11:29:46.000000
E + Hello, world
tests/test_databases.py:308: AssertionError
____________________________________________________________________________ test_custom_field[sqlite:///test.db] ____________________________________________________________________________
database_url = 'sqlite:///test.db'
@pytest.mark.parametrize("database_url", DATABASE_URLS)
@async_adapter
async def test_custom_field(database_url):
"""
Test custom column types.
"""
async with Database(database_url) as database:
async with database.transaction(force_rollback=True):
today = datetime.date.today()
# execute()
query = custom_date.insert()
values = {"title": "Hello, world", "published": today}
await database.execute(query, values)
# fetch_all()
query = custom_date.select()
results = await database.fetch_all(query=query)
assert len(results) == 1
> assert results[0]["title"] == "Hello, world"
E AssertionError: assert '17946' == 'Hello, world'
E - 17946
E + Hello, world
tests/test_databases.py:353: AssertionError