-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtest_authors.py
More file actions
56 lines (40 loc) · 1.8 KB
/
test_authors.py
File metadata and controls
56 lines (40 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import pytest
import sqlalchemy.ext.asyncio
from authors import query
from dbtest.migrations import apply_migrations, apply_migrations_async
def test_authors(db: sqlalchemy.engine.Connection):
apply_migrations(db, [os.path.dirname(__file__) + "/../authors/schema.sql"])
querier = query.Querier(db)
authors = list(querier.list_authors())
assert authors == []
author_name = "Brian Kernighan"
author_bio = "Co-author of The C Programming Language and The Go Programming Language"
new_author = querier.create_author(name=author_name, bio=author_bio)
assert new_author.id > 0
assert new_author.name == author_name
assert new_author.bio == author_bio
db_author = querier.get_author(id=new_author.id)
assert db_author == new_author
author_list = list(querier.list_authors())
assert len(author_list) == 1
assert author_list[0] == new_author
@pytest.mark.asyncio
async def test_authors_async(async_db: sqlalchemy.ext.asyncio.AsyncConnection):
await apply_migrations_async(async_db, [os.path.dirname(__file__) + "/../authors/schema.sql"])
querier = query.AsyncQuerier(async_db)
async for _ in querier.list_authors():
assert False, "No authors should exist"
author_name = "Brian Kernighan"
author_bio = "Co-author of The C Programming Language and The Go Programming Language"
new_author = await querier.create_author(name=author_name, bio=author_bio)
assert new_author.id > 0
assert new_author.name == author_name
assert new_author.bio == author_bio
db_author = await querier.get_author(id=new_author.id)
assert db_author == new_author
author_list = []
async for author in querier.list_authors():
author_list.append(author)
assert len(author_list) == 1
assert author_list[0] == new_author