Esempio n. 1
0
 def post(self, id):
     data = request.get_json()
     if not TournamentsToObject.is_exist(id, data['contestant_id']):
         return return_bad_status(
             'Вы еще не регистрировались на этот турнир!')
     TournamentsToObject.delete(id, data['contestant_id'])
     return return_ok_status('ok')
Esempio n. 2
0
 def test_should_delete_team_to_tournament(self):
     with app.app_context():
         self.team_to_tournament = TournamentsToObject(
             1, 1, self.user, self.tournament)
         self.team_to_tournament.add()
         self.team_to_tournament.delete()
         self.assertFalse(TournamentsToObject.query.count())
Esempio n. 3
0
 def post(self, id):
     data = request.get_json()
     if TournamentsToObject.is_exist(id, data['contestant_id']):
         return return_bad_status('Вы уже зарегестрированы на этот турнир!')
     reg = TournamentsToObject(id, data['contestant_id'])
     reg.add()
     return return_ok_status('ok')
Esempio n. 4
0
 def get(self):
     tournament_id = int(request.args['tournament_id'])
     return return_ok_status({
         'scoreboard':
         TournamentsToObjectScorehistorySchema(many=True).dump(
             TournamentsToObject.get_all_objects_to_tournament(
                 tournament_id)).data,
         'tournament_begin':
         TournamentSchema().dump(
             Tournament.get_info(tournament_id)).data['time']
     })
    def get(self, team_id):
        team = Team.get_by_id(team_id)

        if not team:
            return return_bad_status('Команды с таким id не существует')

        print(team.members)
        tournaments = TournamentsToObject.get_all_by_user_id(team.id)
        tournaments_ = TournamentsToObjectSchema(
            many=True).dump(tournaments).data
        result = TeamSchema().dump(team)
        members = UserSchema(many=True).dump(team.members)
        return return_ok_status([result[0], tournaments_, members])
Esempio n. 6
0
    def get(self, id):
        user = User.query.filter(User.id == id).first()
        if not user:
            return return_bad_status('Пользователя с таким id не существует.')
        result = UserSchema().dump(user).data
        tournaments = TournamentsToObject.get_all_by_user_id(user.id)
        tournaments_ = TournamentsToObjectSchema(
            many=True).dump(tournaments).data

        if user.id == session['id']:
            result['own'] = 1
        else:
            result['own'] = ''
        return return_ok_status([result, tournaments_])
Esempio n. 7
0
 def process(self, form: FlaskForm):
     task_id = int(form.id.data)
     tournament_id = int(form.tournament_id.data)
     task = Task.get_by_id(task_id)
     tournament = Tournament.get_info(tournament_id)
     true_flag = task.flag
     user_flag = form.flag.data
     contestant_id = g.user.id
     if not tournament.for_team_allowed and g.user.teams:
         contestant_id = g.user.teams[0]
     tournament_to_object = TournamentsToObject.get_one_or_none(
         tournament_id, contestant_id)
     if not tournament_to_object:
         return return_bad_status(
             "Ты должен войти в турнир чтобы сдать таск")
     if Attempt.already_solved(tournament_to_object.id, task_id):
         return return_bad_status("Задача сдана")
     if user_flag == true_flag:
         attemp = Attempt(user_flag,
                          True,
                          task=task.id,
                          tournament_to_object=tournament_to_object.id)
         attemp.save()
         send_scoreboard_to_room(
             tournament_id
         )  # Notify everyone who is watching scoreboard for this tournament
         return return_ok_status({
             'right': True,
             'message': 'Попытка добавлена'
         })
     else:
         attemp = Attempt(user_flag,
                          False,
                          task=task.id,
                          tournament_to_object=tournament_to_object.id)
         attemp.save()
         return return_ok_status({
             'right': False,
             'message': 'Попытка добавлена'
         })
Esempio n. 8
0
 def test_should_add_team_to_tournament(self):
     with app.app_context():
         self.team_to_tournament = TournamentsToObject(
             1, 1, self.user, self.tournament)
         self.assertEqual(self.team_to_tournament.add(), 1)
Esempio n. 9
0
class TestTournament(unittest.TestCase):
    def setUp(self):
        app.config['TESTING'] = True
        app.config['CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(
            BASE_DIR, TEST_DB)
        self.app = app.test_client()
        db.create_all()
        self.invite_link = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for _ in range(32))

        our_time = "2019-01-05 22:14:39"
        our_time_to_live = "2019-04-05 22:14:39"

        our_datetime = datetime.strptime(our_time, "%Y-%m-%d %H:%M:%S")
        our_datetime_to_live = datetime.strptime(our_time_to_live,
                                                 "%Y-%m-%d %H:%M:%S")

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

        print(self.user.id)

        self.tournament = Tournament("CTF", "description", self.user,
                                     our_datetime, our_datetime_to_live,
                                     "45.408062, -123.007827",
                                     self.invite_link, True, True, False, True)
        self.tournament.add()

    def tearDown(self):
        db.session.remove()
        db.drop_all()

    def test_should_model_has_need_fields(self):
        self.assertTrue(hasattr(self.tournament, "id"))
        self.assertTrue(hasattr(self.tournament, "name"))
        self.assertTrue(hasattr(self.tournament, "description"))
        self.assertTrue(hasattr(self.tournament, "private"))
        self.assertTrue(hasattr(self.tournament, "platform"))
        self.assertTrue(hasattr(self.tournament, "invite_link"))
        self.assertTrue(hasattr(self.tournament, "creator"))
        self.assertTrue(hasattr(self.tournament, "time"))
        self.assertTrue(hasattr(self.tournament, "time_to_live"))
        self.assertTrue(hasattr(self.tournament, "place"))
        self.assertTrue(hasattr(self.tournament, "online"))
        self.assertTrue(hasattr(self.tournament, "for_team_allowed"))

    def test_should_tournament_delete(self):
        with app.app_context():
            self.tournament.delete()
            self.assertFalse(Tournament.query.count())

    def test_should_add_team_to_tournament(self):
        with app.app_context():
            self.team_to_tournament = TournamentsToObject(
                1, 1, self.user, self.tournament)
            self.assertEqual(self.team_to_tournament.add(), 1)

    def test_should_delete_team_to_tournament(self):
        with app.app_context():
            self.team_to_tournament = TournamentsToObject(
                1, 1, self.user, self.tournament)
            self.team_to_tournament.add()
            self.team_to_tournament.delete()
            self.assertFalse(TournamentsToObject.query.count())
Esempio n. 10
0
 def get_contestants():
     contestants = TournamentsToObject.get_all()
     return TournamentsToObjectSchema(many=True).dump(contestants).data
Esempio n. 11
0
 def in_tournament(tournament_id):
     if TournamentsToObject.is_exist(tournament_id, session['id']):
         return True
     return False
Esempio n. 12
0
 def get_contestants(tournament_id, team):
     contestants = TournamentsToObject.get_all_people_in_tournament(
         tournament_id)
     if not team:
         return TournamentsToObjectSchema(many=True).dump(contestants).data
     return TournamentsToObjectSchema2(many=True).dump(contestants).data