11import unittest
2- from webapp .app import app , is_remote
2+ from webapp .app import app , build_job_application_questions , is_remote
33from unittest .mock import MagicMock , patch
44from webapp .app import job_details
55
66
77class TestIsRemote (unittest .TestCase ):
88 def test_is_remote (self ):
99 self .assertTrue (is_remote ({"location" : None }))
10- self .assertTrue (is_remote ({"location" : {"name" : None }}))
11- self .assertTrue (is_remote ({"location" : {"name" : "Home Based - EMEA" }}))
12- self .assertFalse (is_remote ({"location" : {"name" : "Paris, France" }}))
10+ self .assertTrue (is_remote ({"location" : "Home Based - EMEA" }))
11+ self .assertFalse (is_remote ({"location" : "Paris, France" }))
12+
13+
14+ class TestJobApplicationQuestions (unittest .TestCase ):
15+ def test_builds_form_model_from_v3_questions (self ):
16+ questions = [
17+ {
18+ "answer_type" : "short_text" ,
19+ "description" : None ,
20+ "label" : "First name" ,
21+ "name" : "first_name" ,
22+ "private" : False ,
23+ "required" : True ,
24+ },
25+ {
26+ "answer_type" : "short_text" ,
27+ "description" : "Include the country code" ,
28+ "label" : "Phone Number" ,
29+ "name" : "phone_number" ,
30+ "private" : True ,
31+ "required" : False ,
32+ },
33+ {
34+ "answer_type" : "boolean" ,
35+ "description" : None ,
36+ "label" : "Can you travel?" ,
37+ "name" : "question_1" ,
38+ "options" : [],
39+ "private" : False ,
40+ "required" : True ,
41+ },
42+ {
43+ "answer_type" : "multi_select" ,
44+ "description" : None ,
45+ "label" : "Regions" ,
46+ "name" : "question_2" ,
47+ "options" : [
48+ {"id" : 10 , "label" : "Americas" },
49+ {"id" : 20 , "label" : "EMEA" },
50+ ],
51+ "private" : False ,
52+ "required" : False ,
53+ },
54+ {
55+ "answer_type" : "hidden" ,
56+ "label" : "Internal value" ,
57+ "name" : "internal_value" ,
58+ },
59+ ]
60+
61+ result = build_job_application_questions (questions )
62+
63+ self .assertEqual (
64+ [question ["submission_name" ] for question in result ],
65+ ["first_name" , "phone" , "question_1" , "question_2[]" ],
66+ )
67+ self .assertEqual (result [1 ]["label" ], "Phone" )
68+ self .assertTrue (result [1 ]["private" ])
69+ self .assertEqual (
70+ result [2 ]["options" ],
71+ [
72+ {"value" : 0 , "label" : "No" },
73+ {"value" : 1 , "label" : "Yes" },
74+ ],
75+ )
76+ self .assertTrue (result [3 ]["multiple" ])
77+ self .assertEqual (
78+ result [3 ]["options" ],
79+ [
80+ {"value" : 10 , "label" : "Americas" },
81+ {"value" : 20 , "label" : "EMEA" },
82+ ],
83+ )
84+
85+ def test_rejects_unknown_v3_question_type (self ):
86+ with self .assertRaisesRegex (ValueError , "unsupported Harvest V3" ):
87+ build_job_application_questions (
88+ [
89+ {
90+ "answer_type" : "future_type" ,
91+ "label" : "Future question" ,
92+ "name" : "question_3" ,
93+ }
94+ ]
95+ )
96+
97+ def test_job_template_renders_form_model_and_omits_missing_date (self ):
98+ job = {
99+ "active" : True ,
100+ "first_published_at" : None ,
101+ "id" : 1234 ,
102+ "live" : True ,
103+ "questions" : [
104+ {
105+ "answer_type" : "multi_select" ,
106+ "description" : None ,
107+ "label" : "Regions" ,
108+ "name" : "question_2" ,
109+ "options" : [
110+ {"id" : 10 , "label" : "Americas" },
111+ {"id" : 20 , "label" : "EMEA" },
112+ ],
113+ "private" : True ,
114+ "required" : True ,
115+ }
116+ ],
117+ "skills" : [],
118+ "title" : "Test role" ,
119+ }
120+ harvest = MagicMock ()
121+ harvest .get_job_post .return_value = job
122+ greenhouse = MagicMock ()
123+ greenhouse .get_vacancy .return_value = MagicMock (
124+ content = "<p>Job content</p>" ,
125+ location = "Home based - Worldwide" ,
126+ )
127+
128+ with app .test_request_context ("/careers/1234/test-role" ):
129+ response = job_details (MagicMock (), greenhouse , harvest , "1234" )
130+ rendered = response .get_data (as_text = True )
131+
132+ self .assertIn ('name="question_2[]"' , rendered )
133+ self .assertIn ('<option value="10">Americas</option>' , rendered )
134+ self .assertIn ('<option value="20">EMEA</option>' , rendered )
135+ self .assertNotIn ('"datePosted"' , rendered )
13136
14137
15138class TestCacheControlHeaders (unittest .TestCase ):
@@ -99,43 +222,37 @@ def test_multi_location_string_overrides_harvest_location(self):
99222 harvest_job = {
100223 "active" : True ,
101224 "live" : True ,
102- "location" : { "name" : " Home based - EMEA"} ,
225+ "location" : " Home based - EMEA" ,
103226 }
104227 captured = self ._run_job_details (
105228 harvest_job ,
106229 "Home Based - Americas; Home based - EMEA" ,
107230 )
108231
109232 self .assertEqual (
110- captured ["job" ]["location" ][ "name" ] ,
233+ captured ["job" ]["location" ],
111234 "Home Based - Americas; Home based - EMEA" ,
112235 )
113236
114237 def test_single_location_is_overridden_with_board_value (self ):
115238 harvest_job = {
116239 "active" : True ,
117240 "live" : True ,
118- "location" : { "name" : " Home based - EMEA"} ,
241+ "location" : " Home based - EMEA" ,
119242 }
120243 captured = self ._run_job_details (harvest_job , "Home Based - Americas" )
121244
122- self .assertEqual (
123- captured ["job" ]["location" ]["name" ],
124- "Home Based - Americas" ,
125- )
245+ self .assertEqual (captured ["job" ]["location" ], "Home Based - Americas" )
126246
127- def test_missing_board_location_keeps_harvest_location (self ):
247+ def test_missing_board_location_is_preserved_as_unknown (self ):
128248 harvest_job = {
129249 "active" : True ,
130250 "live" : True ,
131- "location" : {"name" : "Home based - EMEA" },
132251 }
133252 captured = self ._run_job_details (harvest_job , None )
134253
135- self .assertEqual (
136- captured ["job" ]["location" ]["name" ],
137- "Home based - EMEA" ,
138- )
254+ self .assertIsNone (captured ["job" ]["location" ])
255+ self .assertTrue (captured ["job" ]["is_remote" ])
139256
140257 def test_missing_harvest_location_does_not_error (self ):
141258 harvest_job = {
@@ -148,4 +265,7 @@ def test_missing_harvest_location_does_not_error(self):
148265 "Home Based - Americas; Home based - EMEA" ,
149266 )
150267
151- self .assertIsNone (captured ["job" ]["location" ])
268+ self .assertEqual (
269+ captured ["job" ]["location" ],
270+ "Home Based - Americas; Home based - EMEA" ,
271+ )
0 commit comments