added tests, simple login test
This commit is contained in:
13
homepage/cwsvJudo/participo/Makefile
Normal file
13
homepage/cwsvJudo/participo/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
MAKE=make
|
||||
|
||||
.PHONY: TESTS
|
||||
TESTS:
|
||||
$(MAKE) --print-directory --directory ./test
|
||||
|
||||
.PHONY: INSTALL
|
||||
INSTALL:
|
||||
$(MAKE) --print-directory --directory ./test INSTALL
|
||||
|
||||
.PHONY: CLEAN
|
||||
CLEAN:
|
||||
$(MAKE) --print-directory --directory ./test CLEAN
|
||||
3
homepage/cwsvJudo/participo/test/.gitignore
vendored
Normal file
3
homepage/cwsvJudo/participo/test/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.venv
|
||||
__pycache__
|
||||
|
||||
15
homepage/cwsvJudo/participo/test/Makefile
Normal file
15
homepage/cwsvJudo/participo/test/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
PY=python
|
||||
|
||||
.PHONY: RUN
|
||||
RUN: INSTALL
|
||||
. ./run-tests
|
||||
|
||||
.PHONY: INSTALL
|
||||
INSTALL: .venv
|
||||
|
||||
.PHONY: CLEAN
|
||||
CLEAN:
|
||||
rm -rf .venv
|
||||
|
||||
.venv: requirements.txt
|
||||
. ./init-venv
|
||||
3
homepage/cwsvJudo/participo/test/config-template.toml
Normal file
3
homepage/cwsvJudo/participo/test/config-template.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
[credentials]
|
||||
user = "____"
|
||||
password = "****"
|
||||
6
homepage/cwsvJudo/participo/test/config.toml
Normal file
6
homepage/cwsvJudo/participo/test/config.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[credentials]
|
||||
username = "marko"
|
||||
password = "kodokan"
|
||||
|
||||
[url]
|
||||
home = "http://127.0.0.1/participo"
|
||||
56
homepage/cwsvJudo/participo/test/helper.py
Normal file
56
homepage/cwsvJudo/participo/test/helper.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.remote.webdriver import WebDriver
|
||||
|
||||
|
||||
def load_config(config_path: str = "config.toml"):
|
||||
from tomllib import load
|
||||
|
||||
with open(file=config_path, mode="rb") as config_file:
|
||||
return load(config_file)
|
||||
|
||||
def login(driver: WebDriver, username: str, password:str):
|
||||
driver.find_element(by=By.ID, value="username").send_keys(username)
|
||||
driver.find_element(by=By.ID, value="password").send_keys(password)
|
||||
driver.find_element(by=By.TAG_NAME, value="form").submit()
|
||||
|
||||
class Participo:
|
||||
def __init__(self) -> None:
|
||||
from selenium.webdriver import FirefoxOptions
|
||||
|
||||
options = FirefoxOptions()
|
||||
# options.add_argument("-headless")
|
||||
|
||||
self.config = load_config()
|
||||
self.driver = webdriver.Firefox(options=options)
|
||||
|
||||
self.delay = 5
|
||||
|
||||
def __enter__(self):
|
||||
self.get_home()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.driver.quit()
|
||||
|
||||
def get_home(self):
|
||||
self.driver.get(url=self.config["url"]["home"])
|
||||
|
||||
def login(self):
|
||||
credentials = self.config["credentials"]
|
||||
login(driver=self.driver, username=credentials["username"], password=credentials["password"])
|
||||
|
||||
def check_login(self):
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
|
||||
try:
|
||||
logoutButton = WebDriverWait(driver=self.driver, timeout=self.delay).until(
|
||||
EC.presence_of_element_located(
|
||||
locator=(By.LINK_TEXT, "Logout")
|
||||
)
|
||||
)
|
||||
return True
|
||||
except NoSuchElementException:
|
||||
return False
|
||||
8
homepage/cwsvJudo/participo/test/init-venv
Normal file
8
homepage/cwsvJudo/participo/test/init-venv
Normal file
@@ -0,0 +1,8 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
PY=python
|
||||
|
||||
${PY} -m venv .venv
|
||||
. .venv/bin/activate
|
||||
${PY} -m pip install --upgrade pip
|
||||
${PY} -m pip install --requirement requirements.txt
|
||||
1
homepage/cwsvJudo/participo/test/requirements.txt
Normal file
1
homepage/cwsvJudo/participo/test/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
selenium
|
||||
7
homepage/cwsvJudo/participo/test/run-tests
Normal file
7
homepage/cwsvJudo/participo/test/run-tests
Normal file
@@ -0,0 +1,7 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
PY=python
|
||||
|
||||
. .venv/bin/activate
|
||||
${PY} test_main.py
|
||||
deactivate
|
||||
15
homepage/cwsvJudo/participo/test/test_main.py
Normal file
15
homepage/cwsvJudo/participo/test/test_main.py
Normal file
@@ -0,0 +1,15 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
# testing the participo app
|
||||
import unittest
|
||||
|
||||
from helper import Participo
|
||||
|
||||
class TestParticipo(unittest.TestCase):
|
||||
def test_login(self):
|
||||
with Participo() as participo:
|
||||
participo.login()
|
||||
self.assertTrue(participo.check_login())
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user