forked from coding-ai/EasyApply-Linkedin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit_tests.py
55 lines (49 loc) · 2.2 KB
/
unit_tests.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
import unittest
from unittest.mock import patch, MagicMock
from easy_apply_linkedin import EasyApplyLinkedin
class TestEasyApplyLinkedin(unittest.TestCase):
def setUp(self):
self.data = {
"email": "[email protected]",
"password": "bp8v9fvk#?QaKe7",
"keywords": ["TypeScript", "Angular", "React"],
"keywordsToAvoid": ["C++", ".NET"],
"locations": ["Switzerland", "Belgium"],
"driver_path": "/usr/local/bin/geckodriver",
"sortBy": "R",
"filters": {
"easy_apply": True,
"experience": [],
"jobType": ["Full-time", "Contract"],
"timePostedRange": [],
"workplaceType": ["Remote", "Hybrid"],
"less_than_10_applicants": False
}
}
self.bot = EasyApplyLinkedin(self.data)
@patch('easy_apply_linkedin.webdriver.Firefox')
def test_login_linkedin(self, MockWebDriver):
mock_driver = MockWebDriver.return_value
mock_driver.find_element.return_value = MagicMock()
self.bot.login_linkedin()
mock_driver.get.assert_called_with("https://www.linkedin.com/login")
self.assertTrue(mock_driver.find_element.called)
@patch('easy_apply_linkedin.webdriver.Firefox')
def test_construct_url(self, MockWebDriver):
url = self.bot.construct_url()
self.assertIn("keywords=TypeScript%20OR%20Angular%20OR%20React", url)
self.assertIn("geoId=106693272", url)
self.assertIn("f_AL=true", url)
@patch('easy_apply_linkedin.webdriver.Firefox')
def test_apply_filters_and_search_no_results(self, MockWebDriver):
mock_driver = MockWebDriver.return_value
mock_driver.find_element.side_effect = NoSuchElementException
self.bot.apply_filters_and_search()
self.assertEqual(self.bot.current_location_index, 1)
@patch('easy_apply_linkedin.webdriver.Firefox')
def test_log_error(self, MockWebDriver):
self.bot.log_error("Test error")
errors = self.bot.load_json(self.bot.ERROR_LOG_PATH)
self.assertTrue(any("Test error" in v for v in errors.values()))
if __name__ == "__main__":
unittest.main()