Skip to content

Commit bac0183

Browse files
committed
breaking down table tests
1 parent da5d9f0 commit bac0183

File tree

7 files changed

+107
-88
lines changed

7 files changed

+107
-88
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.pyc
22
.pytest_cache/
3+
.mypy_cache/

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"python.pythonPath": "/Users/dantownsend/.virtualenvs/aragorm/bin/python"
2+
"python.pythonPath": "/Users/dantownsend/.virtualenvs/aragorm/bin/python",
3+
"python.linting.pylintEnabled": false,
4+
"python.linting.flake8Enabled": false,
5+
"python.linting.enabled": true,
6+
"python.linting.mypyEnabled": true
37
}

tests/table/test_create.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import asyncio
2+
3+
from ..base import DBTestCase
4+
from ..example_project.tables import Pokemon
5+
6+
7+
class TestCreate(DBTestCase):
8+
9+
def setUp(self):
10+
"""
11+
Need to override, otherwise table will be auto created.
12+
"""
13+
pass
14+
15+
def test_create_table(self):
16+
async def create_table():
17+
return await Pokemon.create().execute()
18+
19+
async def count_rows():
20+
return await Pokemon.select(
21+
'name', 'trainer', 'power'
22+
).count().execute()
23+
24+
asyncio.run(create_table())
25+
26+
# Just do a count to make sure the table was created ok.
27+
response = asyncio.run(count_rows())
28+
self.assertEqual(response[0]['count'], 0)

tests/table/test_delete.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import asyncio
2+
3+
from ..base import DBTestCase
4+
from ..example_project.tables import Pokemon
5+
6+
7+
class TestDelete(DBTestCase):
8+
9+
def test_delete(self):
10+
self.insert_rows()
11+
12+
async def delete_pokemon():
13+
return await Pokemon.delete().where(
14+
Pokemon.name == 'weedle'
15+
).execute()
16+
17+
async def check_pokemon():
18+
return await Pokemon.select().where(
19+
Pokemon.name == 'weedle'
20+
).count().execute()
21+
22+
asyncio.run(delete_pokemon())
23+
response = asyncio.run(check_pokemon())
24+
print(f'response = {response}')
25+
26+
self.assertEqual(
27+
response,
28+
[{'count': 0}]
29+
)

tests/table/test_metaclass.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from unittest import TestCase
2+
3+
from ..example_project.tables import Pokemon
4+
5+
6+
class TestMetaClass(TestCase):
7+
8+
def test_tablename(self):
9+
self.assertEqual(Pokemon.Meta.tablename, 'pokemon')

tests/table/test_select.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import asyncio
2-
from unittest import TestCase
3-
4-
import asyncpg
52

63
from ..base import DBTestCase
74
from ..example_project.tables import Pokemon
@@ -282,87 +279,3 @@ async def get_pokemon():
282279
response,
283280
[{'count': 1}]
284281
)
285-
286-
287-
class TestUpdate(DBTestCase):
288-
289-
def test_update(self):
290-
self.insert_rows()
291-
292-
async def update_pokemon():
293-
return await Pokemon.update(
294-
name='kakuna'
295-
).where(
296-
Pokemon.name == 'weedle'
297-
).execute()
298-
299-
async def check_pokemon():
300-
return await Pokemon.select(
301-
'name'
302-
).where(
303-
Pokemon.name == 'kakuna'
304-
).execute()
305-
306-
asyncio.run(update_pokemon())
307-
response = asyncio.run(check_pokemon())
308-
print(f'response = {response}')
309-
310-
self.assertEqual(
311-
response,
312-
[{'name': 'kakuna'}]
313-
)
314-
315-
316-
class TestDelete(DBTestCase):
317-
318-
def test_delete(self):
319-
self.insert_rows()
320-
321-
async def delete_pokemon():
322-
return await Pokemon.delete().where(
323-
Pokemon.name == 'weedle'
324-
).execute()
325-
326-
async def check_pokemon():
327-
return await Pokemon.select().where(
328-
Pokemon.name == 'weedle'
329-
).count().execute()
330-
331-
asyncio.run(delete_pokemon())
332-
response = asyncio.run(check_pokemon())
333-
print(f'response = {response}')
334-
335-
self.assertEqual(
336-
response,
337-
[{'count': 0}]
338-
)
339-
340-
341-
class TestCreate(DBTestCase):
342-
343-
def setUp(self):
344-
"""
345-
Need to override, otherwise table will be auto created.
346-
"""
347-
pass
348-
349-
def test_create_table(self):
350-
async def create_table():
351-
return await Pokemon.create().execute()
352-
353-
async def count_rows():
354-
return await Pokemon.select(
355-
'name', 'trainer', 'power'
356-
).count().execute()
357-
358-
asyncio.run(create_table())
359-
360-
# Just do a count to make sure the table was created ok.
361-
response = asyncio.run(count_rows())
362-
self.assertEqual(response[0]['count'], 0)
363-
364-
365-
class TestMetaClass(TestCase):
366-
367-
def test_tablename(self):
368-
self.assertEqual(Pokemon.Meta.tablename, 'pokemon')

tests/table/test_update.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import asyncio
2+
3+
import asyncpg
4+
5+
from ..base import DBTestCase
6+
from ..example_project.tables import Pokemon
7+
8+
9+
class TestUpdate(DBTestCase):
10+
11+
def test_update(self):
12+
self.insert_rows()
13+
14+
async def update_pokemon():
15+
return await Pokemon.update(
16+
name='kakuna'
17+
).where(
18+
Pokemon.name == 'weedle'
19+
).execute()
20+
21+
async def check_pokemon():
22+
return await Pokemon.select(
23+
'name'
24+
).where(
25+
Pokemon.name == 'kakuna'
26+
).execute()
27+
28+
asyncio.run(update_pokemon())
29+
response = asyncio.run(check_pokemon())
30+
print(f'response = {response}')
31+
32+
self.assertEqual(
33+
response,
34+
[{'name': 'kakuna'}]
35+
)

0 commit comments

Comments
 (0)