Esempio n. 1
0
    def test_given_non_correct_regex_flag_should_persist_submission_with_is_correct_false(
            self, _db_mock: MagicMock, flag_mock: MagicMock,
            _current_user_mock: MagicMock):
        _current_user_mock.get_team.return_value = A_TEAM
        flag_mock.query.filter_by.return_value.all.return_value = [
            Flag(id=1,
                 challenge_id=A_CHALLENGE.id,
                 is_regex=True,
                 value=self.REQUEST_BODY['flag'] + '1')
        ]

        submit_flag.func(event=A_EVENT, challenge=A_CHALLENGE)

        _db_mock.session.add.assert_called_with(
            Submission(team_id=A_TEAM.id,
                       challenge_id=A_CHALLENGE.id,
                       input=self.REQUEST_BODY['flag'],
                       is_correct=False))
Esempio n. 2
0
    def test_given_incorrect_flag_should_return_correct_false(
            self, flag_mock: MagicMock, _current_user_mock: MagicMock):
        _current_user_mock.get_team.return_value = A_TEAM
        flag_mock.query.filter_by.return_value.all.return_value = [
            Flag(id=1,
                 challenge_id=A_CHALLENGE.id,
                 is_regex=True,
                 value=self.REQUEST_BODY['flag'] + '1')
        ]

        result = submit_flag.func(event=A_EVENT, challenge=A_CHALLENGE)
        assert result == {'correct': False}
Esempio n. 3
0
 def test_given_challenge_and_team_not_in_same_event_should_raise_unprocessable_entity_error(
         self):
     with raises(errors.UnprocessableEntity):
         submit_flag.func(challenge=A_CHALLENGE, event=A_EVENT)
Esempio n. 4
0
 def test_given_non_existent_team_id_should_raise_not_found_error(
         self, _current_user_mock):
     _current_user_mock.get_team.return_value = None
     with raises(errors.NotFound):
         submit_flag.func(challenge=A_CHALLENGE, event=A_EVENT)