feat: add tox test for static format check via black/flake8, integration test

This commit is contained in:
Trung Le 2021-04-08 01:54:51 +07:00
parent fbd24a13c0
commit b3f624a119
No known key found for this signature in database
GPG Key ID: 0264396EFC85E502
4 changed files with 90 additions and 0 deletions

3
.gitignore vendored
View File

@ -127,3 +127,6 @@ dmypy.json
# Pyre type checker
.pyre/
# patched chromedriver
chromedriver

33
tests/conftest.py Normal file
View File

@ -0,0 +1,33 @@
import pytest
from _pytest.fixtures import FixtureRequest
import undetected_chromedriver as uc
FAILED_SCREENSHOT_NAME = "failed.png"
@pytest.fixture
def head_uc(request: FixtureRequest):
request.instance.driver = uc.Chrome()
def teardown():
request.instance.driver.save_screenshot(FAILED_SCREENSHOT_NAME)
request.instance.driver.quit()
request.addfinalizer(teardown)
return request.instance.driver
@pytest.fixture
def headless_uc(request: FixtureRequest):
options = uc.ChromeOptions()
options.headless = True
request.instance.driver = uc.Chrome(options=options)
def teardown():
request.instance.driver.save_screenshot(FAILED_SCREENSHOT_NAME)
request.instance.driver.quit()
request.addfinalizer(teardown)
return request.instance.driver

20
tests/v1/head_test.py Normal file
View File

@ -0,0 +1,20 @@
import pytest
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
TIMEOUT = 10
@pytest.mark.usefixtures("head_uc")
class TestBotCheck:
def test_bot_protect_io(self):
driver: WebDriver = self.driver # type: ignore
driver.get("https://lhcdn.botprotect.io")
msg = WebDriverWait(driver, TIMEOUT).until(
EC.visibility_of_element_located((By.ID, "msg"))
)
print(msg.text)
assert "You are human." in msg.text

34
tox.ini Normal file
View File

@ -0,0 +1,34 @@
[tox]
envlist =
py38,
static_check,
v1,
v2
[testenv]
deps =
pytest
selenium
[testenv:static_check]
deps =
black
flake8
commands =
black --check --diff .
flake8 undetected_chromedriver \
--max-line-length=88 \
--exclude v2.py
[testenv:v1]
commands =
pytest \
-v -s \
./tests/v1
; Currently v2 is WIP
; [testenv:v2]
; commands =
; pytest \
; -v -s \
; ./tests/v2