def test_get_runs(self):
        user_ids = [user.id for user in self.users]
        serialized_runs = get_runs(problem_id=self.problems[0].id,
                                   user_ids=user_ids)

        self.mock_cacher_get.assert_called_once()
        self.mock_cacher_set.assert_called_once()

        self.assertEqual(len(serialized_runs), 3)

        run = self.runs[0]
        serialized_run = serialized_runs[0]
        expected_run_time = run.create_time.replace(tzinfo=UTC).strftime('%Y-%m-%dT%H:%M:%S%z')
        self.assertIn('user', serialized_run)
        self.assertEqual(serialized_run.get('id'), run.id)
        self.assertEqual(serialized_run.get('problem_id'), run.problem_id)
        self.assertEqual(serialized_run.get('create_time'), expected_run_time)
        self.assertEqual(serialized_run.get('ejudge_score'), run.ejudge_score)
        self.assertEqual(serialized_run.get('ejudge_test_num'), run.ejudge_test_num)

        user = run.user
        serialized_user = serialized_run['user']
        self.assertEqual(serialized_user.get('id'), user.id)
        self.assertEqual(serialized_user.get('firstname'), user.firstname)
        self.assertEqual(serialized_user.get('lastname'), user.lastname)
    def test_get_runs_after(self):
        time_creation = datetime.datetime.utcnow() - datetime.timedelta(days=1)
        self.create_runs(time_creation)
        time_after = time_creation + datetime.timedelta(hours=1)

        user_ids = [user.id for user in self.users]
        runs = get_runs(problem_id=self.problems[0].id,
                        user_ids=user_ids,
                        time_after=int(time_after.timestamp()))

        self.assertEqual(len(runs), 3)
    def test_get_runs(self):
        user_ids = [user.id for user in self.users]
        serialized_runs = get_runs(problem_id=self.problems[0].id,
                                   user_ids=user_ids)

        self.mock_cacher_get.assert_called_once()
        self.mock_cacher_set.assert_called_once()

        self.assertEqual(len(serialized_runs), 3)

        serialized_run = serialized_runs[0]
        self.assertIn('user', serialized_run)

        run = self.runs[0]
        user = serialized_run['user']
        self.assertEqual(user.get('id'), run.user.id)
        self.assertEqual(user.get('firstname'), run.user.firstname)
        self.assertEqual(user.get('lastname'), run.user.lastname)