File tree Expand file tree Collapse file tree 5 files changed +67
-1
lines changed
Expand file tree Collapse file tree 5 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 1+ * .pyc
2+ .pytest_cache /
Original file line number Diff line number Diff line change 1+ {
2+ "python.pythonPath" : " /Users/dantownsend/.virtualenvs/aragorm/bin/python"
3+ }
Original file line number Diff line number Diff line change @@ -22,7 +22,11 @@ class Value(object):
2222
2323class 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 ):
Original file line number Diff line number Diff line change 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 ())
Original file line number Diff line number Diff line change 1+ # asyncpg==0.17.0
2+ # pytest==3.7.2
3+ # uvloop==0.11.2
You can’t perform that action at this time.
0 commit comments