コード例 #1
0
class TestModel__statement_finish(TestCase):
    def setUp(self):
        super(TestModel__statement_finish, self).setUp()

        self.now = int(time.time())
        self.time_start = self.now - 60
        self.time_stop = self.now + 30

        self.statement = Statement(
            olympiad=1,
            time_start=self.time_start,
            time_stop=self.time_stop,
        )
        db.session.add(self.statement)

        self.user = User()
        db.session.add(self.user)

        db.session.flush()

    def test_simple(self):
        with mock.patch('rmatics.model.statement.Statement.finish_participant',
                        mock.Mock()) as mock_finish:
            self.statement.finish(self.user)
        mock_finish.assert_called_once_with(self.user)
コード例 #2
0
ファイル: tests.py プロジェクト: ElinRin/informatics-alive
class TestModel__statement_set_settings(TestCase):
    def setUp(self):
        super(TestModel__statement_set_settings, self).setUp()

        self.statement = Statement()
        db.session.add(self.statement)

    def test_simple(self):
        settings = {
            'allowed_languages': [1],
        }
        self.statement.set_settings(settings)
        assert_that(
            self.statement.settings,
            equal_to(settings),
        )
        assert_that(
            self.statement.time_modified,
            close_to(time.time(), 1),
        )

    def test_type_olympiad(self):
        self.statement.set_settings({
            'type': 'olympiad',
        })
        assert_that(self.statement.olympiad, equal_to(True))
        assert_that(self.statement.virtual_olympiad, equal_to(False))

    def test_type_virtual(self):
        self.statement.set_settings({
            'type': 'virtual',
        })
        assert_that(self.statement.olympiad, equal_to(False))
        assert_that(self.statement.virtual_olympiad, equal_to(True))

    def test_type_null(self):
        self.statement.set_settings({
            'type': None,
        })
        assert_that(self.statement.olympiad, equal_to(False))
        assert_that(self.statement.virtual_olympiad, equal_to(False))

    def test_time_start_stop(self):
        time_start = 123
        time_stop = 456
        self.statement.set_settings({
            'time_start': time_start,
            'time_stop': time_stop,
        })
        assert_that(self.statement.time_start, equal_to(time_start))
        assert_that(self.statement.time_stop, equal_to(time_stop))

    def test_additional_property(self):
        settings = {
            'additional_propery': True,
        }
        assert_that(
            calling(self.statement.set_settings).with_args(settings),
            raises(StatementSettingsValidationError),
        )
コード例 #3
0
 def create_statements(self):
     self.statements = [
         Statement(),
         Statement(),
     ]
     db.session.add_all(self.statements)
     db.session.flush(self.statements)
コード例 #4
0
class TestModel__statement_start(TestCase):
    def setUp(self):
        super(TestModel__statement_start, self).setUp()

        self.now = int(time.time())
        self.time_start = self.now - 60
        self.time_stop = self.now + 30

        self.statement = Statement(
            olympiad=1,
            time_start=self.time_start,
            time_stop=self.time_stop,
        )
        db.session.add(self.statement)

        self.user = User()
        db.session.add(self.user)

        db.session.flush()

    def test_simple(self):
        with mock.patch('rmatics.model.statement.time.time', mock.Mock(return_value=self.now)), \
                mock.patch('rmatics.model.statement.Statement.start_participant', mock.Mock()) as mock_start:
            self.statement.start(self.user)

        mock_start.assert_called_once_with(
            user=self.user,
            duration=self.time_stop - self.now,
            password=None,
        )

    def test_not_olympiad(self):
        statement = Statement(olympiad=0)
        db.session.add(statement)
        assert_that(
            calling(statement.start).with_args(self.user),
            raises(StatementNotOlympiad))

    def test_not_started(self):
        with mock.patch('rmatics.model.statement.time.time',
                        mock.Mock(return_value=self.time_start - 1)):
            assert_that(
                calling(self.statement.start).with_args(user=self.user),
                raises(StatementNotStarted))

    def test_finished(self):
        with mock.patch('rmatics.model.statement.time.time',
                        mock.Mock(return_value=self.time_stop)):
            assert_that(
                calling(self.statement.start).with_args(user=self.user),
                raises(StatementFinished))

        with mock.patch('rmatics.model.statement.time.time',
                        mock.Mock(return_value=self.time_stop + 10)):
            assert_that(
                calling(self.statement.start).with_args(user=self.user),
                raises(StatementFinished))
コード例 #5
0
ファイル: tests.py プロジェクト: ElinRin/informatics-alive
    def setUp(self):
        super(TestModel__Statement_finish_virtual, self).setUp()

        self.now = int(time.time())
        self.virtual_duration = 100
        self.time_start = self.now - 60
        self.statement = Statement(
            virtual_olympiad=1,
            virtual_duration=self.virtual_duration,
            time_start=self.time_start,
        )
        db.session.add(self.statement)

        self.user = User()
        db.session.add(self.user)

        db.session.flush()
コード例 #6
0
ファイル: tests.py プロジェクト: ElinRin/informatics-alive
class TestModel__Statement_start_virtual(TestCase):
    def setUp(self):
        super(TestModel__Statement_start_virtual, self).setUp()

        self.now = int(time.time())
        self.virtual_duration = 60
        self.time_start = self.now - 60

        self.statement = Statement(
            virtual_olympiad=1,
            virtual_duration=self.virtual_duration,
            time_start=self.time_start,
        )
        db.session.add(self.statement)

        self.user = User()
        db.session.add(self.user)

        db.session.flush()

    def test_simple(self):
        with mock.patch('rmatics.model.statement.time.time', mock.Mock(return_value=self.now)), \
                mock.patch('rmatics.model.statement.Statement.start_participant', mock.Mock()) as mock_start:
            self.statement.start_virtual(self.user)
        mock_start.assert_called_once_with(
            user=self.user,
            duration=self.virtual_duration,
            password=None,
        )

    def test_not_virtual(self):
        statement = Statement(virtual_olympiad=0)
        db.session.add(statement)
        assert_that(
            calling(statement.start_virtual).with_args(self.user),
            raises(StatementNotVirtual))

    def test_ignores_not_started(self):
        # Виртуальные контесты должны игнорировать поля time_start, time_end для согласования с
        # поведением на старом информатиксе
        with mock.patch('rmatics.model.statement.time.time',
                        mock.Mock(return_value=self.time_start - 1)):
            assert_that(
                calling(self.statement.start_virtual).with_args(self.user),
                is_not(raises(StatementNotStarted)),
            )
コード例 #7
0
ファイル: tests.py プロジェクト: ElinRin/informatics-alive
    def setUp(self):
        super(TestAPI__statement_standings, self).setUp()

        self.create_user_groups()
        self.create_problems()

        self.statement = Statement()
        db.session.add(self.statement)
        db.session.flush()
コード例 #8
0
    def setUp(self):
        super(TestModel__statement_start, self).setUp()

        self.now = int(time.time())
        self.time_start = self.now - 60
        self.time_stop = self.now + 30

        self.statement = Statement(
            olympiad=1,
            time_start=self.time_start,
            time_stop=self.time_stop,
        )
        db.session.add(self.statement)

        self.user = User()
        db.session.add(self.user)

        db.session.flush()
コード例 #9
0
    def setUp(self):
        super(TestModel__statement_start_participant, self).setUp()

        self.create_statements()

        self.now = int(time.time())
        self.duration = 10

        self.user = User()
        db.session.add(self.user)

        self.time_start = self.now
        self.time_stop = self.now + 100
        self.statement = Statement(
            time_start=self.time_start,
            time_stop=self.time_stop,
        )
        db.session.add(self.statement)

        db.session.flush()
コード例 #10
0
    def setUp(self):
        super(TestAPI__statement_start_virtual, self).setUp()

        self.virtual_statement = Statement(
            virtual_olympiad=1,
            virtual_duration=300,
            time_start=0,
            time_stop=int(time.time()) + 100,
        )
        db.session.add(self.virtual_statement)

        self.user = User()
        db.session.add(self.user)
        db.session.flush()
コード例 #11
0
    def setUp(self):
        super(TestView__statement_get_by_module, self).setUp()

        self.statement = Statement()
        db.session.add(self.statement)
        db.session.flush()

        self.course_module = CourseModule(
            id=123,
            instance_id=self.statement.id,
            module=19,
        )
        db.session.add(self.course_module)
        db.session.flush()
コード例 #12
0
    def setUp(self):
        super(TestAPI__statement_start, self).setUp()

        self.user = User()
        db.session.add(self.user)

        self.now = time.time()
        self.duration = 290
        self.statement = Statement(
            olympiad=1,
            time_start=self.now - 10,
            time_stop=self.now + self.duration,
        )
        db.session.add(self.statement)
        db.session.flush()
コード例 #13
0
ファイル: tests.py プロジェクト: ElinRin/informatics-alive
    def setUp(self):
        super(TestModel__statement_serialize, self).setUp()

        self.course = Course(id=123)
        db.session.add(self.course)

        self.statement = Statement(course=self.course)
        self.user = User()

        db.session.add_all([self.statement, self.user])
        db.session.flush()

        self.course_module = CourseModule(
            instance_id=self.statement.id,
            module=19,
            course_id=self.course.id,
        )

        self.participant = Participant(
            user_id=self.user.id,
            statement_id=self.statement.id,
        )

        db.session.add_all([self.course_module, self.participant])
コード例 #14
0
ファイル: tests.py プロジェクト: ElinRin/informatics-alive
    def setUp(self):
        super(TestAPI__statement_finish_virtual, self).setUp()

        self.virtual_statement = Statement(
            virtual_olympiad=1,
            virtual_duration=300,
        )
        db.session.add(self.virtual_statement)

        self.user = User()
        db.session.add(self.user)
        db.session.flush()

        self.actual_duration = 10
        self.participant = Participant(
            user_id=self.user.id,
            statement_id=self.virtual_statement.id,
            start=time.time() - self.actual_duration,
            duration=300,
        )
        db.session.add(self.participant)
コード例 #15
0
    def setUp(self):
        super(TestAPI__statement_set_settings, self).setUp()

        self.create_roles()

        self.user = User()
        self.admin_user = User()

        self.statement = Statement()

        db.session.add_all((
            self.user,
            self.admin_user,
            self.statement,
        ))
        db.session.flush()

        role_assignment = RoleAssignment(
            user_id=self.admin_user.id,
            role_id=self.admin_role.id,
        )
        db.session.add(role_assignment)
コード例 #16
0
    def setUp(self):
        super(TestAPI__statement_finish, self).setUp()

        self.user = User()
        db.session.add(self.user)

        self.now = time.time()
        self.duration = 290
        self.statement = Statement(
            olympiad=1,
            time_start=self.now - 10,
            time_stop=self.now + self.duration,
        )
        db.session.add(self.statement)
        db.session.flush()

        self.actual_duration = 5
        self.participant = Participant(
            user_id=self.user.id,
            statement_id=self.statement.id,
            start=int(self.now - self.actual_duration),
            duration=self.duration,
        )
        db.session.add(self.participant)
コード例 #17
0
 def test_not_olympiad(self):
     statement = Statement(olympiad=0)
     db.session.add(statement)
     assert_that(
         calling(statement.start).with_args(self.user),
         raises(StatementNotOlympiad))
コード例 #18
0
ファイル: tests.py プロジェクト: ElinRin/informatics-alive
    def setUp(self):
        super(TestModel__statement_set_settings, self).setUp()

        self.statement = Statement()
        db.session.add(self.statement)
コード例 #19
0
ファイル: tests.py プロジェクト: ElinRin/informatics-alive
class TestModel__statement_serialize(TestCase):
    def setUp(self):
        super(TestModel__statement_serialize, self).setUp()

        self.course = Course(id=123)
        db.session.add(self.course)

        self.statement = Statement(course=self.course)
        self.user = User()

        db.session.add_all([self.statement, self.user])
        db.session.flush()

        self.course_module = CourseModule(
            instance_id=self.statement.id,
            module=19,
            course_id=self.course.id,
        )

        self.participant = Participant(
            user_id=self.user.id,
            statement_id=self.statement.id,
        )

        db.session.add_all([self.course_module, self.participant])


    def test_simple(self):
        assert_that(
            self.statement.serialize(),
            has_entries({
                'course': anything(),
                'course_module_id': 1,
                'id': self.statement.id,
                'name': None,
                'olympiad': None,
                'problems': {},
                'settings': None,
                'time_start': None,
                'time_stop': None,
                'virtual_duration': None,
                'virtual_olympiad': None,
            })
        )

    def test_olympiad(self):
        self.statement.olympiad = True
        with self.app.test_request_context():
            g.user = None
            assert_that(
                self.statement.serialize(),
                is_not(has_items('problems'))
            )
        with self.app.test_request_context():
            g.user = self.user
            assert_that(
                self.statement.serialize(),
                has_items('problems')
            )

    def test_virtual_olympiad(self):
        self.statement.virtual_olympiad = True
        with self.app.test_request_context():
            g.user = None
            assert_that(
                self.statement.serialize(),
                is_not(has_items('problems'))
            )
        with self.app.test_request_context():
            g.user = self.user
            assert_that(
                self.statement.serialize(),
                has_items('problems')
            )
コード例 #20
0
class TestModel__statement_start_participant(TestCase):
    def setUp(self):
        super(TestModel__statement_start_participant, self).setUp()

        self.create_statements()

        self.now = int(time.time())
        self.duration = 10

        self.user = User()
        db.session.add(self.user)

        self.time_start = self.now
        self.time_stop = self.now + 100
        self.statement = Statement(
            time_start=self.time_start,
            time_stop=self.time_stop,
        )
        db.session.add(self.statement)

        db.session.flush()

    def test_simple(self):
        with mock.patch('rmatics.model.statement.time.time',
                        mock.Mock(return_value=self.now)):
            participant = self.statement.start_participant(
                user=self.user,
                duration=self.duration,
            )
        assert_that(participant.user_id, equal_to(self.user.id))
        assert_that(participant.statement_id, equal_to(self.statement.id))
        assert_that(participant.start, equal_to(self.now))
        assert_that(participant.duration, equal_to(self.duration))
        db.session.query(Participant) \
            .filter_by(user_id=self.user.id) \
            .filter_by(statement_id=self.statement.id) \
            .filter_by(start=self.now) \
            .filter_by(duration=self.duration) \
            .one()

    def test_can_only_start_once(self):
        participant = Participant(
            user_id=self.user.id,
            statement_id=self.statement.id,
            start=self.now - self.duration,
            duration=self.duration,
        )
        db.session.add(participant)
        assert_that(
            calling(self.statement.start_participant).with_args(
                user=self.user,
                duration=self.duration,
            ), raises(StatementCanOnlyStartOnce))

    def test_only_one_ongoing(self):
        participant = Participant(
            user_id=self.user.id,
            statement_id=self.statements[0].id,
            start=self.now - self.duration,
            duration=self.duration * 2,
        )
        db.session.add(participant)
        assert_that(
            calling(self.statement.start_participant).with_args(
                user=self.user,
                duration=self.duration,
            ), raises(StatementOnlyOneOngoing))

    def test_with_password(self):
        password = '******'
        course = Course(password=password)
        db.session.add(course)
        self.statement.course = course

        with mock.patch('rmatics.model.statement.time.time',
                        mock.Mock(return_value=self.now)):
            assert_that(
                calling(self.statement.start_participant).with_args(
                    user=self.user,
                    duration=self.duration,
                ), raises(StatementPasswordIsWrong))
            assert_that(
                calling(self.statement.start_participant).with_args(
                    user=self.user,
                    duration=self.duration,
                    password='******',
                ), raises(StatementPasswordIsWrong))
            assert_that(
                calling(self.statement.start_participant).with_args(
                    user=self.user,
                    duration=self.duration,
                    password=password,
                ), is_not(raises(StatementPasswordIsWrong)))
コード例 #21
0
ファイル: tests.py プロジェクト: ElinRin/informatics-alive
 def test_not_virtual(self):
     statement = Statement(virtual_olympiad=0)
     db.session.add(statement)
     assert_that(
         calling(statement.start_virtual).with_args(self.user),
         raises(StatementNotVirtual))