diff --git a/homepage/cwsvJudo/participo/Makefile b/homepage/cwsvJudo/participo/Makefile new file mode 100644 index 0000000..095b537 --- /dev/null +++ b/homepage/cwsvJudo/participo/Makefile @@ -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 diff --git a/homepage/cwsvJudo/participo/test/.gitignore b/homepage/cwsvJudo/participo/test/.gitignore new file mode 100644 index 0000000..d449405 --- /dev/null +++ b/homepage/cwsvJudo/participo/test/.gitignore @@ -0,0 +1,3 @@ +.venv +__pycache__ + diff --git a/homepage/cwsvJudo/participo/test/Makefile b/homepage/cwsvJudo/participo/test/Makefile new file mode 100644 index 0000000..2955f7e --- /dev/null +++ b/homepage/cwsvJudo/participo/test/Makefile @@ -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 diff --git a/homepage/cwsvJudo/participo/test/config-template.toml b/homepage/cwsvJudo/participo/test/config-template.toml new file mode 100644 index 0000000..72291cd --- /dev/null +++ b/homepage/cwsvJudo/participo/test/config-template.toml @@ -0,0 +1,3 @@ +[credentials] +user = "____" +password = "****" diff --git a/homepage/cwsvJudo/participo/test/config.toml b/homepage/cwsvJudo/participo/test/config.toml new file mode 100644 index 0000000..4352847 --- /dev/null +++ b/homepage/cwsvJudo/participo/test/config.toml @@ -0,0 +1,6 @@ +[credentials] +username = "marko" +password = "kodokan" + +[url] +home = "http://127.0.0.1/participo" diff --git a/homepage/cwsvJudo/participo/test/helper.py b/homepage/cwsvJudo/participo/test/helper.py new file mode 100644 index 0000000..86f4913 --- /dev/null +++ b/homepage/cwsvJudo/participo/test/helper.py @@ -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 diff --git a/homepage/cwsvJudo/participo/test/init-venv b/homepage/cwsvJudo/participo/test/init-venv new file mode 100644 index 0000000..fe8e315 --- /dev/null +++ b/homepage/cwsvJudo/participo/test/init-venv @@ -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 diff --git a/homepage/cwsvJudo/participo/test/requirements.txt b/homepage/cwsvJudo/participo/test/requirements.txt new file mode 100644 index 0000000..7cb6656 --- /dev/null +++ b/homepage/cwsvJudo/participo/test/requirements.txt @@ -0,0 +1 @@ +selenium diff --git a/homepage/cwsvJudo/participo/test/run-tests b/homepage/cwsvJudo/participo/test/run-tests new file mode 100644 index 0000000..5d58979 --- /dev/null +++ b/homepage/cwsvJudo/participo/test/run-tests @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +PY=python + +. .venv/bin/activate +${PY} test_main.py +deactivate diff --git a/homepage/cwsvJudo/participo/test/test_main.py b/homepage/cwsvJudo/participo/test/test_main.py new file mode 100644 index 0000000..4d94f52 --- /dev/null +++ b/homepage/cwsvJudo/participo/test/test_main.py @@ -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()