Exemple #1
0
 def save(self):
     game_type = self.cleaned_data['type']
     csv_file = self.cleaned_data['file']
     for line in csv_file.readlines():
         teams = line.strip().split(',')
         try:
             group = Group.objects.get(name=teams[0])
         except Group.DoesNotExist:
             group = None
         try:
             game_conf = GameConfiguration.objects.get(id=teams[1])
         except GameConfiguration.DoesNotExist:
             continue
         try:
             place = GamePlace.objects.get(id=teams[2])
         except GamePlace.DoesNotExist:
             place = None
         try:
             time = datetime.datetime(*list(map(int, teams[3:8])))
         except ValueError:
             time = None
         Game.create([Team.objects.get(id=team) for team in teams[8:]],
                     game_type=game_type,
                     game_conf=game_conf,
                     title=self.cleaned_data['name'],
                     group=group,
                     place=place,
                     time=time)
    def setUpTestData(cls):
        super().setUpTestData()
        for i in range(4):
            User.objects.create_user(username='******' + str(i),
                                     email='player' + str(i) + '@test.com',
                                     password=cls.password)
        players = Player.objects.all()
        players_team_a = [players[0], players[1]]
        players_team_b = [players[2], players[3]]
        team_a = Team.create(players_team_a)
        team_b = Team.create(players_team_b)
        print(team_a)
        print(team_b)

        team_a = Team.get_or_create_team(
            [player.id for player in team_a.players.all()])
        team_b = Team.get_or_create_team(
            [player.id for player in team_b.players.all()])
        teams = [team_a, team_b]
        max_score = 13
        score_a = 13
        score_b = 7
        game = Game.create(max_score=max_score, teams=teams)
        ScoreTeam.objects.create(team=team_a, game=game, score=score_a)
        ScoreTeam.objects.create(team=team_b, game=game, score=score_b)
        max_score = 13
        score_a = 7
        score_b = 13
        game = Game.create(max_score=max_score, teams=teams)
        ScoreTeam.objects.create(team=team_a, game=game, score=score_a)
        ScoreTeam.objects.create(team=team_b, game=game, score=score_b)
Exemple #3
0
    def setUp(self):

        logger.debug('GameSearchTest.setUp')
        user = get_user()
        for i in range(1, 8):
            title = ''
            title += 'foo ' if i & 1 == 1 else ''
            title += 'bar ' if i & 2 == 2 else ''
            title += 'baz ' if i & 4 == 4 else ''
            Game.create(title, '', developer=user).save()

        Game.create('game1',
                    '',
                    description='some description',
                    developer=user).save()
        Game.create('game2',
                    '',
                    description='also some description',
                    developer=user).save()
        Game.create('title',
                    '',
                    description='this game has a title',
                    developer=user).save()
        Game.create('another game',
                    '',
                    description='this game also has a title',
                    developer=user).save()
Exemple #4
0
    def setUp(self):

        logger.debug('BuyViewTest.setUp')

        self.client = Client()
        user = get_user()
        self.client.force_login(user)

        Game.create(title='title', url='url', developer=user).save()
Exemple #5
0
    def setUp(self):

        logger.debug('SearchViewTest.setUp')

        self.client = Client()
        user = get_user()

        for i in range(0, 30):
            Game.create('game title {0}'.format(i), '', developer=user).save()
    def accept(self, accepted):
        wait = GameRequest.check_last_time(self.requester)
        if wait:
            return wait

        self.accepted = accepted
        self.accept_time = timezone.now()
        if accepted:
            Game.create([self.requestee, self.requester], game_conf=self.game_config)
        self.save()
Exemple #7
0
    def setUp(self):
        logger.debug('game.GameRatingTest.setUp')
        self.client = Client()

        for i in range(1, 5):
            user = User.objects.create()
            user.username = '******' + str(i)
            user.save()

        for i in range(1, 3):
            Game.create(title='game' + str(i),
                        url='http://google.com',
                        developer=user).save()
Exemple #8
0
 def start_game(request):
     data = request.data
     new_game = Game.create(data["first_player"], data["second_player"])
     new_game.save()
     serializer_class = GameSerializer(new_game, many=False,
                                       context={'request': request})
     return Response(data=serializer_class.data, template_name=None)
Exemple #9
0
 def setUp(self):
     
     logger.debug('SortByTest.setUp')
     
     self.client = APIClient()
     self.parser = JSONParser()
     
     dev_group = Group.objects.get(name='Developer')
     ply_group = Group.objects.get(name='Player')
     
     developer = User.objects.create(username='******')
     developer.save()
     dev_group.user_set.add(developer)
     
     for i in range(4):
         user = User.objects.create(username='******'.format(i))
         user.save()
         ply_group.user_set.add(user)
     
     for i in range(4):
         game = Game.create(
             title='game{}'.format(i),
             url='http://foobar.fi',
             developer=developer,
             price=0.5*i
         )
         game.save()
         
         for user in ply_group.user_set.all():
             buy_game_for_user(user, game)
Exemple #10
0
 def setUp(self):
     
     logger.debug('DeveloperGamesTest.setUp')
     
     self.parser = JSONParser()
     self.client = APIClient()
     
     dev_group = Group.objects.get(name='Developer')
     
     for i in range(4):
         user = User.objects.create(username='******'.format(i))
         user.save()
         dev_group.user_set.add(user)
     
     for i in range(4):
         developer = User.objects.get(username='******'.format(i))
         for j in range(i):
             Game.create(
                 title='game{}x{}'.format(i, j),
                 url='http://foobar.fi',
                 developer=developer
             ).save()
 def save(self):
     game_type = self.cleaned_data['type']
     csv_file = self.cleaned_data['file']
     for line in csv_file.readlines():
         teams = line.strip().split(',')
         try:
             group = Group.objects.get(name=teams[0])
         except Group.DoesNotExist:
             group = None
         try:
             game_conf = GameConfiguration.objects.get(id=teams[1])
         except GameConfiguration.DoesNotExist:
             continue
         try:
             place = GamePlace.objects.get(id=teams[2])
         except GamePlace.DoesNotExist:
             place = None
         try:
             time = datetime.datetime(*list(map(int, teams[3:8])))
         except ValueError:
             time = None
         Game.create([Team.objects.get(id=team) for team in teams[8:]], game_type=game_type, game_conf=game_conf,
                     title=self.cleaned_data['name'], group=group, place=place, time=time)
 def create(self, request, *args, **kwargs):
     print(request.data)
     max_score = request.data['maxScore']
     players_team_a = request.data['playersTeamA']
     players_team_b = request.data['playersTeamB']
     score_a = request.data['scoreTeamA']
     score_b = request.data['scoreTeamB']
     players_team_a_ids = [player["id"] for player in players_team_a]
     players_team_b_ids = [player["id"] for player in players_team_b]
     team_a = Team.get_or_create_team(players_team_a_ids)
     team_b = Team.get_or_create_team(players_team_b_ids)
     teams = [team_a, team_b]
     game = Game.create(max_score=max_score, teams=teams)
     ScoreTeam.objects.create(team=team_a, game=game, score=score_a)
     ScoreTeam.objects.create(team=team_b, game=game, score=score_b)
     print(game)
     self.kwargs['pk'] = game.id
     return self.retrieve(request)
Exemple #13
0
def start_game(request):
    user = request.user
    qs = GameSession.objects.\
        filter(user=user,
               left=False,
               game__finished=False).\
        exclude(client_state=ClientConnectionState.LOST)
    if qs.count():
        gs = qs.all()[0]
        return {'status': 302,
                'url': reverse(game_screen, kwargs={'game_id': gs.game.id})}

    wu = WaitingUser.objects.get_or_create(user=user)[0].update()
    last_poll_guard = datetime.datetime.now() - constants.WAITING_USER_TIMEOUT

    opponents = WaitingUser.objects.\
        filter(last_poll__gt=last_poll_guard).\
        exclude(user=user).all()
    if not opponents:
        return {'status': 'polling',
                'opponents': []}

    now = datetime.datetime.now()
    join_timeout = request.session.get('game_join_timeout', None)
    if not join_timeout:
        join_timeout = request.session['game_join_timeout'] = now

    if join_timeout + constants.GAME_JOIN_WAIT_TIMEOUT > now:
        time_left = join_timeout + constants.GAME_JOIN_WAIT_TIMEOUT - now
        return {'status': 'polling',
                'timeout': time_left.seconds,
                'opponents': [op.serialize() for op in opponents]}

    game_id = get_uid()
    game = Game.create(id=game_id)
    GameSession.objects.create(game=game, user=user)
    wu.delete()
    for op in opponents:
        GameSession.objects.create(game=game, user=op.user)
        op.delete()
    return {'status': '302',
            'url': reverse(game_screen, kwargs={'game_id': game_id})}
Exemple #14
0
    def setUp(self):

        logger.debug('StatisticsTest.setUp')

        dev_group = Group.objects.get(name='Developer')
        ply_group = Group.objects.get(name='Player')

        developer = User.objects.create(username='******')
        developer.save()
        dev_group.user_set.add(developer)

        users = []

        for i in range(5):
            user = User.objects.create(username='******'.format(i))
            user.save()
            ply_group.user_set.add(user)
            users.append(user)

        games = []

        for i in range(3):
            game = Game.create(title='game{}'.format(i),
                               url='http://foobar.fi',
                               developer=developer,
                               price=(i + 0.5))
            game.save()
            games.append(game)

        for user in users[:3]:
            buy_game_for_user(user, games[0])
            buy_game_for_user(user, games[1])
            rate_game_for_user(user, games[0], 3)
            rate_game_for_user(user, games[1], 4)
        for user in users:
            buy_game_for_user(user, games[2])
            rate_game_for_user(user, games[2], 3)
Exemple #15
0
 def create_game(request):
     data = request.data
     new_game = Game.create(data["first_player"], data["second_player"])
     new_game.save()
     context_dict = GameView.get_game_context(new_game, request)
     return Response(data=context_dict, template_name=None)