forked from johnny603/lux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_contributors.py
More file actions
62 lines (51 loc) · 1.79 KB
/
Copy pathtest_contributors.py
File metadata and controls
62 lines (51 loc) · 1.79 KB
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
import json
import contributors
import server
def test_load_contributors_normalizes_entries(tmp_path):
manifest = tmp_path / "contributors.json"
manifest.write_text(
json.dumps(
{
"contributors": [
{
"login": "ada",
"name": "Ada Lovelace",
"contributions": ["documentation"],
"badges": ["founding-contributor"],
},
{"name": "missing login"},
]
}
)
)
assert contributors.load_contributors(str(manifest)) == [
{
"login": "ada",
"name": "Ada Lovelace",
"contributions": ["documentation"],
"badges": ["founding-contributor"],
}
]
def test_load_contributors_handles_malformed_manifest(tmp_path):
manifest = tmp_path / "contributors.json"
manifest.write_text("not json")
assert contributors.load_contributors(str(manifest)) == []
assert contributors.load_contributors(str(tmp_path / "missing.json")) == []
def test_contributor_endpoints(monkeypatch):
entries = [
{
"login": "ada",
"name": "Ada Lovelace",
"contributions": ["documentation"],
"badges": ["founding-contributor"],
}
]
monkeypatch.setattr(server.contributors, "load_contributors", lambda: entries)
client = server.app.test_client()
response = client.get("/api/v1/contributors")
assert response.status_code == 200
assert response.get_json() == {"contributors": entries}
response = client.get("/contributors")
assert response.status_code == 200
assert b"Ada Lovelace" in response.data
assert b"founding-contributor" in response.data