forked from feder-cr/Jobs_Applier_AI_Agent_AIHawk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_aihawk_easy_applier.py
99 lines (70 loc) · 3.28 KB
/
test_aihawk_easy_applier.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
import pytest
from unittest import mock
from ai_hawk.linkedIn_easy_applier import AIHawkEasyApplier
@pytest.fixture
def mock_driver():
"""Fixture to mock Selenium WebDriver."""
return mock.Mock()
@pytest.fixture
def mock_gpt_answerer():
"""Fixture to mock GPT Answerer."""
return mock.Mock()
@pytest.fixture
def mock_resume_generator_manager():
"""Fixture to mock Resume Generator Manager."""
return mock.Mock()
@pytest.fixture
def easy_applier(mock_driver, mock_gpt_answerer, mock_resume_generator_manager):
"""Fixture to initialize AIHawkEasyApplier with mocks."""
return AIHawkEasyApplier(
driver=mock_driver,
resume_dir="/path/to/resume",
set_old_answers=[('Question 1', 'Answer 1', 'Type 1')],
gpt_answerer=mock_gpt_answerer,
resume_generator_manager=mock_resume_generator_manager
)
def test_initialization(mocker, easy_applier):
"""Test that AIHawkEasyApplier is initialized correctly."""
# Mock os.path.exists to return True
mocker.patch('os.path.exists', return_value=True)
easy_applier = AIHawkEasyApplier(
driver=mocker.Mock(),
resume_dir="/path/to/resume",
set_old_answers=[('Question 1', 'Answer 1', 'Type 1')],
gpt_answerer=mocker.Mock(),
resume_generator_manager=mocker.Mock()
)
assert easy_applier.resume_path == "/path/to/resume"
assert len(easy_applier.set_old_answers) == 1
assert easy_applier.gpt_answerer is not None
assert easy_applier.resume_generator_manager is not None
def test_apply_to_job_success(mocker, easy_applier):
"""Test successfully applying to a job."""
mock_job = mock.Mock()
# Mock job_apply so we don't actually try to apply
mocker.patch.object(easy_applier, 'job_apply')
easy_applier.apply_to_job(mock_job)
easy_applier.job_apply.assert_called_once_with(mock_job)
def test_apply_to_job_failure(mocker, easy_applier):
"""Test failure while applying to a job."""
mock_job = mock.Mock()
mocker.patch.object(easy_applier, 'job_apply',
side_effect=Exception("Test error"))
with pytest.raises(Exception, match="Test error"):
easy_applier.apply_to_job(mock_job)
easy_applier.job_apply.assert_called_once_with(mock_job)
def test_check_for_premium_redirect_no_redirect(mocker, easy_applier):
"""Test that check_for_premium_redirect works when there's no redirect."""
mock_job = mock.Mock()
easy_applier.driver.current_url = "https://www.linkedin.com/jobs/view/1234"
easy_applier.check_for_premium_redirect(mock_job)
easy_applier.driver.get.assert_not_called()
def test_check_for_premium_redirect_with_redirect(mocker, easy_applier):
"""Test that check_for_premium_redirect handles AIHawk Premium redirects."""
mock_job = mock.Mock()
easy_applier.driver.current_url = "https://www.linkedin.com/premium"
mock_job.link = "https://www.linkedin.com/jobs/view/1234"
with pytest.raises(Exception, match="Redirected to AIHawk Premium page and failed to return"):
easy_applier.check_for_premium_redirect(mock_job)
# Verify that it attempted to return to the job page 3 times
assert easy_applier.driver.get.call_count == 3