diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 0000000..96c10bd --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,12 @@ +FROM debian8_python3 + +COPY app/requirements.txt /requirements.txt +RUN pip3 install -r /requirements.txt; \ + mkdir /data + +ADD app /app + +VOLUME ["/data"] +VOLUME ["/app/config] +EXPOSE 5000 +ENTRYPOINT python3 /app/main.py diff --git a/tests/app/main.py b/tests/app/main.py new file mode 100644 index 0000000..4268acc --- /dev/null +++ b/tests/app/main.py @@ -0,0 +1,60 @@ +import unittest +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions + +class PythonOrgSearch(unittest.TestCase): + screen_shot_counter=0 + + def setUp(self): + self.driver = webdriver.Remote( + command_executor='http://selenium:4444/wd/hub', + desired_capabilities=DesiredCapabilities.FIREFOX) + self.driver.get("http://rollerverbrauch:5000") + WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "email"))) + + def test_page_loads(self): + self.driver.get("http://rollerverbrauch:5000") + self.create_screenshot() + assert "refuel" in self.driver.title + + def test_can_register(self): + self.driver.get("http://rollerverbrauch:5000") + self.driver.find_element_by_partial_link_text('Register').click() + self.create_screenshot() + WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "submit"))) + self.create_screenshot() + self.driver.find_element_by_id('email').send_keys('test@test.com') + self.driver.find_element_by_id('password').send_keys('test123') + self.driver.find_element_by_id('password_confirm').send_keys('test123') + self.create_screenshot() + self.driver.find_element_by_id('submit').click() + WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "i1"))) + self.create_screenshot() + + def test_register_must_repeat_pwd(self): + self.driver.get("http://rollerverbrauch:5000") + self.driver.find_element_by_partial_link_text('Register').click() + self.create_screenshot() + WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "submit"))) + self.create_screenshot() + self.driver.find_element_by_id('email').send_keys('test@test.com') + self.driver.find_element_by_id('password').send_keys('test123') + self.create_screenshot() + self.driver.find_element_by_id('submit').click() + self.create_screenshot() + error = self.driver.find_elements_by_class_name('error') + assert error is not None + + def create_screenshot(self): + self.driver.get_screenshot_as_file('/results/screenshot_%s.png' % (str(self.screen_shot_counter))) + self.screen_shot_counter += 1 + + def tearDown(self): + self.driver.close() + +if __name__ == "__main__": + unittest.main() diff --git a/tests/app/requirements.txt b/tests/app/requirements.txt new file mode 100644 index 0000000..954f0db --- /dev/null +++ b/tests/app/requirements.txt @@ -0,0 +1 @@ +selenium \ No newline at end of file diff --git a/tests/compose_config/config.py b/tests/compose_config/config.py new file mode 100644 index 0000000..79c2dcf --- /dev/null +++ b/tests/compose_config/config.py @@ -0,0 +1,16 @@ +import os + +#SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:%s@database/pitstops' % (os.environ['DATABASE_ENV_MYSQL_ROOT_PASSWORD']) +SQLALCHEMY_DATABASE_URI = 'sqlite:////data/rollerverbrauch.db' + +MAIL_SERVER = '' +MAIL_PORT= 25 +MAIL_USE_TLS = True +MAIL_USE_SSL = False +MAIL_USERNAME = '' +MAIL_PASSWORD = '' +SECURITY_EMAIL_SENDER = '' +SECURITY_PASSWORD_SALT = 'SecretSalt' +SECRET_KEY = 'SecretKey' + +SECURITY_SEND_REGISTER_EMAIL = False diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 0000000..7809e4f --- /dev/null +++ b/tests/docker-compose.yml @@ -0,0 +1,22 @@ +version: '2' +services: + tests: + build: . + depends_on: + - selenium + volumes: + - ./results:/results + selenium: + image: selenium/standalone-firefox + depends_on: + - rollerverbrauch + rollerverbrauch: + build: .. + volumes: + - ./compose_config/:/config + environment: + - config=/config/config.py + - DATABASE_ENV_MYSQL_ROOT_PASSWORD=foobar123 + ports: + - 5000 + diff --git a/tests/results/rollerverbrauch.png b/tests/results/rollerverbrauch.png new file mode 100644 index 0000000..5e5a3d6 Binary files /dev/null and b/tests/results/rollerverbrauch.png differ diff --git a/tests/run_test.sh b/tests/run_test.sh new file mode 100755 index 0000000..eac53a8 --- /dev/null +++ b/tests/run_test.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +docker-compose build +docker-compose up --abort-on-container-exit +docker-compose down +docker-compose rm --all