Feat: add delete_student
This commit is contained in:
parent
066990d109
commit
356db507eb
@ -84,7 +84,6 @@ def update_student(
|
|||||||
tribe_repo: AbstractRepository,
|
tribe_repo: AbstractRepository,
|
||||||
conn,
|
conn,
|
||||||
) -> Student:
|
) -> Student:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_tribe = tribe_repo.get(tribe)
|
_tribe = tribe_repo.get(tribe)
|
||||||
except TribeRepositoryError:
|
except TribeRepositoryError:
|
||||||
@ -103,3 +102,15 @@ def update_student(
|
|||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return student
|
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:
|
try:
|
||||||
self._students.pop(id)
|
self._students.pop(id)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise StudentRepositoryError(f"The student {student} does not exists")
|
raise StudentRepositoryError(f"The student with id {id} does not exists")
|
||||||
|
|
||||||
|
|
||||||
class FakeConn:
|
class FakeConn:
|
||||||
@ -247,7 +247,7 @@ def test_update_student():
|
|||||||
assert len(listed_student) == 2
|
assert len(listed_student) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_update_student_tribe_doesnt_exists():
|
def test_update_student_tribe_doesnt_exist():
|
||||||
tribes = build_tribes(2)
|
tribes = build_tribes(2)
|
||||||
tribe_repo = FakeTribeRepository(tribes)
|
tribe_repo = FakeTribeRepository(tribes)
|
||||||
students = build_student(tribes, 1)
|
students = build_student(tribes, 1)
|
||||||
@ -278,7 +278,7 @@ def test_update_student_tribe_doesnt_exists():
|
|||||||
assert len(listed_student) == 2
|
assert len(listed_student) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_update_student_doesnt_exists():
|
def test_update_student_doesnt_exist():
|
||||||
tribes = build_tribes(2)
|
tribes = build_tribes(2)
|
||||||
tribe_repo = FakeTribeRepository(tribes)
|
tribe_repo = FakeTribeRepository(tribes)
|
||||||
students = build_student(tribes, 1)
|
students = build_student(tribes, 1)
|
||||||
@ -307,3 +307,44 @@ def test_update_student_doesnt_exists():
|
|||||||
|
|
||||||
listed_student = student_repo.list()
|
listed_student = student_repo.list()
|
||||||
assert len(listed_student) == 2
|
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