File size: 2,530 Bytes
2756f0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""D6: GET /v1/catalog/metrics."""


from tests import factories


async def headers() -> dict:
    return (await factories.make_account())["headers"]


async def test_hitting_catalog(client):
    response = await client.get("/v1/catalog/metrics?mode=h", headers=await headers())
    assert response.status_code == 200
    body = response.json()
    assert body["groups"] == [
        {"group": "balance_load", "display_name": "Balance and Load"},
        {"group": "stride", "display_name": "Stride"},
        {"group": "power_move", "display_name": "Power Move"},
        {"group": "contact_follow_through", "display_name": "Contact and Follow-Through"},
    ]
    assert [m["metric_id"] for m in body["metrics"]] == [
        "hip_shoulder_separation_at_foot_down", "stride_relative_length", "hip_shoulder_separation_at_contact"]
    assert body["metrics"][1] == {"metric_id": "stride_relative_length", "display_name": "Stride Length",
                                  "group": "stride", "unit": "cm",
                                  "what_it_means": "How far your front foot steps forward."}
    drill = next(d for d in body["drills"] if d["drill_id"] == "hit_13")
    assert drill == {"drill_id": "hit_13", "name": "Front Shoulder In Tee",
                     "how": "Set the tee on the outer half. Keep your front shoulder pointed at the pitcher until your "
                            "hips have turned, then swing.", "cue": "Shoulder in.", "reps": "3x8"}
    assert all(d["drill_id"].startswith("hit_") for d in body["drills"])


async def test_default_mode_is_hitting(client):
    response = await client.get("/v1/catalog/metrics", headers=await headers())
    assert response.status_code == 200 and len(response.json()["metrics"]) == 3


async def test_pitching_catalog(client):
    response = await client.get("/v1/catalog/metrics?mode=p", headers=await headers())
    assert response.status_code == 200
    body = response.json()
    assert body["metrics"] == [] and body["groups"] == []
    assert body["drills"] and all(d["drill_id"].startswith("pit_") for d in body["drills"])


async def test_invalid_mode(client):
    response = await client.get("/v1/catalog/metrics?mode=x", headers=await headers())
    assert response.status_code == 400
    assert response.json()["error"]["code"] == "VALIDATION"


async def test_unauthenticated(client):
    response = await client.get("/v1/catalog/metrics?mode=h")
    assert response.status_code == 401
    assert response.json()["error"]["code"] == "UNAUTHENTICATED"