Beispiel #1
0
def aimmo_home(request):
    aimmo_sessions = []
    aimmo_sheets = []

    get_session_pdfs("Kurono_session_", aimmo_sessions)
    get_resource_sheets_pdfs(aimmo_sessions, "Kurono_S", aimmo_sheets)

    playable_games = request.user.playable_games.all()

    if request.method == "POST":
        create_game_form = AddGameForm(playable_games, data=request.POST)
        if create_game_form.is_valid():
            return save_form(request, create_game_form)

    else:
        create_game_form = AddGameForm(playable_games)

    return render(
        request,
        "portal/aimmo_home.html",
        {
            "create_game_form": create_game_form,
            "aimmo_sessions": aimmo_sessions,
            "aimmo_sheets": aimmo_sheets,
        },
    )
Beispiel #2
0
def test_form_with_non_existing_worksheet(class1: Class):
    form = AddGameForm(
        Class.objects.all(),
        data={
            "name": "test1",
            "game_class": class1.id,
            "worksheet": 12345
        },
    )
    assert not form.is_valid()
Beispiel #3
0
def test_form_with_non_existing_class(worksheet: Worksheet):
    form = AddGameForm(
        Class.objects.all(),
        data={
            "name": "test1",
            "game_class": 12345,
            "worksheet": worksheet.id
        },
    )
    assert not form.is_valid()
Beispiel #4
0
def test_create_game(class1: Class, worksheet: Worksheet):
    form = AddGameForm(
        Class.objects.all(),
        data={
            "name": "test1",
            "game_class": class1.id,
            "worksheet": worksheet.id
        },
    )
    assert form.is_valid()

    game = form.save()
    assert game.name == "test1"
    assert game.game_class == class1
Beispiel #5
0
def test_cannot_add_game_for_classes_not_given_to_form(class1: Class,
                                                       worksheet: Worksheet,
                                                       teacher1_email: str):
    # Make query set for form
    class_query_set = Class.objects.filter(id=class1.id)

    # Create class not in the query set
    klass, _, _ = create_class_directly(teacher1_email)

    form = AddGameForm(
        class_query_set,
        data={
            "name": "test1",
            "game_class": klass.id,
            "worksheet": worksheet.id
        },
    )

    assert not form.is_valid()
Beispiel #6
0
 def test_adding_a_game_creates_an_avatar(self):
     client = self.login()
     worksheet = Worksheet.objects.create(name="test", starter_code="test")
     worksheet.save()
     game: Game = create_game(
         self.user,
         AddGameForm(
             Class.objects.all(),
             data={
                 "name": "new game",
                 "game_class": self.klass.id,
                 "worksheet": worksheet.id,
             },
         ),
     )
     game = models.Game.objects.get(pk=2)
     avatar = game.avatar_set.get(owner=client.session["_auth_user_id"])
     assert avatar is not None
Beispiel #7
0
def test_cannot_create_duplicate_game(class1: Class, worksheet: Worksheet):
    # Create first game
    form = AddGameForm(
        Class.objects.all(),
        data={
            "name": "test1",
            "game_class": class1.id,
            "worksheet": worksheet.id
        },
    )
    _ = form.save()

    # Create second game with the same class and worksheet
    form = AddGameForm(
        Class.objects.all(),
        data={
            "name": "test2",
            "game_class": class1.id,
            "worksheet": worksheet.id
        },
    )
    with pytest.raises(ValidationError) as excinfo:
        _ = form.save()
        assert excinfo.value == "Game with this Class and Worksheet already exists."