Esempio n. 1
0
    def test_right_values(self):
        self.filler.db_define_ref = Mock(side_effect=[1, 2, 3, 4, 5, 6, 7, 8])
        self.filler.db_update = Mock()
        submit = Mock()
        submit.scoring = 'scoring'
        submit.problem_id = ['problem_id0', 'problem_id1']
        submit.user_id = 'user_id'
        submit.submit_id = 'submit_id'
        submit.lang_id = 'lang_id'
        submit.outcome = 'outcome'
        submit.timestamp = 'timestamp'
        submit.runs = [Mock(), Mock()]
        submit.runs[0].case_id = 'case_id0'
        submit.runs[1].case_id = 'case_id1'
        submit.runs[0].real_time = 'real_time0'
        submit.runs[1].real_time = 'real_time1'
        submit.runs[0].time = 'time0'
        submit.runs[1].time = 'time1'
        submit.runs[0].outcome = 'outcome0'
        submit.runs[1].outcome = 'outcome1'
        self.filler.fill_db_from_submit(submit, 'origin')
        self.assertEqual(len(self.filler.db_define_ref.mock_calls), 8)
        keys, values = ['origin', 'scoring', 'contest_id'], ['origin', 'scoring', 'problem_id0']
        self.assertEqual(self.filler.db_define_ref.mock_calls[0], call('Contests', keys, values))
        keys, values = ['origin', 'user_id'], ['origin', 'user_id']
        self.assertEqual(self.filler.db_define_ref.mock_calls[1], call('Users', keys, values))
        keys, values = ['contest_ref', 'problem_id'], [1, 'problem_id1']
        self.assertEqual(self.filler.db_define_ref.mock_calls[2], call('Problems', keys, values))
        keys, values = ['submit_id', 'problem_ref'], ['submit_id', 3]
        self.assertEqual(self.filler.db_define_ref.mock_calls[3], call('Submits', keys, values))
        keys, values = ['problem_ref', 'case_id'], [3, 'case_id0']
        self.assertEqual(self.filler.db_define_ref.mock_calls[4], call('Cases', keys, values))
        keys, values = ['submit_ref', 'case_ref'], [4, 5]
        self.assertEqual(self.filler.db_define_ref.mock_calls[5], call('Runs', keys, values))
        keys, values = ['problem_ref', 'case_id'], [3, 'case_id1']
        self.assertEqual(self.filler.db_define_ref.mock_calls[6], call('Cases', keys, values))
        keys, values = ['submit_ref', 'case_ref'], [4, 7]
        self.assertEqual(self.filler.db_define_ref.mock_calls[7], call('Runs', keys, values))

        self.assertEqual(len(self.filler.db_update.mock_calls), 3)
        keys, values = ['lang_id', 'outcome', 'timestamp', 'user_ref'], ['lang_id', 'outcome', 'timestamp', 2]
        self.assertEqual(self.filler.db_update.mock_calls[0], call('Submits', 4, keys, values))
        keys, values = ['realtime', 'time', 'outcome'], ['real_time0', 'time0', 'outcome0']
        self.assertEqual(self.filler.db_update.mock_calls[1], call('Runs', 6, keys, values))
        params = [('realtime', 'real_time1'), ('time', 'time1'), ('outcome', 'outcome1')]
        keys, values = ['realtime', 'time', 'outcome'], ['real_time1', 'time1', 'outcome1']
        self.assertEqual(self.filler.db_update.mock_calls[2], call('Runs', 8, keys, values))
Esempio n. 2
0
    def test_this_shit(self):
        run1 = Mock()
        run1.case_id = 1
        run1.outcome = 'OK'
        run1.time = 3000

        run2 = Mock()
        run2.case_id = 2
        run2.outcome = 'OK'
        run2.time = 3500

        run3 = Mock()
        run3.case_id = 3
        run3.outcome = 'OK'
        run3.time = 2700

        submit = Mock()
        submit.runs = [run1, run2, run3]

        for i in range(10):
            submit.problem_id = i
            self.srf.visit(submit)
            self.srf.visit(submit)

        run4 = Mock()
        run4.case_id = 1
        run4.outcome = 'OK'
        run4.time = 3000

        run5 = Mock()
        run5.case_id = 2
        run5.outcome = 'WA'
        run5.time = 3000

        submit1 = Mock()
        submit1.runs = [run4, run5]
        self.srf.visit(submit1)

        self.assertEqual(self.srf.pretty_print(),
                         'WE RECOMMEND REMOVING: 20/32 (62%)\nIT WILL SAVE: 0D 0H 2M 10S / 0D 0H 3M 10S (68%)\n')