import unittest
from datetime import date
from src.services.services import Services
from src.repository.students_repo import StudentsRepo
from src.repository.assignments_repo import AssignmentsRepo
from src.repository.grades_repo import GradesRepo



class Tester(unittest.TestCase):
    def __init__(self, methodName: str = ...) -> None:
        super().__init__(methodName)
        
    def setUp(self) -> None:
        self.service = Services(StudentsRepo("tests/test_students_file.json"), AssignmentsRepo("tests/test_assignments_file.json"), GradesRepo("tests/test_grades_file.json"))
    
    def tearDown(self) -> None:
        return super().tearDown()
    
    def test_student_repo(self):
        self.service.add_student("1","John", "911")
        self.assertEqual(self.service.list_students()[0].get_name(), "John")
        self.assertEqual(self.service.list_students()[0].get_student_id(), "1")
        self.assertEqual(self.service.list_students()[0].get_group(), "911")
        self.service.update_student("1", "Jack", "912")
        self.assertEqual(self.service.list_students()[0].get_name(), "Jack")
        self.assertEqual(self.service.list_students()[0].get_student_id(), "1")
        self.assertEqual(self.service.list_students()[0].get_group(), "912")
        self.service.remove_student("1")
        self.assertEqual(len(self.service.list_students()), 0)

    def test_assignment_repo(self):
        self.service.add_assignment("1", "Assignment 1", date(2021, 2, 1))
        self.assertEqual(self.service.list_assignments()[0].get_assignment_id(), "1")
        self.assertEqual(self.service.list_assignments()[0].get_description(), "Assignment 1")
        self.assertEqual(self.service.list_assignments()[0].get_deadline(), date(2021, 2, 1))
        self.service.update_assignment("1", "Assignment 2", date(2021, 2, 2))
        self.assertEqual(self.service.list_assignments()[0].get_assignment_id(), "1")
        self.assertEqual(self.service.list_assignments()[0].get_description(), "Assignment 2")
        self.assertEqual(self.service.list_assignments()[0].get_deadline(), date(2021, 2, 2))
        self.service.remove_assignment("1")
        self.assertEqual(len(self.service.list_assignments()), 0)
   

if __name__ == '__main__':
    unittest.main()

#python -m unittest discover -v -s tests -p "*test*.py"