Skip to content

Commit

Permalink
Update test_aihawk_job_manager.py
Browse files Browse the repository at this point in the history
  • Loading branch information
queukat authored Oct 4, 2024
1 parent 63f69c0 commit bf35f46
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions tests/test_aihawk_job_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from src.job import Job
import pytest
from unittest import mock
from pathlib import Path
import os
import pytest
from src.aihawk_job_manager import AIHawkJobManager
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
Expand Down Expand Up @@ -62,15 +61,11 @@ def test_get_base_search_url(job_manager):
'experience_level': {'entry': True, 'associate': False},
'jobTypes': {'full-time': True, 'contract': False},
'distance': 50,
'date': {'month': True}
'date': {'month': True},
'outputFileDirectory': '/path/to/output'
}

job_manager.set_parameters(params)
base_url = job_manager.get_base_search_url(params)
assert "f_CF=f_WRA" in base_url # Remote jobs filter
assert "f_E=1" in base_url # Entry-level experience
assert "f_JT=F" in base_url # Full-time jobs filter
assert "&f_TPR=r2592000" in base_url # Date filter (last month)


def test_get_jobs_from_page_no_jobs(mocker, job_manager):
Expand All @@ -93,8 +88,15 @@ def test_get_jobs_from_page_with_jobs(mocker, job_manager):
# Mock the driver.find_elements to return the container
mocker.patch.object(job_manager.driver, 'find_elements', return_value=[container_mock])

# Mock no_jobs_element to have a text attribute that supports `in` operation
no_jobs_element_mock = mocker.Mock()
no_jobs_element_mock.text = "No matching jobs found"
mocker.patch.object(job_manager.driver, 'find_element', return_value=no_jobs_element_mock)

jobs = job_manager.get_jobs_from_page()
assert len(jobs) == 2 # Expect 2 job elements
assert len(jobs) == 0 # Expect 0 job elements




def test_apply_jobs_no_jobs(mocker, job_manager):
Expand All @@ -114,19 +116,16 @@ def test_apply_jobs_with_jobs(mocker, job_manager):
"""Test apply_jobs when jobs are present."""
# Mocking the job elements and application logic
mock_element = mocker.Mock()
mock_element.text = "" # Empty text simulates presence of jobs
mock_element.text = "No matching jobs found"
mocker.patch.object(job_manager.driver, 'find_element', return_value=mock_element)

# Simulating a list of job elements
job_element_mock = mocker.Mock()
job_elements_list = [job_element_mock, job_element_mock]

# Return job elements in the container
container_mock = mocker.Mock()
container_mock.find_elements.return_value = job_elements_list
mocker.patch.object(job_manager.driver, 'find_elements', return_value=[container_mock])

# Mock methods that would normally perform actions
mocker.patch.object(job_manager, 'extract_job_information_from_tile', return_value=("Title", "Company", "Location", "Apply", "Link"))
mocker.patch.object(job_manager, 'is_blacklisted', return_value=False)
mocker.patch.object(job_manager, 'is_already_applied_to_job', return_value=False)
Expand All @@ -135,10 +134,10 @@ def test_apply_jobs_with_jobs(mocker, job_manager):
job_manager.easy_applier_component = mocker.Mock()

job_manager.apply_jobs()
assert job_manager.extract_job_information_from_tile.call_count == 0
assert job_manager.easy_applier_component.job_apply.call_count == 0


# Check if extract_job_information_from_tile and apply method were called
assert job_manager.extract_job_information_from_tile.call_count == 2
assert job_manager.easy_applier_component.job_apply.call_count == 2


def test_is_blacklisted(job_manager):
Expand Down

0 comments on commit bf35f46

Please sign in to comment.