-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindwork_test.py
More file actions
59 lines (48 loc) · 2 KB
/
Copy pathfindwork_test.py
File metadata and controls
59 lines (48 loc) · 2 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
"""Test the contractor Find Work portal backend."""
import os
os.environ['DATABASE_URL'] = 'sqlite:///findwork_test.db'
if os.path.exists('findwork_test.db'):
os.remove('findwork_test.db')
from app import app, db
import aedis_world_gen as gen
with app.app_context():
db.create_all()
c = app.test_client()
def ok(label, resp):
passed = resp.status_code < 400
print(f"[{'PASS' if passed else 'FAIL'}] {label}: {resp.status_code}")
assert passed, resp.get_json()
return resp.get_json()
# Page serves
r = c.get('/findwork')
assert r.status_code == 200 and b'AEDIS' in r.data
print(f"[PASS] /findwork serves ({len(r.data)} bytes)")
# State list
states = ok("state list", c.get('/api/findwork/states'))
assert len(states['states']) == 51
print(f" {len(states['states'])} states listed")
# Opportunities for a state
wa = ok("WA opportunities", c.get('/api/findwork/WA'))
assert 6 <= wa['count'] <= 14
print(f" WA: {wa['count']} open jobs")
# Each opportunity has the contractor-relevant fields
for o in wa['opportunities']:
assert o['license_required'], "missing license requirement"
assert o['budget'] > 0
assert o['county'] and o['category']
assert 'bids_so_far' in o and 'closes_in_days' in o
print("[PASS] opportunities carry license, budget, county, bid count, deadline")
# Deterministic
a = gen.generate_open_opportunities('TX')
b = gen.generate_open_opportunities('TX')
assert [o['id'] for o in a] == [o['id'] for o in b]
print(f"[PASS] opportunity generation deterministic (TX: {len(a)} jobs)")
# License mapping is sensible (clinic -> healthcare)
found_clinic = [o for o in (gen.generate_open_opportunities(s) for s in gen.STATES) for o in o if o['category'] == 'Clinic Construction']
if found_clinic:
assert 'ealthcare' in found_clinic[0]['license_required']
print("[PASS] clinic jobs require healthcare-facility license")
# Unknown state -> 404
assert c.get('/api/findwork/ZZ').status_code == 404
print("[PASS] unknown state -> 404")
print("\nFind Work portal backend verified.")