Пример #1
0
    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()
Пример #2
0
 def get(self, tournament_id):
     if Tournament.is_exist_by_id(tournament_id):
         tournament = self.get_info(tournament_id)
         creator = self.get_creator(tournament['creator'])
         contestants = self.get_contestants()
         in_tournament = self.in_tournament(tournament_id)
         return return_ok_status(
             [tournament, creator, contestants, in_tournament])
     return return_bad_status("Такого турнира не существует!")
Пример #3
0
    def process(self, form: FlaskForm):
        if not is_auth():
            return return_bad_status("Вы не авторизованы!")

        user_id = session['id']
        user = User.get_user_by_id(user_id)
        time = form.time.data
        time_to_live = form.time_to_live.data
        link = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for _ in range(32))
        tour = Tournament(form.name.data, form.description.data, user, time,
                          time_to_live, form.place.data, link,
                          bool(int(form.private.data)),
                          bool(int(form.platform.data)),
                          bool(int(form.online.data)),
                          bool(int(form.for_team_allowed.data)))
        last = tour.add()
        return return_ok_status(last)
Пример #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']
     })
Пример #5
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': 'Попытка добавлена'
         })
Пример #6
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())
Пример #7
0
 def get_info(tournament_id):
     tournament = Tournament.get_info(tournament_id)
     if tournament:
         return TournamentSchema().dump(tournament).data
     return False