-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement proxy_checker unittests plus test and coverage github…
… actions
- Loading branch information
1 parent
e3981d2
commit 6696834
Showing
8 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
comment: | ||
layout: header, changes, diff, sunburst | ||
coverage: | ||
status: | ||
patch: | ||
default: | ||
threshold: "10%" | ||
only_pulls: true | ||
|
||
project: | ||
default: | ||
target: auto | ||
threshold: "10%" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Unit Test | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
testing: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python V3.12 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.12" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
make devtools | ||
- name: Run Unit Tests with Coverage | ||
run: | | ||
coverage run -m unittest discover tests | ||
coverage report | ||
coverage xml | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
file: coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Unit Test | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
testing: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python V3.12 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.12" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
make devtools | ||
- name: Run Unit Tests | ||
run: | | ||
make unittest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
import requests | ||
from proxy_miner.proxy_checker.proxy_checker import ProxyChecker | ||
from proxy_miner.proxy_enum.proxy_type import ProxyType | ||
|
||
|
||
class TestProxyChecker(unittest.TestCase): | ||
|
||
@patch("proxy_miner.proxy_checker.proxy_checker.requests.get") | ||
def test_validate_http_proxy_success(self, mock_get): | ||
# Setup | ||
proxies = [ | ||
(ProxyType.HTTP, ["http_proxy1", "http_proxy2"]), | ||
(ProxyType.HTTPS, ["https_proxy1"]), | ||
] | ||
url = "http://example.com" | ||
timeout = 5.0 | ||
ssl_verify = False | ||
checker = ProxyChecker(proxies, url, timeout, ssl_verify) | ||
|
||
# Mock response for successful request | ||
mock_response = MagicMock() | ||
mock_response.status_code = 200 | ||
mock_get.return_value = mock_response | ||
|
||
# Act | ||
checker.validate_http_proxy() | ||
|
||
# Assert | ||
self.assertIn("http_proxy1", checker.fetch_proxies()) | ||
self.assertIn("http_proxy2", checker.fetch_proxies()) | ||
self.assertNotIn("https_proxy1", checker.fetch_proxies()) | ||
|
||
@patch("proxy_miner.proxy_checker.proxy_checker.requests.get") | ||
def test_validate_http_proxy_failure(self, mock_get): | ||
# Setup | ||
proxies = [ | ||
(ProxyType.HTTP, ["http_proxy1"]), | ||
] | ||
url = "http://example.com" | ||
timeout = 5.0 | ||
ssl_verify = False | ||
checker = ProxyChecker(proxies, url, timeout, ssl_verify) | ||
|
||
# Mock response for failed request | ||
mock_get.side_effect = requests.exceptions.RequestException | ||
|
||
# Act | ||
checker.validate_http_proxy() | ||
|
||
# Assert | ||
self.assertNotIn("http_proxy1", checker.fetch_proxies()) | ||
|
||
@patch("proxy_miner.proxy_checker.proxy_checker.requests.get") | ||
def test_validate_https_proxy_success(self, mock_get): | ||
# Setup | ||
proxies = [ | ||
(ProxyType.HTTPS, ["https_proxy1"]), | ||
] | ||
url = "https://example.com" | ||
timeout = 5.0 | ||
ssl_verify = True | ||
checker = ProxyChecker(proxies, url, timeout, ssl_verify) | ||
|
||
# Mock response for successful request | ||
mock_response = MagicMock() | ||
mock_response.status_code = 200 | ||
mock_get.return_value = mock_response | ||
|
||
# Act | ||
checker.validate_https_proxy() | ||
|
||
# Assert | ||
self.assertIn("https_proxy1", checker.fetch_proxies()) | ||
|
||
@patch("proxy_miner.proxy_checker.proxy_checker.requests.get") | ||
def test_validate_socks4_proxy_success(self, mock_get): | ||
# Setup | ||
proxies = [ | ||
(ProxyType.SOCKS4, ["socks4_proxy1"]), | ||
] | ||
url = "http://example.com" | ||
timeout = 5.0 | ||
ssl_verify = False | ||
checker = ProxyChecker(proxies, url, timeout, ssl_verify) | ||
|
||
# Mock response for successful request | ||
mock_response = MagicMock() | ||
mock_response.status_code = 200 | ||
mock_get.return_value = mock_response | ||
|
||
# Act | ||
checker.validate_socks4_proxy() | ||
|
||
# Assert | ||
self.assertIn("socks4_proxy1", checker.fetch_proxies()) | ||
|
||
@patch("proxy_miner.proxy_checker.proxy_checker.requests.get") | ||
def test_validate_socks5_proxy_success(self, mock_get): | ||
# Setup | ||
proxies = [ | ||
(ProxyType.SOCKS5, ["socks5_proxy1"]), | ||
] | ||
url = "http://example.com" | ||
timeout = 5.0 | ||
ssl_verify = False | ||
checker = ProxyChecker(proxies, url, timeout, ssl_verify) | ||
|
||
# Mock response for successful request | ||
mock_response = MagicMock() | ||
mock_response.status_code = 200 | ||
mock_get.return_value = mock_response | ||
|
||
# Act | ||
checker.validate_socks5_proxy() | ||
|
||
# Assert | ||
self.assertIn("socks5_proxy1", checker.fetch_proxies()) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |