Feat: add delete_student
This commit is contained in:
parent
066990d109
commit
356db507eb
@ -84,7 +84,6 @@ def update_student(
|
||||
tribe_repo: AbstractRepository,
|
||||
conn,
|
||||
) -> Student:
|
||||
|
||||
try:
|
||||
_tribe = tribe_repo.get(tribe)
|
||||
except TribeRepositoryError:
|
||||
@ -103,3 +102,15 @@ def update_student(
|
||||
|
||||
conn.commit()
|
||||
return student
|
||||
|
||||
|
||||
def delete_student(
|
||||
id: str,
|
||||
student_repo: AbstractRepository,
|
||||
conn,
|
||||
) -> Student:
|
||||
try:
|
||||
student_repo.delete(id=id)
|
||||
except StudentRepositoryError:
|
||||
raise StudentDoesExist("The student with id {id} does not exists")
|
||||
conn.commit()
|
||||
|
@ -77,7 +77,7 @@ class FakeStudentRepository(AbstractRepository):
|
||||
try:
|
||||
self._students.pop(id)
|
||||
except KeyError:
|
||||
raise StudentRepositoryError(f"The student {student} does not exists")
|
||||
raise StudentRepositoryError(f"The student with id {id} does not exists")
|
||||
|
||||
|
||||
class FakeConn:
|
||||
@ -247,7 +247,7 @@ def test_update_student():
|
||||
assert len(listed_student) == 2
|
||||
|
||||
|
||||
def test_update_student_tribe_doesnt_exists():
|
||||
def test_update_student_tribe_doesnt_exist():
|
||||
tribes = build_tribes(2)
|
||||
tribe_repo = FakeTribeRepository(tribes)
|
||||
students = build_student(tribes, 1)
|
||||
@ -278,7 +278,7 @@ def test_update_student_tribe_doesnt_exists():
|
||||
assert len(listed_student) == 2
|
||||
|
||||
|
||||
def test_update_student_doesnt_exists():
|
||||
def test_update_student_doesnt_exist():
|
||||
tribes = build_tribes(2)
|
||||
tribe_repo = FakeTribeRepository(tribes)
|
||||
students = build_student(tribes, 1)
|
||||
@ -307,3 +307,44 @@ def test_update_student_doesnt_exists():
|
||||
|
||||
listed_student = student_repo.list()
|
||||
assert len(listed_student) == 2
|
||||
|
||||
|
||||
def test_delete_student():
|
||||
tribes = build_tribes(2)
|
||||
tribe_repo = FakeTribeRepository(tribes)
|
||||
students = build_student(tribes, 1)
|
||||
student_repo = FakeStudentRepository(students)
|
||||
conn = FakeConn()
|
||||
|
||||
student = students.pop()
|
||||
|
||||
services.delete_student(
|
||||
id=student.id,
|
||||
student_repo=student_repo,
|
||||
conn=conn,
|
||||
)
|
||||
|
||||
assert conn.committed is True
|
||||
|
||||
listed_student = student_repo.list()
|
||||
assert listed_student == students
|
||||
|
||||
|
||||
def test_delete_student_doesnt_exist():
|
||||
tribes = build_tribes(2)
|
||||
tribe_repo = FakeTribeRepository(tribes)
|
||||
students = build_student(tribes, 1)
|
||||
student_repo = FakeStudentRepository(students)
|
||||
conn = FakeConn()
|
||||
|
||||
with pytest.raises(StudentDoesExist):
|
||||
services.delete_student(
|
||||
id="not existing id",
|
||||
student_repo=student_repo,
|
||||
conn=conn,
|
||||
)
|
||||
|
||||
assert conn.committed is False
|
||||
|
||||
listed_student = student_repo.list()
|
||||
assert set(listed_student) == set(students)
|
||||
|
Loading…
Reference in New Issue
Block a user