diff --git a/requirements.txt b/requirements.txt index 0d87cf6c..00313ba3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ werkzeug==2.0.0 Flask==2.0.3 jinja2==3.0.0 -requests==2.24.0 +requests==2.25.0 python-pptx==0.6.18 odfpy==1.4.1 pymongo==3.11.1 @@ -28,3 +28,5 @@ pytest~=7.1.2 filetype==1.2.0 language-tool-python==2.7.1 markdown==3.4.4 +selenium==4.16.0 +webdriver-manager==4.0.1 diff --git a/tests/README.md b/tests/README.md index e2f61ebb..cff11bd9 100644 --- a/tests/README.md +++ b/tests/README.md @@ -8,12 +8,17 @@ Install requirements.txt: $ pip install -r tests/requirements.txt ``` +## Test for autorization: +class AuthTestSelenium(BasicSeleniumTest) with 3 tests -## Test for open page /version: +Tests check: if page "/login" opens, if it doesn't take wrong login/password and takes correct. + +## Test for open page /check_list: class StatisticTestSelenium(BasicSeleniumTest) with 1 test Test check: if page "/check_list" opens + ## Run run_tests use login and password from .env diff --git a/tests/main.py b/tests/main.py index e16af4a7..cad68c53 100644 --- a/tests/main.py +++ b/tests/main.py @@ -3,6 +3,7 @@ import argparse from basic_selenium_test import BasicSeleniumTest from test_statistic import StatisticTestSelenium +from test_authorization import AuthTestSelenium def parse_arguments(): parser = argparse.ArgumentParser(description='Run Selenium tests with specified host, login, and password.') @@ -15,8 +16,9 @@ def main(): args = parse_arguments() suite = unittest.TestSuite() + suite.addTest(BasicSeleniumTest.parametrize(AuthTestSelenium, param=(args.host, args.login, args.password))) suite.addTest(BasicSeleniumTest.parametrize(StatisticTestSelenium, param=(args.host, args.login, args.password))) - + returnCode = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() BasicSeleniumTest.closeDriver() diff --git a/tests/test_authorization.py b/tests/test_authorization.py new file mode 100644 index 00000000..02683bcf --- /dev/null +++ b/tests/test_authorization.py @@ -0,0 +1,37 @@ +import os +from basic_selenium_test import BasicSeleniumTest +from selenium.webdriver.common.by import By + +class AuthTestSelenium(BasicSeleniumTest): + + def check_auth(self, login_param, password_param): + URL = self.getUrl('/login') + self.getDriver().get(URL) + self.getDriver().implicitly_wait(30) + login = self.getDriver().find_element(By.ID, "login_text_field") + login.clear() + login.send_keys(login_param) + password = self.getDriver().find_element(By.ID, "password_text_field") + password.clear() + password.send_keys(password_param) + login_button = self.getDriver().find_element(By.ID, "login_button") + login_button.click() + + def test_loading(self): + URL = self.getUrl('/login') + self.getDriver().get(URL) + self.getDriver().implicitly_wait(30) + obj = self.getDriver().find_element(By.CLASS_NAME, "form-group") + self.assertNotEquals(obj, None) + + def test_failed_auth(self): + host, login, password = self.param + self.check_auth('wrong_login', 'wrong_password') + obj = self.getDriver().find_element(By.ID, "login_button") + self.assertNotEquals(obj, None) + + def test_complete_auth(self): + host, login, password = self.param + self.check_auth(login, password) + upload_url = self.getUrl('/upload') + self.assertIn(upload_url, self.getDriver().current_url)