From 20b09f7b39e3cfec6d8f7a8f90c972a07e662c5b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 23 May 2022 13:03:00 +0200 Subject: [PATCH 01/10] add selenium un requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 56dbf2be..0f5fc8ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -43,3 +43,4 @@ tqdm==4.32.2 python-decouple==3.3 python-dotenv==0.14.0 pyjwt==2.0.0a1 +selenium==4.1.5 From af470c0ecd7112f96d3554cca8fe453091d6daa7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 24 May 2022 16:41:23 +0200 Subject: [PATCH 02/10] add selenium test --- .github/workflows/flask.yml | 6 +++ tests/test_selenium.py | 90 +++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 tests/test_selenium.py diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index 16086b5b..f0a59be7 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -49,6 +49,11 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest coverage pip install -r requirements.txt + alembic -x inventory=dbtest upgrade head + dh dummy --yes + mkdir bin + wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz + tar xf geckodriver-v0.30.0-linux64.tar.gz -C bin/ - name: Prepare database env: @@ -79,6 +84,7 @@ jobs: coverage run --source='ereuse_devicehub' -m pytest -m mvp --maxfail=5 tests/ coverage report --include='ereuse_devicehub/*' coverage xml + flask run & pytest tests/test_selenium.py - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 diff --git a/tests/test_selenium.py b/tests/test_selenium.py new file mode 100644 index 00000000..866c2321 --- /dev/null +++ b/tests/test_selenium.py @@ -0,0 +1,90 @@ +# Generated by Selenium IDE +import time + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.firefox.options import Options + + +class TestSelenium: + def setup_method(self, method): + options = Options() + options.add_argument("--headless") + self.driver = webdriver.Firefox( + options=options, executable_path=r'./bin/geckodriver' + ) + self.vars = {} + + def teardown_method(self, method): + self.driver.quit() + + def test_selenium(self): + # setup + self.driver.get("http://localhost:5000/login/") + self.driver.set_window_size(1920, 1063) + + # login + self.driver.find_element(By.ID, "yourEmail").click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, "yourPassword").send_keys("1234") + self.driver.find_element(By.ID, "yourEmail").send_keys("user@dhub.com") + self.driver.find_element(By.CSS_SELECTOR, ".btn").click() + self.driver.implicitly_wait(3) + + # select the first lot and get the ID of it + self.driver.find_element(By.LINK_TEXT, "Temporary Lots").click() + self.driver.implicitly_wait(3) + self.driver.find_element( + By.CSS_SELECTOR, "#temporal-lots-nav > li:nth-child(2) span" + ).click() + self.driver.implicitly_wait(3) + lot_id = self.driver.current_url.split("/")[5] + + # go to unassigned + self.driver.find_element(By.CSS_SELECTOR, ".nav-item:nth-child(3) span").click() + self.driver.implicitly_wait(3) + + # select the first device + self.driver.find_element( + By.CSS_SELECTOR, "tr:nth-child(1) .deviceSelect" + ).click() + self.driver.implicitly_wait(3) + + # add to new selenium_lot + self.driver.find_element(By.ID, "btnLots").click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, lot_id).click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, "ApplyDeviceLots").click() + time.sleep(3) + self.driver.find_element(By.ID, "SaveAllActions").click() + time.sleep(3) + + # go to selenium lot + self.driver.find_element(By.LINK_TEXT, "Temporary Lots").click() + self.driver.implicitly_wait(3) + self.driver.find_element( + By.CSS_SELECTOR, "#temporal-lots-nav > li:nth-child(2) span" + ).click() + self.driver.implicitly_wait(3) + + # select the first device + self.driver.find_element(By.CSS_SELECTOR, ".deviceSelect").click() + + # remove to new selenium_lot + self.driver.find_element(By.ID, "btnLots").click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, lot_id).click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, "ApplyDeviceLots").click() + time.sleep(3) + self.driver.find_element(By.ID, "SaveAllActions").click() + time.sleep(3) + + self.driver.find_element(By.CSS_SELECTOR, ".nav-item:nth-child(3) span").click() + self.driver.implicitly_wait(3) + + # logout + self.driver.find_element(By.CSS_SELECTOR, ".d-md-block").click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.LINK_TEXT, "Sign Out").click() From 7ce18e148242dc1a6243ef4f486176ccec2b74cf Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 24 May 2022 16:52:19 +0200 Subject: [PATCH 03/10] add new process for check --- .github/workflows/flask.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index f0a59be7..ef68be92 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -49,8 +49,6 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest coverage pip install -r requirements.txt - alembic -x inventory=dbtest upgrade head - dh dummy --yes mkdir bin wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz tar xf geckodriver-v0.30.0-linux64.tar.gz -C bin/ @@ -67,6 +65,11 @@ jobs: psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION citext SCHEMA public;" psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION pg_trgm SCHEMA public;" + - name: Adding minimum datas + run: | + alembic -x inventory=dbtest upgrade head + dh dummy --yes + - name: Lint with flake8 run: | # stop the build if: From 7299ce15cfbab5685874341cd9ab3b7cd3a470c8 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 24 May 2022 16:57:42 +0200 Subject: [PATCH 04/10] fix pip --- .github/workflows/flask.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index ef68be92..74965db1 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -49,6 +49,7 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest coverage pip install -r requirements.txt + pip install -e . mkdir bin wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz tar xf geckodriver-v0.30.0-linux64.tar.gz -C bin/ From a6b3e725be8336ce1fe367dd6492b25b7843e318 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 24 May 2022 17:02:33 +0200 Subject: [PATCH 05/10] fix pip --- .github/workflows/flask.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index 74965db1..079835ad 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -67,6 +67,8 @@ jobs: psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION pg_trgm SCHEMA public;" - name: Adding minimum datas + env: + SECRET_KEY = 'f00046306835001b55c230092e3a7990485beda0bc3bf732088d1ba1b5b74110e22e3f9ec3a24890272554b37d4' run: | alembic -x inventory=dbtest upgrade head dh dummy --yes From 0530fef4149be874ad292a86ee08ad6062d80ad7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 24 May 2022 17:03:41 +0200 Subject: [PATCH 06/10] fix env vars --- .github/workflows/flask.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index 079835ad..d08a5cb7 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -68,7 +68,7 @@ jobs: - name: Adding minimum datas env: - SECRET_KEY = 'f00046306835001b55c230092e3a7990485beda0bc3bf732088d1ba1b5b74110e22e3f9ec3a24890272554b37d4' + SECRET_KEY: 'f00046306835001b55c230092e3a7990485beda0bc3bf732088d1ba1b5b74110e22e3f9ec3a24890272554b37d4' run: | alembic -x inventory=dbtest upgrade head dh dummy --yes From ab20cdd1d0f795af39fbfb0f326cc2d1b204013d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 24 May 2022 17:12:53 +0200 Subject: [PATCH 07/10] fix env vars --- .github/workflows/flask.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index d08a5cb7..3d8acf69 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -66,9 +66,10 @@ jobs: psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION citext SCHEMA public;" psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION pg_trgm SCHEMA public;" - - name: Adding minimum datas + - name: Selenium tests env: SECRET_KEY: 'f00046306835001b55c230092e3a7990485beda0bc3bf732088d1ba1b5b74110e22e3f9ec3a24890272554b37d4' + DB_DATABASE: dh_test run: | alembic -x inventory=dbtest upgrade head dh dummy --yes From a5d397627467e0d452908398efad4bcab537fb3a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 24 May 2022 17:16:50 +0200 Subject: [PATCH 08/10] fix env vars --- .github/workflows/flask.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index 3d8acf69..2b6ef986 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -70,6 +70,7 @@ jobs: env: SECRET_KEY: 'f00046306835001b55c230092e3a7990485beda0bc3bf732088d1ba1b5b74110e22e3f9ec3a24890272554b37d4' DB_DATABASE: dh_test + dhi: dbtest run: | alembic -x inventory=dbtest upgrade head dh dummy --yes From ef570232e7ea7ac80fccd572f236a3cfe9b6d0e6 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 24 May 2022 17:20:17 +0200 Subject: [PATCH 09/10] fix env vars --- .github/workflows/flask.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index 2b6ef986..c899a218 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -74,6 +74,7 @@ jobs: run: | alembic -x inventory=dbtest upgrade head dh dummy --yes + flask run & pytest tests/test_selenium.py - name: Lint with flake8 run: | @@ -92,7 +93,6 @@ jobs: coverage run --source='ereuse_devicehub' -m pytest -m mvp --maxfail=5 tests/ coverage report --include='ereuse_devicehub/*' coverage xml - flask run & pytest tests/test_selenium.py - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 From 5f025ff86988bdfdab900f66fcd00472e3b86d6e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 25 May 2022 09:56:47 +0200 Subject: [PATCH 10/10] fix env vars --- .github/workflows/flask.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index c899a218..ec42536f 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -70,6 +70,7 @@ jobs: env: SECRET_KEY: 'f00046306835001b55c230092e3a7990485beda0bc3bf732088d1ba1b5b74110e22e3f9ec3a24890272554b37d4' DB_DATABASE: dh_test + FLASK_APP: examples/app.py dhi: dbtest run: | alembic -x inventory=dbtest upgrade head