コード例 #1
0
def test_room_create(client, world):
    world.trait_grants["apiuser"] = ["foobartrait", "admin"]
    world.save()

    r = client.post(
        "/api/v1/worlds/sample/rooms/",
        data={
            "name": "Forum",
            "sorting_priority": 100,
        },
        format="json",
        HTTP_AUTHORIZATION=get_token_header(world),
    )
    assert r.status_code == 403
    r = client.post(
        "/api/v1/worlds/sample/rooms/",
        data={
            "name": "Forum",
            "sorting_priority": 100,
            "module_config": [{
                "type": "unknown"
            }],
        },
        format="json",
        HTTP_AUTHORIZATION=get_token_header(world,
                                            ["admin", "api", "foobartrait"]),
    )
    assert r.status_code == 201
    assert world.rooms.last().name == "Forum"
    assert str(world.rooms.last().id) == r.data["id"]

    r = client.post(
        "/api/v1/worlds/sample/rooms/",
        format="json",
        data={
            "name": "Forum",
            "sorting_priority": 102,
            "module_config": [{
                "type": "chat.native"
            }],
        },
        HTTP_AUTHORIZATION=get_token_header(world,
                                            ["admin", "api", "foobartrait"]),
    )
    assert r.status_code == 201
    assert world.rooms.last().name == "Forum"
    assert str(world.rooms.last().id) == r.data["id"]
    assert world.rooms.last().channel
コード例 #2
0
def test_world_no_delete(client, world):
    r = client.delete(
        "/api/v1/worlds/sample/",
        {"title": "Democon"},
        HTTP_AUTHORIZATION=get_token_header(world),
    )
    assert r.status_code == 403
コード例 #3
0
def test_room_delete(client, world):
    world.trait_grants["apiuser"] = ["foobartrait", "admin"]
    world.save()
    rid = world.rooms.first().id

    r = client.delete(
        "/api/v1/worlds/sample/rooms/{}/".format(str(rid)),
        HTTP_AUTHORIZATION=get_token_header(world),
    )
    assert r.status_code == 403
    r = client.delete(
        "/api/v1/worlds/sample/rooms/{}/".format(str(rid)),
        HTTP_AUTHORIZATION=get_token_header(world,
                                            ["admin", "api", "foobartrait"]),
    )
    assert r.status_code == 204
    assert not world.rooms.filter(id=rid).exists()
コード例 #4
0
async def test_push_world_update(client, action, world):
    async with world_communicator() as c:
        r = await sync_to_async(client.get)(
            "/api/v1/worlds/sample/rooms/",
            HTTP_AUTHORIZATION=get_token_header(world),
        )
        rid = r.data["results"][0]["id"]
        await sync_to_async(client.patch)(
            "/api/v1/worlds/sample/rooms/{}/".format(str(rid)),
            format="json",
            data={
                "name": "Forum"
            },
            HTTP_AUTHORIZATION=get_token_header(world),
        )
        w = await c.receive_json_from()
        assert w[0] == "world.updated"
コード例 #5
0
def it_returns_no_repeated_questions(client):
    from collections import Counter
    from operator import itemgetter

    response = client.get('api/quizz/30', headers=get_token_header(client))
    questions = json.loads(response.get_data(as_text=True))
    repeated = len(Counter(map(itemgetter("id"), questions['quizz_questions'])))
    assert repeated == 30
コード例 #6
0
def test_world_update(client, world):
    world.trait_grants["apiuser"] = ["foobartrait"]
    world.save()

    r = client.patch(
        "/api/v1/worlds/sample/",
        {"title": "Democon"},
        HTTP_AUTHORIZATION=get_token_header(world),
    )
    assert r.status_code == 403

    r = client.patch(
        "/api/v1/worlds/sample/",
        {"title": "Democon"},
        HTTP_AUTHORIZATION=get_token_header(world,
                                            ["foobartrait", "admin", "api"]),
    )
    assert r.status_code == 200
    world.refresh_from_db()
    assert world.title == "Democon"
コード例 #7
0
def test_world_config_protect_secrets(client, world):
    world.trait_grants["apiuser"] = ["foobartrait"]
    world.save()
    r = client.get("/api/v1/worlds/sample/",
                   HTTP_AUTHORIZATION=get_token_header(world))
    assert r.status_code == 403
    r = client.get(
        "/api/v1/worlds/sample/",
        HTTP_AUTHORIZATION=get_token_header(world,
                                            ["api", "foobartrait", "admin"]),
    )
    assert r.status_code == 200
    world.roles["apiuser"] = ["world:api"]
    world.save()
    r = client.get(
        "/api/v1/worlds/sample/",
        HTTP_AUTHORIZATION=get_token_header(world,
                                            ["api", "admin", "foobartrait"]),
    )
    assert r.status_code == 403
コード例 #8
0
def test_world_config(client, world):
    r = client.get("/api/v1/worlds/sample/",
                   HTTP_AUTHORIZATION=get_token_header(world))
    assert r.status_code == 200
    assert r.data == {
        "id": "sample",
        "title": "Unsere tolle Online-Konferenz",
        "config": world.config,
        "roles": world.roles,
        "trait_grants": world.trait_grants,
        "domain": "localhost",
    }
コード例 #9
0
def test_room_update(client, world):
    world.trait_grants["apiuser"] = ["foobartrait", "admin"]
    world.save()
    rid = world.rooms.first().id

    r = client.patch(
        "/api/v1/worlds/sample/rooms/{}/".format(str(rid)),
        dataß={"name": "Forum"},
        format="json",
        HTTP_AUTHORIZATION=get_token_header(world),
    )
    assert r.status_code == 403
    r = client.patch(
        "/api/v1/worlds/sample/rooms/{}/".format(str(rid)),
        data={
            "name": "Forum",
        },
        format="json",
        HTTP_AUTHORIZATION=get_token_header(world,
                                            ["admin", "api", "foobartrait"]),
    )
    assert r.status_code == 200
    assert world.rooms.get(id=rid).name == "Forum"
コード例 #10
0
def it_correct_questions(client):
    answer1 = dict(question_id=30, answer=3)
    answer2 = dict(question_id=45, answer=1)
    answer_list = list()
    answer_list.append(answer1)
    answer_list.append(answer2)
    answers = dict(answers=answer_list)

    response = client.post('/api/quizz/user/1', json=dict(answers), headers=get_token_header(client))
    answers_from_api = json.loads(response.get_data(as_text=True))
    correct_answers = answers_from_api['correct_answers']
    for correct_answer in correct_answers:
        if (correct_answer['question_id']) == 30:
            assert correct_answer['correct']
        else:
            assert (not correct_answer['correct'])
コード例 #11
0
def test_room_detail(client, world):
    r = client.get(
        "/api/v1/worlds/sample/rooms/{}/".format(str(world.rooms.first().id)),
        HTTP_AUTHORIZATION=get_token_header(world),
    )
    assert r.status_code == 200
    assert r.data == {
        "id":
        str(world.rooms.first().id),
        "deleted":
        False,
        "trait_grants": {
            "viewer": [],
            "participant": []
        },
        "name":
        "About",
        "module_config": [{
            "type": "page.landing",
            "config": {
                "header_background_color":
                "#673ab7",
                "header_image":
                "/venueless-logo-full-white.svg",
                "content":
                "# Welcome to this example event!\n\nYou might notice that the dates for the current "
                "sessions are not actually your current time and that time does not progress. That's "
                "because we froze time – only in this demo of course – with the power of programming!"
                "\n\nHave a look around!",
            },
        }],
        "description":
        "UNUSED",
        "pretalx_id":
        0,
        "sorting_priority":
        0,
        "schedule_data":
        None,
    }
コード例 #12
0
def it_returns_the_correct_number_of_questions(client):
    header = get_token_header(client)
    response = client.get('api/quizz/10', headers=header)
    questions = json.loads(response.get_data(as_text=True))
    assert len(questions['quizz_questions']) == 10