Zion Boggan zionboggan.com ↗
56 lines · python
History for this file →
1
import pytest
2
 
3
from cti.approval import make_token
4
from cti.pipeline import run
5
from cti.web import create_app
6
 
7
 
8
@pytest.fixture
9
def app_and_bundle(base_config):
10
    result = run(base_config)
11
    app = create_app(base_config)
12
    app.config["TESTING"] = True
13
    return app, result
14
 
15
 
16
def test_dashboard_lists_bundle(app_and_bundle):
17
    app, result = app_and_bundle
18
    client = app.test_client()
19
    resp = client.get("/")
20
    assert resp.status_code == 200
21
    assert result["bundle_id"].encode() in resp.data
22
 
23
 
24
def test_review_requires_valid_token(app_and_bundle):
25
    app, _ = app_and_bundle
26
    client = app.test_client()
27
    assert client.get("/review/garbage").status_code == 403
28
 
29
 
30
def test_review_renders_for_valid_token(app_and_bundle):
31
    app, result = app_and_bundle
32
    token = make_token("test-secret", result["bundle_id"])
33
    client = app.test_client()
34
    resp = client.get(f"/review/{token}")
35
    assert resp.status_code == 200
36
    assert b"Approve and deploy" in resp.data
37
 
38
 
39
def test_approve_promotes(app_and_bundle):
40
    app, result = app_and_bundle
41
    token = make_token("test-secret", result["bundle_id"])
42
    client = app.test_client()
43
    resp = client.post(f"/approve/{token}")
44
    assert resp.status_code == 200
45
    assert b"approved" in resp.data
46
    follow = client.get(f"/review/{token}")
47
    assert b"already been approved" in follow.data
48
 
49
 
50
def test_reject_marks_bundle(app_and_bundle):
51
    app, result = app_and_bundle
52
    token = make_token("test-secret", result["bundle_id"])
53
    client = app.test_client()
54
    resp = client.post(f"/reject/{token}", data={"reason": "false positives"})
55
    assert resp.status_code == 200
56
    assert b"rejected" in resp.data