Skip to content

Commit db8d5bd

Browse files
committed
fleshing out tests
1 parent 7a705af commit db8d5bd

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pyc
2+
.pytest_cache/

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.pythonPath": "/Users/dantownsend/.virtualenvs/aragorm/bin/python"
3+
}

aragorm/model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ class Value(object):
2222

2323
class Where(object):
2424
"""
25-
Example use case -
25+
Example use case - id = 5
26+
27+
Can potentially simplify things dramatically here by just accepting
28+
postgres where clauses directly, avoiding the need for equal, greater than
29+
etc syntax.
2630
"""
2731

2832
def __init__(self, field: str, value: Value):

aragorm/tests/test_model.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Need a test runner ...
2+
import asyncio
3+
from unittest import TestCase
4+
5+
import asyncpg
6+
7+
8+
TEST_CREDENTIALS = {
9+
'host': 'localhost',
10+
'database': 'aragorm',
11+
'user': 'aragorm',
12+
'password': 'aragorm'
13+
}
14+
15+
16+
class TestQuery(TestCase):
17+
18+
async def create_table(self):
19+
conn = await asyncpg.connect(**TEST_CREDENTIALS)
20+
await conn.execute('''
21+
CREATE TABLE pokemon (
22+
name VARCHAR(50),
23+
power SMALLINT
24+
);'''
25+
)
26+
await conn.close()
27+
28+
async def insert_rows(self):
29+
conn = await asyncpg.connect(**TEST_CREDENTIALS)
30+
await conn.execute('''
31+
INSERT INTO pokemon (
32+
name,
33+
power
34+
) VALUES (
35+
'pikachu',
36+
1000
37+
);'''
38+
)
39+
40+
async def drop_table(self):
41+
conn = await asyncpg.connect(**TEST_CREDENTIALS)
42+
await conn.execute('DROP TABLE pokemon;')
43+
await conn.close()
44+
45+
def setUp(self):
46+
asyncio.run(self.create_table())
47+
48+
def test_query(self):
49+
print('hello there ...')
50+
asyncio.run(self.insert_rows())
51+
breakpoint()
52+
53+
def tearDown(self):
54+
asyncio.run(self.drop_table())

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# asyncpg==0.17.0
2+
# pytest==3.7.2
3+
# uvloop==0.11.2

0 commit comments

Comments
 (0)