aboutsummaryrefslogtreecommitdiff
path: root/tests/http/test_preview.py
blob: 467c63ca176b6a814b22d8e7250d2c8b852c1dfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# There are two types of "preview" - one is where we navigate direclty
# to it and one is where we redirect possibly

import pytest
from httpx import AsyncClient
from jb.models.hit import Hit
from jb.models.assignment import AssignmentStub


class TestPreview:

    @pytest.mark.anyio
    async def test_preview_direct(self, httpxclient: AsyncClient):
        client = httpxclient
        res = await client.get("/preview/")

        assert res.status_code == 200
        assert res.headers["content-type"] == "text/html; charset=utf-8"
        assert res.num_bytes_downloaded == 507

        assert "James Billings loves you." in res.text
        assert "https://cdn.jamesbillings67.com/james-has-style.css" in res.text
        assert "https://cdn.jamesbillings67.com/james-billings.js" in res.text

    @pytest.mark.anyio
    async def test_preview_redirect_from_work_random_str(
        self, httpxclient: AsyncClient, amt_hit_id: str, amt_assignment_id: str
    ):
        client = httpxclient

        """
        The redirect occurs regardless of any parameter validation. This is
        because the query params will be used for record lookup on the work
        page itself.
        """

        params = {
            "workerId": None,
            "assignmentId": amt_assignment_id,
            "hitId": amt_hit_id,
        }
        res = await client.get("/work/", params=params)

        assert res.status_code == 302
        assert "/preview/" in res.headers["location"]

    @pytest.mark.anyio
    async def test_preview_redirect_from_work_records(
        self,
        httpxclient: AsyncClient,
        hit_record: Hit,
        assignment_stub_record: AssignmentStub,
    ):
        client = httpxclient

        """
        The redirect occurs regardless of any parameter validation. This is
        because the query params will be used for record lookup on the work
        page itself.
        """

        params = {
            "workerId": None,
            "assignmentId": assignment_stub_record.amt_assignment_id,
            "hitId": hit_record.amt_hit_id,
        }
        res = await client.get("/work/", params=params)

        assert res.status_code == 302
        assert "/preview/" in res.headers["location"]