Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Wuzzuf Files #1045

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scrape_up/wuzzuf/wuzzuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __get_job_url(self, job_data):
return job_data.find("h2", {"class": "css-m604qf"}).find("a")["href"]

def __get_job_company(self, job_data):
return job_data.find("div", {"class": "css-d7j1kk"}).find("a").text[:-1].strip()
return job_data.find("div", {"class": "css-d7j1kk"}).find("a").text.strip()

def __get_job_location(self, job_data):
data = job_data.find("span", {"class": "css-5wys0k"})
Expand Down
62 changes: 62 additions & 0 deletions src/test/wuzzuf_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import unittest
from unittest.mock import patch
from scrape_up.wuzzuf import Jobs
import requests


class JobsTest(unittest.TestCase):
"""
Jobs module test.
| Methods | Details |
| ------------------- | -------------------------------------------------------------------------------------------- |
| `filter_job()` | Apply filters to the job search using parameters like title, country, city, min/max years of experience. |
| `fetch_jobs()` | Fetch job listings based on the applied filters, with an optional maximum number of pages to scrape. |
"""

def setUp(self):
self.scraper = Jobs()

def test_filter_job(self):
self.scraper.filter_job(
title="software engineer",
country="Egypt",
city="Cairo",
min_years_of_experience=2,
max_years_of_experience=5,
)
expected_url = "https://wuzzuf.net/search/jobs/?q=software+engineer&filters[country][0]=Egypt&filters[city][0]=Cairo&filters[years_of_experience_min][0]=2&filters[years_of_experience_max][0]=5"
self.assertEqual(self.scraper.url, expected_url)

@patch("requests.get")
def test_fetch_jobs(self, mock_get):
# Mock the get response
mock_response = requests.Response()
mock_response.status_code = 200
mock_response._content = b"""
<div class="css-1gatmva e1v1l3u10">
<h2 class="css-m604qf"><a href="/job/1">Software Engineer</a></h2>
<div class="css-d7j1kk"><a href="#">Company Name</a></div>
<span class="css-5wys0k">Cairo, Egypt</span>
<div class="css-4c4ojb">3 days ago</div>
<span class="eoyjyou0">Full Time</span>
<span class="eoyjyou0">Senior</span>
</div>
"""
mock_get.return_value = mock_response

jobs = self.scraper.fetch_jobs(max_page_number=1)
expected_job = {
"name": "Software Engineer",
"url": "/job/1",
"company": "Company Name",
"location": "Cairo, Egypt",
"published_time": "3 days ago",
"properties": "Full Time ,Senior",
}

self.assertEqual(len(jobs), 1)
self.assertEqual(jobs[0], expected_job)


if __name__ == "__main__":
unittest.main()