Example #1
0
    def test_disciplines_with_grades(self):
        services = Services()
        repo = services.repository

        services = Services()
        repo = services.repository

        services.add(["student", "1", "stud 1"])
        services.add(["student", "2", "stud 2"])
        services.add(["student", "3", "stud 3"])
        services.add(["discipline", "1", "discipline 1"])
        services.add(["discipline", "2", "discipline 2"])

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 2)

        self.assertRaises(Exception, lambda: services.see_grades())

        services.grade(["1", "1", "10"])
        services.grade(["2", "1", "10"])
        services.grade(["2", "1", "1"])
        services.grade(["2", "1", "4"])
        services.grade(["2", "2", "5"])
        services.grade(["3", "1", "1"])
        services.grade(["3", "1", "2"])
        services.grade(["3", "1", "3"])
        services.grade(["3", "1", "4"])
        services.grade(["3", "2", "5"])
        self.assertEqual(repo.get_grades_count(), 10)

        self.assertIn("\n", services.see_grades())
Example #2
0
    def test_remove_student(self):
        services = Services()
        repo = services.repository

        services.add(["discipline", "0", "discipline test"])
        services.add(["student", "1", "student 1 test"])
        services.add(["student", "2", "student 2 test"])
        services.grade(["1", "0", "10"])
        services.grade(["1", "0", "6"])
        services.grade(["2", "0", "9"])
        services.grade(["2", "0", "7"])
        services.grade(["2", "0", "8"])

        self.assertEqual(repo.get_students_count(), 2)
        self.assertEqual(repo.get_disciplines_count(), 1)
        self.assertEqual(repo.get_grades_count(), 5)

        self.assertRaises(Exception, lambda: services.remove([]))
        self.assertRaises(Exception, lambda: services.remove(["", ""]))
        self.assertRaises(Exception, lambda: services.remove(["abc", "abc"]))
        self.assertRaises(Exception,
                          lambda: services.remove(["student", "abc"]))
        self.assertRaises(Exception, lambda: services.remove(["student", "0"]))
        services.remove(["student", "2"])

        self.assertEqual(repo.get_students_count(), 1)
        self.assertEqual(repo.get_disciplines_count(), 1)
        self.assertEqual(repo.get_grades_count(), 2)
        self.assertRaises(Exception, lambda: services.remove(["student", "2"]))
Example #3
0
    def test_redo(self):
        services = Services()
        repo = services.repository

        self.assertRaises(Exception, lambda: services.redo())

        services.add(["student", "1", "stud 1"])
        services.add(["student", "2", "stud 2"])
        services.add(["student", "3", "stud 3"])
        services.add(["discipline", "1", "discipline 1"])
        services.add(["discipline", "2", "discipline 2"])

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 2)
        self.assertEqual(repo.get_grades_count(), 0)

        self.assertRaises(Exception, lambda: services.redo())

        services.undo()
        services.undo()

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 0)
        self.assertEqual(repo.get_grades_count(), 0)

        services.redo()
        services.redo()

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 2)
        self.assertEqual(repo.get_grades_count(), 0)

        services.grade(["1", "1", "10"])
        services.grade(["2", "1", "10"])
        services.grade(["2", "1", "1"])
        services.grade(["2", "1", "4"])
        services.grade(["2", "2", "5"])
        services.grade(["3", "1", "1"])
        services.grade(["3", "1", "2"])
        services.grade(["3", "1", "3"])
        services.grade(["3", "2", "4"])
        services.grade(["3", "2", "5"])

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 2)
        self.assertEqual(repo.get_grades_count(), 10)

        services.remove(["discipline", "2"])

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 1)
        self.assertEqual(repo.get_grades_count(), 7)

        services.undo()

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 2)
        self.assertEqual(repo.get_grades_count(), 10)

        services.redo()

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 1)
        self.assertEqual(repo.get_grades_count(), 7)

        services.remove(["student", "3"])

        self.assertEqual(repo.get_students_count(), 2)
        self.assertEqual(repo.get_disciplines_count(), 1)
        self.assertEqual(repo.get_grades_count(), 4)

        for _ in range(13):
            services.undo()

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 1)
        self.assertEqual(repo.get_grades_count(), 0)

        services.redo()
        services.redo()

        self.assertEqual(repo.get_students_count(), 3)
        self.assertEqual(repo.get_disciplines_count(), 2)
        self.assertEqual(repo.get_grades_count(), 1)

        services.update(["discipline", "1", "test"])
        self.assertEqual(repo.get_disciplines_count(), 2)

        services.undo()
        self.assertEqual(repo.get_disciplines_count(), 2)

        discipline = repo.get_discipline(1)
        self.assertEqual(discipline.name, "discipline 1")

        services.redo()
        self.assertEqual(repo.get_disciplines_count(), 2)

        discipline = repo.get_discipline(1)
        self.assertEqual(discipline.name, "test")

        for _ in range(7):
            services.undo()

        self.assertTrue(repo.is_empty())

        services.preload_list()
        self.assertFalse(repo.is_empty())

        services.undo()
        self.assertTrue(repo.is_empty())

        services.redo()
        self.assertFalse(repo.is_empty())

        self.assertRaises(Exception, lambda: services.redo())
Example #4
0
    def test_grade(self):
        services = Services()
        repo = services.repository

        services.add(["student", "1", "stud 1"])
        services.add(["discipline", "1", "discipline 1"])

        self.assertEqual(repo.get_students_count(), 1)
        self.assertEqual(repo.get_disciplines_count(), 1)

        self.assertRaises(Exception, lambda: services.grade([]))
        self.assertRaises(Exception, lambda: services.grade(["", "", ""]))
        self.assertRaises(Exception,
                          lambda: services.grade(["abc", "abc", "abc"]))
        self.assertRaises(Exception,
                          lambda: services.grade(["0", "abc", "abc"]))
        self.assertRaises(Exception,
                          lambda: services.grade(["1", "abc", "abc"]))
        self.assertRaises(Exception, lambda: services.grade(["1", "0", "abc"]))
        self.assertRaises(Exception, lambda: services.grade(["1", "1", "abc"]))
        self.assertRaises(Exception, lambda: services.grade(["1", "1", "0"]))
        self.assertRaises(Exception, lambda: services.grade(["1", "1", "11"]))

        services.grade(["1", "1", "1"])
        services.grade(["1", "1", "10"])
        services.grade(["1", "1", "5"])

        self.assertEqual(repo.get_grades_count(), 3)
Example #5
0
class Program:

    def __init__(self):
        self.__services = Services()
        self.__ui_manager = MenuUI()

    def change_ui(self):
         if self.__ui_manager.switch_ui_prefernece():
            if self.__ui_manager.TYPE == MenuUI.TYPE:
                self.__ui_manager = GraphicalUI()
            else:
                self.__ui_manager = MenuUI()

    def start(self):
        self.__services.preload_list()
        self.change_ui()

        while True:
            result = ""

            try:
                action = self.__ui_manager.get_action()

                if action.type == Action.ADD:
                    self.__services.add(action.params)

                elif action.type == Action.REMOVE:
                    self.__services.remove(action.params)

                elif action.type == Action.UPDATE:
                    self.__services.update(action.params)

                elif action.type == Action.LIST:
                    result = self.__services.list_all()

                elif action.type == Action.GRADE:
                    self.__services.grade(action.params)

                elif action.type == Action.SEARCH:
                    result = self.__services.search(action.params)

                elif action.type == Action.SEE_FAILING_STUDENTS:
                    result = self.__services.see_failing_students()

                elif action.type == Action.SEE_BEST_STUDENTS:
                    result = self.__services.see_best_students()

                elif action.type == Action.SEE_GRADES:
                    result = self.__services.see_grades()

                elif action.type == Action.UNDO:
                    self.__services.undo()

                elif action.type == Action.REDO:
                    self.__services.redo()

                elif action.type == Action.HELP:
                    self.__ui_manager.show_help()
                    continue

                elif action.type == Action.UI:
                    self.change_ui()
                    continue

                elif action.type == Action.TEST:
                    unittest.main(module = "services_test", exit = False) 
                    continue

                elif action.type == Action.EXIT:
                    return
                
                self.__ui_manager.print_result(result)
            except Exception as error:
                self.__ui_manager.handle_error(error)