def test_user_cannot_join_an_archived_game_they_created(self): user_middleware = GamePlayerMiddleware(self.david.username) game_creator_middleware = GameCreatorMiddleware(self.david.username) game_creator_middleware.stop_game("9XMQ-FXYJ") self.assertFalse( user_middleware.can_join_game("9XMQ-FXYJ"), "ERROR! User joined an archived game that they have created!")
def test_user_cannot_join_a_game_with_invalid_code_with_invalid_format( self): user_middleware = GamePlayerMiddleware(self.david.username) self.assertFalse( user_middleware.can_join_game("QWERTYUIOP-1234567"), "ERROR! User joined a game using a valid code with invalid format!" )
def post(self, request, *args, **kwargs): player = GamePlayerMiddleware(request.user.username) form = self.form(request.POST) # Inputting new game code to start playing a game if 'code' in request.POST.keys() and request.POST['code'] != '': game = _GameMiddleware(request.POST['code']) if not game.game: return render(request, self.template_name, context={ 'recent_game_ranks': player.rank_in_most_recent_games(10), 'game_error': "Oops, incorrect code!" }) else: if player.can_join_game(request.POST['code']): player.join_game(request.POST['code']) return HttpResponseRedirect("/game/leaderboard/" + request.POST['code']) else: return render(request, self.template_name, context={ 'recent_game_ranks': player.rank_in_most_recent_games(10), 'game_error': "Oops, incorrect code!" }) # Inputing a game name to start creating a new game if form.is_valid(): game = form.save() game_creator = GameCreator.objects.create(game=game, creator=request.user) return redirect('create_game', game.code) return render(request, self.template_name, {'form': form})
def test_user_cannot_join_a_not_published_game_of_another_creator(self): user_middleware = GamePlayerMiddleware(self.david.username) self.assertFalse( user_middleware.can_join_game("4Y1H-M4NX"), "ERROR! User can join a game that has not been published yet!")
def test_user_cannot_join_an_unpublished_they_created(self): user_middleware = GamePlayerMiddleware(self.david.username) self.assertFalse( user_middleware.can_join_game("13T2-JFRN"), "ERROR! User joined an archived game that they have created!")
def test_user_cannot_join_a_live_game_they_created(self): user_middleware = GamePlayerMiddleware(self.david.username) self.assertFalse( user_middleware.can_join_game("9XMQ-FXYJ"), "ERROR! User joined a live game that they have created!")
def test_user_cannot_join_archived_game_of_another_creator(self): user_middleware = GamePlayerMiddleware(self.david.username) game_creator_middleware = GameCreatorMiddleware(self.mustafa.username) game_creator_middleware.stop_game("RIPM-VKBR") self.assertFalse(user_middleware.can_join_game("RIPM-VKBR"), "ERROR! User joined an archived game!")
def test_user_cannot_join_an_already_joined_game(self): user_middleware = GamePlayerMiddleware(self.david.username) self.assertFalse(user_middleware.can_join_game("WS30-8FA3"), "ERROR! User joined a game they are already in!")
def test_user_can_join_live_game_they_are_not_in_of_another_creator(self): user_middleware = GamePlayerMiddleware(self.david.username) self.assertTrue( user_middleware.can_join_game("RIPM-VKBR"), "ERROR! User cannot join a live game they are not in!")