Ejemplo n.º 1
0
    def test_list_all(self):
        services = Services()
        repo = services.repository

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

        services.add(["student", "0", "stud 1"])
        self.assertEqual(repo.get_students_count(), 1)

        self.assertNotIn('|', services.list_all())

        repo.clear()
        self.assertEqual(repo.get_students_count(), 0)
        services.add(["discipline", "1", "discipline 1"])
        self.assertEqual(repo.get_disciplines_count(), 1)

        self.assertNotIn('|', services.list_all())

        services.add(["student", "2", "stud 1"])
        self.assertEqual(repo.get_students_count(), 1)
        services.add(["student", "3", "stud 2"])
        self.assertEqual(repo.get_students_count(), 2)

        self.assertIn('|', services.list_all())
Ejemplo n.º 2
0
class Program:
    def __init__(self):
        self.__ui_manager = MenuUI()
        self.__DEBUGGING_MODE = True
        self.__services = Services()

    def start(self):
        if self.__DEBUGGING_MODE:
            run_tests()

        self.__services.preload_list()
        self.__ui_manager.show_help()

        while True:
            action = self.__ui_manager.get_action()

            try:
                if action.type == constants.ACTION_ADD:
                    result = self.__services.add(action.params)
                    self.__ui_manager.print_result(result)

                elif action.type == constants.ACTION_ERROR:
                    self.__ui_manager.on_invalid_command()

                elif action.type == constants.ACTION_EXIT:
                    return

                elif action.type == constants.ACTION_FILTER_ABOVE:
                    result = self.__services.filter_above(action.params)
                    self.__ui_manager.print_result(result)

                elif action.type == constants.ACTION_HELP:
                    self.__ui_manager.show_help()

                elif action.type == constants.ACTION_LIST_ALL:
                    result = self.__services.list_all()
                    self.__ui_manager.print_result(result)

                elif action.type == constants.ACTION_UNDO:
                    result = self.__services.undo_last_action()
                    self.__ui_manager.print_result(result)
            except ValidationError as error:
                self.__ui_manager.handle_error(error)
Ejemplo n.º 3
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)