mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Increase coverage
This commit is contained in:
parent
9d04d62b1c
commit
27d074d760
9 changed files with 93 additions and 3 deletions
67
tests/test_database/test_crud/test_ufora_announcements.py
Normal file
67
tests/test_database/test_crud/test_ufora_announcements.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import datetime
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from database.crud import ufora_announcements as crud
|
||||
from database.models import UforaAnnouncement, UforaCourse
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def course(database_session: AsyncSession) -> UforaCourse:
|
||||
"""Fixture to create a course"""
|
||||
course = UforaCourse(name="test", code="code", year=1, log_announcements=True)
|
||||
database_session.add(course)
|
||||
await database_session.commit()
|
||||
return course
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def announcement(course: UforaCourse, database_session: AsyncSession) -> UforaAnnouncement:
|
||||
"""Fixture to create an announcement"""
|
||||
announcement = UforaAnnouncement(course_id=course.course_id, publication_date=datetime.datetime.now())
|
||||
database_session.add(announcement)
|
||||
await database_session.commit()
|
||||
return announcement
|
||||
|
||||
|
||||
async def test_get_courses_with_announcements_none(database_session: AsyncSession):
|
||||
"""Test getting all courses with announcements when there are none"""
|
||||
results = await crud.get_courses_with_announcements(database_session)
|
||||
assert len(results) == 0
|
||||
|
||||
|
||||
async def test_get_courses_with_announcements(database_session: AsyncSession):
|
||||
"""Test getting all courses with announcements"""
|
||||
course_1 = UforaCourse(name="test", code="code", year=1, log_announcements=True)
|
||||
course_2 = UforaCourse(name="test2", code="code2", year=1, log_announcements=False)
|
||||
database_session.add_all([course_1, course_2])
|
||||
await database_session.commit()
|
||||
|
||||
results = await crud.get_courses_with_announcements(database_session)
|
||||
assert len(results) == 1
|
||||
assert results[0] == course_1
|
||||
|
||||
|
||||
async def test_create_new_announcement(course: UforaCourse, database_session: AsyncSession):
|
||||
"""Test creating a new announcement"""
|
||||
await crud.create_new_announcement(database_session, 1, course=course, publication_date=datetime.datetime.now())
|
||||
await database_session.refresh(course)
|
||||
assert len(course.announcements) == 1
|
||||
|
||||
|
||||
async def test_remove_old_announcements(announcement: UforaAnnouncement, database_session: AsyncSession):
|
||||
"""Test removing all stale announcements"""
|
||||
course = announcement.course
|
||||
announcement.publication_date -= datetime.timedelta(weeks=2)
|
||||
announcement_2 = UforaAnnouncement(course_id=announcement.course_id, publication_date=datetime.datetime.now())
|
||||
database_session.add_all([announcement, announcement_2])
|
||||
await database_session.commit()
|
||||
await database_session.refresh(course)
|
||||
assert len(course.announcements) == 2
|
||||
|
||||
await crud.remove_old_announcements(database_session)
|
||||
|
||||
await database_session.refresh(course)
|
||||
assert len(course.announcements) == 1
|
||||
assert announcement_2.course.announcements[0] == announcement_2
|
||||
0
tests/test_didier/test_data/__init__.py
Normal file
0
tests/test_didier/test_data/__init__.py
Normal file
0
tests/test_didier/test_data/test_embeds/__init__.py
Normal file
0
tests/test_didier/test_data/test_embeds/__init__.py
Normal file
0
tests/test_didier/test_utils/test_types/__init__.py
Normal file
0
tests/test_didier/test_utils/test_types/__init__.py
Normal file
22
tests/test_didier/test_utils/test_types/test_string.py
Normal file
22
tests/test_didier/test_utils/test_types/test_string.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from didier.utils.types.string import leading
|
||||
|
||||
|
||||
def test_leading():
|
||||
"""Test leading() when it actually does something"""
|
||||
assert leading("0", "5") == "05"
|
||||
assert leading("0", "5", target_length=3) == "005"
|
||||
|
||||
|
||||
def test_leading_not_necessary():
|
||||
"""Test leading() when the input is already long enough"""
|
||||
assert leading("0", "05") == "05"
|
||||
|
||||
|
||||
def test_leading_no_exact():
|
||||
"""Test leading() when adding would bring you over the required length"""
|
||||
assert leading("ab", "c", target_length=6) == "abababc"
|
||||
|
||||
|
||||
def test_leading_no_target_length():
|
||||
"""Test leading() when target_length is None"""
|
||||
assert leading("0", "05", target_length=None) == "005"
|
||||
Loading…
Add table
Add a link
Reference in a new issue