forked from feder-cr/Jobs_Applier_AI_Agent_AIHawk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_job_application_profile.py
185 lines (175 loc) · 6.29 KB
/
test_job_application_profile.py
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import pytest
from src.job_application_profile import JobApplicationProfile
@pytest.fixture
def valid_yaml():
"""Valid YAML string for initializing JobApplicationProfile."""
return """
self_identification:
gender: Male
pronouns: He/Him
veteran: No
disability: No
ethnicity: Asian
legal_authorization:
eu_work_authorization: "Yes"
us_work_authorization: "Yes"
requires_us_visa: "No"
requires_us_sponsorship: "Yes"
requires_eu_visa: "No"
legally_allowed_to_work_in_eu: "Yes"
legally_allowed_to_work_in_us: "Yes"
requires_eu_sponsorship: "No"
canada_work_authorization: "Yes"
requires_canada_visa: "No"
legally_allowed_to_work_in_canada: "Yes"
requires_canada_sponsorship: "No"
uk_work_authorization: "Yes"
requires_uk_visa: "No"
legally_allowed_to_work_in_uk: "Yes"
requires_uk_sponsorship: "No"
work_preferences:
remote_work: "Yes"
in_person_work: "No"
open_to_relocation: "Yes"
willing_to_complete_assessments: "Yes"
willing_to_undergo_drug_tests: "Yes"
willing_to_undergo_background_checks: "Yes"
availability:
notice_period: "2 weeks"
salary_expectations:
salary_range_usd: "80000-120000"
"""
@pytest.fixture
def missing_field_yaml():
"""YAML string missing a required field (self_identification)."""
return """
legal_authorization:
eu_work_authorization: "Yes"
us_work_authorization: "Yes"
requires_us_visa: "No"
requires_us_sponsorship: "Yes"
requires_eu_visa: "No"
legally_allowed_to_work_in_eu: "Yes"
legally_allowed_to_work_in_us: "Yes"
requires_eu_sponsorship: "No"
canada_work_authorization: "Yes"
requires_canada_visa: "No"
legally_allowed_to_work_in_canada: "Yes"
requires_canada_sponsorship: "No"
uk_work_authorization: "Yes"
requires_uk_visa: "No"
legally_allowed_to_work_in_uk: "Yes"
requires_uk_sponsorship: "No"
work_preferences:
remote_work: "Yes"
in_person_work: "No"
open_to_relocation: "Yes"
willing_to_complete_assessments: "Yes"
willing_to_undergo_drug_tests: "Yes"
willing_to_undergo_background_checks: "Yes"
availability:
notice_period: "2 weeks"
salary_expectations:
salary_range_usd: "80000-120000"
"""
@pytest.fixture
def invalid_type_yaml():
"""YAML string with an invalid type for a field."""
return """
self_identification:
gender: Male
pronouns: He/Him
veteran: No
disability: No
ethnicity: Asian
legal_authorization:
eu_work_authorization: "Yes"
us_work_authorization: "Yes"
requires_us_visa: "No"
requires_us_sponsorship: "Yes"
requires_eu_visa: "No"
legally_allowed_to_work_in_eu: "Yes"
legally_allowed_to_work_in_us: "Yes"
requires_eu_sponsorship: "No"
canada_work_authorization: "Yes"
requires_canada_visa: "No"
legally_allowed_to_work_in_canada: "Yes"
requires_canada_sponsorship: "No"
uk_work_authorization: "Yes"
requires_uk_visa: "No"
legally_allowed_to_work_in_uk: "Yes"
requires_uk_sponsorship: "No"
work_preferences:
remote_work: 12345 # Invalid type, expecting a string
in_person_work: "No"
open_to_relocation: "Yes"
willing_to_complete_assessments: "Yes"
willing_to_undergo_drug_tests: "Yes"
willing_to_undergo_background_checks: "Yes"
availability:
notice_period: "2 weeks"
salary_expectations:
salary_range_usd: "80000-120000"
"""
def test_initialize_with_valid_yaml(valid_yaml):
"""Test initializing JobApplicationProfile with valid YAML."""
profile = JobApplicationProfile(valid_yaml)
# Check that the profile fields are correctly initialized
assert profile.self_identification.gender == "Male"
assert profile.self_identification.pronouns == "He/Him"
assert profile.legal_authorization.eu_work_authorization == "Yes"
assert profile.work_preferences.remote_work == "Yes"
assert profile.availability.notice_period == "2 weeks"
assert profile.salary_expectations.salary_range_usd == "80000-120000"
def test_initialize_with_missing_field(missing_field_yaml):
"""Test initializing JobApplicationProfile with missing required fields."""
with pytest.raises(KeyError) as excinfo:
JobApplicationProfile(missing_field_yaml)
assert "self_identification" in str(excinfo.value)
def test_initialize_with_invalid_yaml():
"""Test initializing JobApplicationProfile with invalid YAML."""
invalid_yaml_str = """
self_identification:
gender: Male
pronouns: He/Him
veteran: No
disability: No
ethnicity: Asian
legal_authorization:
eu_work_authorization: "Yes"
us_work_authorization: "Yes"
requires_us_visa: "No"
requires_us_sponsorship: "Yes"
requires_eu_visa: "No"
legally_allowed_to_work_in_eu: "Yes"
legally_allowed_to_work_in_us: "Yes"
requires_eu_sponsorship: "No"
canada_work_authorization: "Yes"
requires_canada_visa: "No"
legally_allowed_to_work_in_canada: "Yes"
requires_canada_sponsorship: "No"
uk_work_authorization: "Yes"
requires_uk_visa: "No"
legally_allowed_to_work_in_uk: "Yes"
requires_uk_sponsorship: "No"
work_preferences:
remote_work: "Yes"
in_person_work: "No"
availability:
notice_period: "2 weeks"
salary_expectations:
salary_range_usd: "80000-120000"
""" # Missing fields in work_preferences
with pytest.raises(TypeError):
JobApplicationProfile(invalid_yaml_str)
def test_str_representation(valid_yaml):
"""Test the string representation of JobApplicationProfile."""
profile = JobApplicationProfile(valid_yaml)
profile_str = str(profile)
assert "Self Identification:" in profile_str
assert "Legal Authorization:" in profile_str
assert "Work Preferences:" in profile_str
assert "Availability:" in profile_str
assert "Salary Expectations:" in profile_str
assert "Male" in profile_str
assert "80000-120000" in profile_str