Пример #1
0
    def setUp(self):
        super(TestModel__ejudge_run_serialize, self).setUp()

        self.create_problems()

        self.author = SimpleUser(
            ejudge_id=1,
            firstname='author_firstname',
            lastname='author_lastname',
        )
        self.other = SimpleUser(
            ejudge_id=2,
            firstname='other_firstname',
            lastname='other_lastname',
        )
        db.session.add_all([self.author, self.other])
        db.session.flush()

        self.run = EjudgeRun(
            user=self.author,
            run_id=123,
            problem=self.problems[0],
        )
        db.session.add(self.run)
        db.session.flush([self.run])

        self.pynformatics_run_serialized = {'some_key': 'some_value'}
        self.pynformatics_run_mock = mock.Mock()
        self.pynformatics_run_mock.serialize = mock.Mock(
            return_value=self.pynformatics_run_serialized)
Пример #2
0
 def create_users(self):
     self.users = [
         SimpleUser(
             firstname='Maxim',
             lastname='Grishkin',
             ejudge_id=179,
         ),
         SimpleUser(
             firstname='Somebody',
             lastname='Oncetoldme',
             ejudge_id=1543,
         ),
     ]
     db.session.add_all(self.users)
     db.session.flush(self.users)
Пример #3
0
    def setUp(self):
        super(TestView__protocol_get_v2, self).setUp()

        self.user = SimpleUser(ejudge_id=22)
        db.session.add(self.user)
        db.session.flush()

        self.run_id = 123
        self.contest_id = 456

        self.problem = EjudgeProblem(
            ejudge_prid=1,
            contest_id=2,
            ejudge_contest_id=self.contest_id,
            problem_id=4,
        )
        db.session.add(self.problem)
        db.session.flush()

        self.run = EjudgeRun(
            run_id=self.run_id,
            problem=self.problem,
            user_id=self.user.ejudge_id,
        )

        db.session.add(self.run)
        db.session.flush()
Пример #4
0
    def setUp(self):
        super().setUp()

        self.create_ejudge_problems()
        self.create_problems()
        self.create_statements()
        self.create_statement_problems()
        self.create_course_module_statement()

        self.user1 = SimpleUser(firstname='user1', lastname='user1')
        self.user2 = SimpleUser(firstname='user2', lastname='user2')

        db.session.add_all([self.user1, self.user2])

        db.session.flush()

        self.run1 = Run(user_id=self.user1.id,
                        problem_id=self.problems[1].id,
                        ejudge_status=0,
                        ejudge_language_id=1)
        self.run2 = Run(user_id=self.user1.id,
                        problem_id=self.problems[2].id,
                        ejudge_status=0,
                        ejudge_language_id=1)
        self.run3 = Run(user_id=self.user2.id,
                        problem_id=self.problems[1].id,
                        ejudge_status=2,
                        ejudge_language_id=2)
        self.run4 = Run(user_id=self.user2.id,
                        problem_id=self.problems[2].id,
                        ejudge_status=2,
                        ejudge_language_id=2)

        self.run4.create_time = datetime.utcnow() - timedelta(days=1)

        db.session.add_all([self.run1, self.run2, self.run3, self.run4])

        self.group = Group()
        db.session.add(self.group)
        db.session.flush()

        user_group = UserGroup(user_id=self.user1.id, group_id=self.group.id)
        db.session.add(user_group)

        db.session.commit()
Пример #5
0
    def setUp(self):
        super().setUp()

        self.create_ejudge_problems()
        self.create_problems()
        self.create_statements()
        self.create_statement_problems()
        self.create_course_module_statement()

        self.user1 = SimpleUser(firstname='user1', lastname='user1')
        self.user2 = SimpleUser(firstname='user2', lastname='user2')

        db.session.add_all([self.user1, self.user2])

        db.session.flush()
        db.session.commit()

        self.SOURCE_HASH = 'source-hash'
        self.CONTEXT_SOURCE = 1
Пример #6
0
    def setUp(self):
        super(TestModel__pynformatics_run__serialize, self).setUp()

        self.create_statements()

        self.author = SimpleUser(ejudge_id=666)
        self.other = SimpleUser(ejudge_id=777)
        self.run = EjudgeRun(
            run_id=1,
            contest_id=2,
            user=self.author,
        )
        self.pynformatics_run = PynformaticsRun(
            run=self.run,
            statement=self.statements[0],
            source='some source',
        )

        db.session.add_all(
            [self.author, self.other, self.run, self.pynformatics_run])
        db.session.flush()
Пример #7
0
class TestModel__simple_user_rest_password(TestCase):
    def setUp(self):
        super(TestModel__simple_user_rest_password, self).setUp()

        self.simple_user = SimpleUser()
        db.session.add(self.simple_user)

    def test_simple(self):
        password = '******'
        hashed_password = '******'
        with mock.patch('rmatics.model.user.random_password', mock.Mock(return_value=password)), \
                mock.patch('rmatics.model.user.hash_password', mock.Mock(return_value=hashed_password)):
            assert_that(self.simple_user.reset_password(), equal_to(password))
            assert_that(self.simple_user.password_md5,
                        equal_to(hashed_password))
Пример #8
0
    def setUp(self):
        super().setUp()

        self.create_ejudge_problems()
        self.create_problems()
        self.create_statements()
        self.create_statement_problems()
        self.create_course_module_statement()

        self.user1 = SimpleUser(firstname='user1', lastname='user1')
        self.user2 = SimpleUser(firstname='user2', lastname='user2')
        db.session.add_all([self.user1, self.user2])
        db.session.flush()

        self.run1 = Run(user_id=self.user1.id,
                        problem_id=self.problems[1].id,
                        ejudge_status=0,
                        ejudge_language_id=1,
                        is_visible=True)
        self.run2 = Run(user_id=self.user1.id,
                        problem_id=self.problems[2].id,
                        ejudge_status=0,
                        ejudge_language_id=1,
                        is_visible=True)
        self.run3 = Run(user_id=self.user2.id,
                        problem_id=self.problems[1].id,
                        ejudge_status=2,
                        ejudge_language_id=2,
                        is_visible=True)
        self.run4 = Run(user_id=self.user2.id,
                        problem_id=self.problems[2].id,
                        ejudge_status=2,
                        ejudge_language_id=2,
                        is_visible=True)
        self.run5 = Run(user_id=self.user2.id,
                        problem_id=self.problems[1].id,
                        ejudge_status=2,
                        ejudge_language_id=2,
                        is_visible=False)

        self.run4.create_time = datetime.utcnow() - timedelta(days=1)

        # Context tests fixtures
        self.run1.context_source = CONTEXT_SOURCE
        self.run5.context_source = CONTEXT_SOURCE

        self.run1.statement_id = CONTEXT_ID_1
        self.run3.statement_id = CONTEXT_ID_1
        self.run5.statement_id = CONTEXT_ID_1
        self.run2.statement_id = CONTEXT_ID_2
        self.run4.statement_id = CONTEXT_ID_2

        db.session.add_all(
            [self.run1, self.run2, self.run3, self.run4, self.run5])

        self.group = Group()
        db.session.add(self.group)
        db.session.flush()

        user_group = UserGroup(user_id=self.user1.id, group_id=self.group.id)
        db.session.add(user_group)

        db.session.commit()
Пример #9
0
    def setUp(self):
        super(TestModel__simple_user_rest_password, self).setUp()

        self.simple_user = SimpleUser()
        db.session.add(self.simple_user)
Пример #10
0
class TestModel__ejudge_run_serialize(TestCase):
    def setUp(self):
        super(TestModel__ejudge_run_serialize, self).setUp()

        self.create_problems()

        self.author = SimpleUser(
            ejudge_id=1,
            firstname='author_firstname',
            lastname='author_lastname',
        )
        self.other = SimpleUser(
            ejudge_id=2,
            firstname='other_firstname',
            lastname='other_lastname',
        )
        db.session.add_all([self.author, self.other])
        db.session.flush()

        self.run = EjudgeRun(
            user=self.author,
            run_id=123,
            problem=self.problems[0],
        )
        db.session.add(self.run)
        db.session.flush([self.run])

        self.pynformatics_run_serialized = {'some_key': 'some_value'}
        self.pynformatics_run_mock = mock.Mock()
        self.pynformatics_run_mock.serialize = mock.Mock(
            return_value=self.pynformatics_run_serialized)

    def call_serialize(self):
        with mock.patch(
                'rmatics.model.ejudge_run.EjudgeRun.get_pynformatics_run',
                mock.Mock(return_value=self.pynformatics_run_mock)):
            return self.run.serialize()

    def test_for_author(self):
        with self.app.test_request_context():
            g.user = self.author
            result = self.call_serialize()
        assert_that(
            result,
            has_entries({
                'status': None,
                'contest_id': self.run.contest_id,
                'prob_id': 1,
                'run_id': self.run.run_id,
                'create_time': 'None',
                'lang_id': None,
                'score': None,
                'size': None,
            }))
        assert_that(result, has_entries(self.pynformatics_run_serialized))
        assert_that(result, is_not(has_key('user')))

    def test_for_other(self):
        with self.app.test_request_context():
            g.user = self.other
            result = self.call_serialize()
        assert_that(
            result,
            has_entries({
                'status': None,
                'contest_id': self.run.contest_id,
                'prob_id': 1,
                'run_id': self.run.run_id,
                'create_time': 'None',
                'lang_id': None,
                'score': None,
                'size': None,
                'user': self.author.serialize()
            }))