File size: 1,305 Bytes
c5dbf9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fba078d
 
c5dbf9f
 
 
 
 
 
 
 
 
 
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
"""Tests for the FastAPI UI wrapper."""

from starlette.requests import Request

from openenv_bug_triage.app import index


def _request(root_path: str = "") -> Request:
    return Request(
        {
            "type": "http",
            "http_version": "1.1",
            "method": "GET",
            "scheme": "http",
            "path": "/",
            "root_path": root_path,
            "headers": [],
            "query_string": b"",
            "client": ("testclient", 50000),
            "server": ("testserver", 80),
        }
    )


def test_index_renders_ui_assets_at_root():
    response = index(_request())
    body = response.body.decode("utf-8")

    assert response.status_code == 200
    assert 'href="/ui/styles.css"' in body
    assert 'src="/ui/app.js"' in body
    assert 'window.OPENENV_BASE_PATH = ""' in body
    assert "Suggest action" in body
    assert "Baseline snapshot" in body


def test_index_renders_proxy_aware_asset_paths():
    response = index(_request("/spaces/demo/bug-triage"))
    body = response.body.decode("utf-8")

    assert response.status_code == 200
    assert 'href="/spaces/demo/bug-triage/ui/styles.css"' in body
    assert 'src="/spaces/demo/bug-triage/ui/app.js"' in body
    assert 'window.OPENENV_BASE_PATH = "/spaces/demo/bug-triage"' in body