返回 last30days-skill
test_jobs_teams.py
根目录 / tests / test_jobs_teams.py
1 """Named teams read from a board's own titles (lib/jobs_teams.py), the digest
2 slots they take, and how the digest shows them."""
3
4 from __future__ import annotations
5
6 from lib import jobs_digest, jobs_teams, render
7
8 WINDOW_START = "2026-10-17"
9
10
11 def _role(title, date="2026-11-10", location="Seattle, WA", dated=True, index=[0]):
12 index[0] += 1
13 return {
14 "title": title, "department": "", "location": location,
15 "date": date, "posted_date_true": dated,
16 "url": f"https://jobs.example.com/{index[0]}",
17 }
18
19
20 def _board():
21 # A large board: hundreds of store roles, a long-running AWS team, and a
22 # new team whose name no other title carries.
23 rows = [_role(f"Store Associate, Store {n}", date="2026-09-01") for n in range(200)]
24 rows += [_role(f"Software Engineer, AWS Billing {n}", date="2026-06-01") for n in range(5)]
25 rows += [_role(f"Area Manager, Seattle", date="2026-11-01") for _ in range(4)]
26 rows += [
27 _role("Applied Scientist, Fauna"),
28 _role("Robotics Software Engineer, Fauna", date="2026-11-12"),
29 _role("Marketing Manager, Fauna Robotics", date="2026-11-11"),
30 _role("Hardware Engineer, Fauna", date="2026-10-20"),
31 ]
32 rows += [
33 _role("Head of Alternate Payment Methods, Example Agentic Payments", date="2026-11-14"),
34 _role("Administrative Assistant to the GM, Agentic Payments Ops", date="2026-11-15"),
35 ]
36 return rows
37
38
39 def test_a_new_team_named_only_in_its_own_titles_ranks_first_and_stores_and_places_are_not_teams():
40 result = jobs_teams.named_teams(_board(), company="Example", window_start=WINDOW_START)
41
42 names = [team["name"] for team in result["teams"]]
43 assert names[0] == "fauna"
44 assert result["teams"][0] == {"name": "fauna", "roles": 4, "new": 4}
45 # "fauna robotics" is the same team, not a second one.
46 assert "fauna robotics" not in names
47 assert not any("store" in name or name == "seattle" for name in names)
48 assert result["team_items"][0]["title"] == "Robotics Software Engineer, Fauna"
49
50
51 def test_a_head_of_a_team_no_other_title_names_is_a_lead_and_an_assistant_is_not():
52 result = jobs_teams.named_teams(_board(), company="Example", window_start=WINDOW_START)
53
54 leads = [row["title"] for row in result["lead_items"]]
55 assert "Head of Alternate Payment Methods, Example Agentic Payments" in leads
56 assert not any("Assistant" in title for title in leads)
57
58
59 def test_an_undated_board_still_names_its_teams_and_leads_without_counting_new_roles():
60 rows = [dict(row, posted_date_true=False) for row in _board()]
61 result = jobs_teams.named_teams(rows, company="Example", window_start=WINDOW_START)
62
63 assert result["teams"][0] == {"name": "fauna", "roles": 4, "new": None}
64 assert result["lead_items"]
65
66
67 def test_named_team_roles_and_leads_take_digest_slots_and_are_tagged():
68 rows = _board()
69 teams = jobs_teams.named_teams(rows, company="Example", window_start=WINDOW_START)
70 selected = jobs_digest.select_roles(rows, open_roles=len(rows), teams=teams, limit=5)
71 digest = jobs_digest.build_digest(rows, selected)
72
73 tagged = {entry["title"]: entry for entry in digest["roles"]}
74 lead = tagged["Head of Alternate Payment Methods, Example Agentic Payments"]
75 assert lead["team_lead"] is True
76 assert tagged["Robotics Software Engineer, Fauna"]["team"] == {"name": "fauna", "roles": 4}
77
78
79 def test_the_named_teams_line_shows_counts_and_new_roles_only_when_dated():
80 line = render._named_teams_line([
81 {"name": "fauna", "roles": 17, "new": 16},
82 {"name": "public sector", "roles": 40, "new": None},
83 ])
84 assert line == (
85 "- Named teams (team names repeated across this board's titles): "
86 "fauna (17 roles, 16 new); public sector (40 roles)."
87 )
88 assert render._named_teams_line([]) == ""
89 assert render._named_teams_line(None) == ""
90
91
92 def test_one_role_posted_in_three_cities_is_one_role_not_a_team():
93 rows = _board() + [
94 _role("Program Manager, Lonely Team", location=city) for city in ("Austin, TX", "Boston, MA", "Denver, CO")
95 ]
96 result = jobs_teams.named_teams(rows, company="Example", window_start=WINDOW_START)
97
98 assert "lonely team" not in [team["name"] for team in result["teams"]]
99
99 lines PYTHON