switch to pipfile, new tests

This commit is contained in:
Xevion
2021-02-12 23:19:35 -06:00
parent 89b16fdc04
commit ea825b9a30
5 changed files with 92 additions and 5 deletions

15
Pipfile Normal file
View File

@@ -0,0 +1,15 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
discord = "~=1.0.1"
aiosqlite = "~=0.16.1"
pytest = "*"
pytest-asyncio = "*"
[requires]
python_version = "3.7"

View File

@@ -66,7 +66,7 @@ class ContestCog(commands.Cog):
await self.bot.db.new_period(new_period)
# Handle submissions state
elif period.current_state == 0:
await self.bot.db.update_period(period)
await self.bot.db.update(period)
return
# Handle voting state
elif period.current_state == 1:

View File

@@ -14,7 +14,8 @@ logger.setLevel(constants.LOGGING_LEVEL)
Guild = namedtuple('Guild', ['id', 'prefix', 'submission', 'period'])
Submission = namedtuple('Submission', ['id', 'user', 'guild', 'timestamp'])
Period = namedtuple('Period', ['id', 'guild', 'current_state', 'started_at', 'voting_at', 'finished_at', ''])
Period = namedtuple('Period', ['id', 'guild', 'current_state', 'started_at', 'voting_at', 'finished_at'])
tables = [Guild, Submission, Period]
class ContestDatabase(object):

View File

@@ -1,3 +0,0 @@
discord~=1.0.1
aiosqlite~=0.16.1

74
tests/bot/test_db.py Normal file
View File

@@ -0,0 +1,74 @@
import pytest
from bot.db import ContestDatabase, tables
@pytest.fixture()
async def db() -> ContestDatabase:
db = await ContestDatabase.create(':memory:')
yield db
await db.conn.close()
@pytest.mark.asyncio
async def test_table_setup(db) -> None:
"""Test that all tables were setup by the database."""
cur = await db.conn.cursor()
try:
for table_namedtuple in tables:
await cur.execute('''SELECT name FROM sqlite_master WHERE type='table' AND name = ?;''',
[table_namedtuple.__name__.lower()])
rows = list(await cur.fetchall())
assert len(rows) == 1
finally:
await cur.close()
@pytest.mark.asyncio
async def test_guild_setup(db) -> None:
await db.setup_guild(0)
guild = await db.get_guild(0)
assert guild is not None
assert guild.submission is None
assert await db.get_guild(1) is None
@pytest.mark.asyncio
async def test_update(db) -> None:
pass
@pytest.mark.asyncio
async def test_generate_update_query(db) -> None:
pass
@pytest.mark.asyncio
async def test_insert(db) -> None:
"""Test automatic namedtuple query"""
pass
@pytest.mark.asyncio
async def test_generate_insert_query(db) -> None:
"""Test INSERT query generation."""
pass
@pytest.mark.asyncio
async def test_submissions(db) -> None:
"""Test all submission related helper functions."""
pass
@pytest.mark.asyncio
async def test_guilds(db) -> None:
"""Test all guild related helper functions"""
pass
@pytest.mark.asyncio
async def test_periods(db) -> None:
"""Test all period related helper functions."""
pass