コード例 #1
0
 def test_with_not_block_jump(self):
     mock_warning = mocks.MockWarning()
     mocks.MockWarning.retrieve_value = mock_warning
     self.configuration.block = models_tests.generate_block(sessions=self.list_sessions)
     self.configuration.session = self.list_sessions[1]
     main.update_config(self.configuration, [], [])
     self.assertEqual(self.configuration.session, self.list_sessions[0])
     self.assertEqual(len(self.configuration.warnings), 1)
     self.assertEqual(self.configuration.warnings[0], mock_warning)
コード例 #2
0
    def setUp(self):
        def generate_sessions():
            list_mock_sessions = []
            for level in range(1, 5):
                list_mock_sessions.extend([
                    models_tests.generate_block_session(level * 5, level=level, session=models.ModelSession(),
                                                        order=10),
                    models_tests.generate_block_session(level * 5 + 1, level=level, session=models.ModelSession(),
                                                        order=20),
                    models_tests.generate_block_session(level * 5 + 2, level=level, session=models.ModelSession(),
                                                        order=30),
                ])
            return list_mock_sessions

        self.configuration = models.OlderConfig()
        self.b1 = models_tests.generate_block(order=10, sessions=generate_sessions())
        self.b2 = models_tests.generate_block(order=20, sessions=generate_sessions())
        self.b3 = models_tests.generate_block(order=30, sessions=generate_sessions())
        self.configuration.pattern = models_tests.generate_pattern(blocks=[self.b1, self.b3, self.b2])
コード例 #3
0
    def setUp(self):
        self.pauta = main.pauta
        self.update_config = main.update_config
        self.session = models.Session
        self.pattern_history = models.PatternHistory
        self.get_counters = main.get_counters
        self.configuration_save = models.OlderConfig.save
        self.check_warnings = main.check_warnings
        self.last_check_warnings_sessions = None
        self.last_check_warnings_all_sessions = None
        self.count = {
            "pauta": 0,
            "update_config": 0,
            "get_counters": 0,
        }
        self.list_sessions = []
        self.get_counters_value = (0, 0, 0)

        def mock_pauta(configuration):
            self.count["pauta"] += 1
            return mocks.MockSession()

        def mock_update_config(configuration, sessions_made, sessions_use_data):
            self.count["update_config"] += 1

        def mock_get_counters(sessions, list_sessions, monday):
            self.count["get_counters"] += 1
            return self.get_counters_value

        def mock_check_warnings(configuration, all_sessions, sessions):
            self.last_check_warnings_sessions = sessions
            self.last_check_warnings_all_sessions = all_sessions

        models.Session = mocks.MockSession
        models.PatternHistory = mocks.MockPatternHistory
        main.pauta = mock_pauta
        main.update_config = mock_update_config
        main.get_counters = mock_get_counters
        main.check_warnings = mock_check_warnings

        self.configuration = mocks.MockOlderConfig()
        self.configuration.block = models_tests.generate_block(sessions=[])
        self.configuration.older = models.Older()
        self.configuration.older.id = 1
        self.configuration.level = "1"
        self.configuration.numberSessions = 2
        self.configuration.maxSessionsWeek = 5
コード例 #4
0
 def test_history(self):
     self.get_counters_value = (0, 0, 0)
     mocks.MockPatternHistory.list_mocks = []
     self.configuration.pattern = models_tests.generate_pattern()
     self.configuration.block = models_tests.generate_block()
     self.configuration.level = 2
     self.configuration.older = models.Older()
     self.configuration.warnings = [mocks.MockWarning(), mocks.MockWarning()]
     main.run(self.configuration, "monday")
     self.assertEqual(len(mocks.MockPatternHistory.list_mocks), 1)
     historic = mocks.MockPatternHistory.list_mocks[0]
     self.assertEqual(self.configuration.pattern, historic.pattern)
     self.assertEqual(self.configuration.block, historic.block)
     self.assertEqual(self.configuration.level, historic.level)
     self.assertEqual(self.configuration.older, historic.older)
     self.assertEqual(self.configuration.warnings, historic.warnings)
     self.assertEqual(len(historic.sessions), 2)
コード例 #5
0
    def setUp(self):
        self.last_jump_configuration = None
        self.last_jump_condition = None

        self.mock_avg_percentile = None
        self.mock_avg_motivation = None

        def mock_jump(configuration, condition):
            self.last_jump_configuration = configuration
            self.last_jump_condition = condition

        def mock_get_average_data(older, s1, s2):
            return self.mock_avg_percentile, self.mock_avg_motivation

        self.get_average_data = main.get_average_data
        main.get_average_data = mock_get_average_data
        self.jump = main.jump
        main.jump = mock_jump
        self.warnings = models.Warnings
        models.Warnings = mocks.MockWarning

        self.bjc = models_tests.generate_block_jump_condition(level="1")
        bjc2 = models_tests.generate_block_jump_condition(level="1")
        self.bjd = models_tests.generate_block_jump_default(level="2")
        bj = models_tests.generate_block_jump(conditions=[self.bjc, bjc2], defaults=[self.bjd])
        self.configuration = models.OlderConfig()
        self.configuration.warnings = []
        self.configuration.level = "1"
        self.list_sessions = [
            models_tests.generate_block_session(order=10, level="1"),
            models_tests.generate_block_session(order=20, level="1"),
            models_tests.generate_block_session(order=15, level="1"),
            models_tests.generate_block_session(order=10, level="2"),
            models_tests.generate_block_session(order=20, level="3"),
            models_tests.generate_block_session(order=10, level="3")

        ]
        self.block = models_tests.generate_block(block_jump=bj, sessions=self.list_sessions)
        self.configuration.block = self.block