Exemplo n.º 1
0
def make_move(request,id):
    game=get_object_or_404(Game,pk=id)
    if not game.is_users_move(request.user):
        raise PermissionDenied
    move=game.new_move()
    form=MoveForm(instance=move,data=request.POST)
    if form.is_valid():
        move.save()
        return redirect("gameplay_detail",id)
    else:
        return render(request,
                      "gameplay/game_detail.html",
                      {'game':game,'form':form})
Exemplo n.º 2
0
    def test_invalid_move(self):
        form_data = {"x": 5, "y": 7}
        form = MoveForm(data=form_data, instance=self.move)

        self.assertFalse(form.is_valid())
Exemplo n.º 3
0
    def test_valid_move(self):
        form_data = {"x": 0, "y": 1}
        form = MoveForm(data=form_data, instance=self.move)

        self.assertTrue(form.is_valid())