-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrilldown_test.py
More file actions
119 lines (100 loc) · 5.41 KB
/
Copy pathdrilldown_test.py
File metadata and controls
119 lines (100 loc) · 5.41 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""Test the country drill-down (US + China) backend."""
import os
os.environ['DATABASE_URL'] = 'sqlite:///drilldown_test.db'
if os.path.exists('drilldown_test.db'):
os.remove('drilldown_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()
def check(label, cond):
print(f"[{'PASS' if cond else 'FAIL'}] {label}")
assert cond
# World view: ALL countries clickable now; 15 are 'built', rest are templates
world_v = ok("world view", c.get('/api/portal/world'))
all_clickable = all(c_.get('clickable') for c_ in world_v['countries'])
built = [c_['code'] for c_ in world_v['countries'] if c_.get('built')]
check("all countries clickable", all_clickable)
assert len(built) >= 190, f"expected nearly all built, got {len(built)}"
assert 'US' in built and 'CN' in built, "US and CN must be built"
assert 'CA' in built, "Canada should be built out"
print(f" {len(built)} of {len(world_v['countries'])} countries built out")
print(f" {len(world_v['countries'])} countries, all clickable; {len(built)} built out")
# China is present in the roster
assert any(c_['code'] == 'CN' for c_ in world_v['countries']), "China missing"
# US country summary + regions
us = ok("US country summary", c.get('/api/portal/country/US'))
assert us['region_label'] == 'State'
assert len(us['regions']) == 51, f"expected 51 US regions, got {len(us['regions'])}"
print(f" US: {us['summary']['job_count']} jobs across {len(us['regions'])} states")
# China country summary + provinces
cn = ok("China country summary", c.get('/api/portal/country/CN'))
assert cn['region_label'] == 'Province'
assert len(cn['regions']) == len(gen.CN_PROVINCES)
print(f" China: {cn['summary']['job_count']} jobs across {len(cn['regions'])} provinces")
# China province ledger populated
prov_code = cn['regions'][0]['code']
prov = ok(f"China province ledger ({prov_code})", c.get(f'/api/portal/country/CN/region/{prov_code}'))
assert 15 <= prov['summary']['job_count'] <= 40
print(f" {prov['region']}: {prov['summary']['job_count']} jobs")
# China generated job detail is recoverable (the CN-XX-GEN-#### id format)
sample = prov['jobs'][0]['id']
detail = ok(f"China job detail ({sample})", c.get(f'/api/portal/job/{sample}'))
assert detail['id'] == sample
assert 'is_scam' not in detail, "is_scam leaked!"
print(f" recovered detail for {sample}: {detail['title']}")
# US state drill-down still works via the new country endpoint
wa = ok("US WA via country endpoint", c.get('/api/portal/country/US/region/WA'))
wa_ids = [j['id'] for j in wa['jobs']]
assert 'WA-SEA-0001' in wa_ids, "hand-authored WA job missing from country-region view"
print(f" WA via country endpoint includes seeded jobs ({wa['summary']['job_count']})")
# Several of the new drill-down countries work end to end
for ccode in ['IN', 'BR', 'NG', 'JP', 'KE', 'DE']:
cv = ok(f"{ccode} country summary", c.get(f'/api/portal/country/{ccode}'))
assert len(cv['regions']) >= 4
rcode = cv['regions'][0]['code']
rv = ok(f"{ccode} region {rcode} ledger", c.get(f'/api/portal/country/{ccode}/region/{rcode}'))
assert rv['summary']['job_count'] >= 15
# recover a generated job's detail
sample = rv['jobs'][0]['id']
det = c.get(f'/api/portal/job/{sample}').get_json()
assert det.get('id') == sample, f"could not recover {sample}"
print("[PASS] new drill-down countries (IN, BR, NG, JP, KE, DE) work + job detail recovers")
# Every roster country is now built out - there are no template countries left.
# Verify a sampling of countries across batches all return real region data.
for ccode in ['IS', 'NZ', 'SG', 'JM', 'TZ', 'CI', 'CH', 'FI']:
cv = c.get(f'/api/portal/country/{ccode}')
check(f"{ccode} returns built country data", cv.status_code == 200)
cvd = cv.get_json()
check(f"{ccode} is built (not a template)", cvd.get('built') is True and not cvd.get('template'))
assert len(cvd['regions']) >= 1
# A truly unknown code still 404s
check("unknown country code -> 404", c.get('/api/portal/country/ZZ').status_code == 404)
# The three template pages serve
for path in ['/templates/job', '/templates/bid', '/templates/research']:
r = c.get(path)
check(f"{path} serves", r.status_code == 200 and b'template' in r.data.lower())
# Flag reasons: every flagged job carries a reason + severity
cases = ok("cases endpoint", c.get('/api/portal/cases'))
assert 'serious_count' in cases and 'minor_count' in cases
for cj in cases['cases']:
assert cj.get('flag_reason'), f"flagged job {cj['id']} has no reason"
assert cj.get('flag_severity') in ('minor', 'serious')
# banned companies only from serious cases, and capped (rare)
assert len(cases['banned']) <= 6
for b in cases['banned']:
assert b['reason'], "banned company missing reason"
print(f"[PASS] flags carry reasons; {cases['serious_count']} serious / {cases['minor_count']} minor; "
f"{len(cases['banned'])} banned")
# Determinism: China province generates same jobs twice
a = gen.generate_region_jobs('CN-GD', gen.CN_PROVINCES)
b = gen.generate_region_jobs('CN-GD', gen.CN_PROVINCES)
assert [j['id'] for j in a] == [j['id'] for j in b]
print(f"[PASS] China province generation deterministic ({len(a)} jobs)")
print("\nCountry drill-down (15 countries) + flag reasons verified.")