From f6b867f076ed985739f8efbee584a2ab3bd8e8ac Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 14 Jul 2023 17:29:29 +0200 Subject: [PATCH 1/3] CI - test packaged version of fittrackee --- .github/workflows/.tests-python.yml | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/.github/workflows/.tests-python.yml b/.github/workflows/.tests-python.yml index 7f701496..6c1dc844 100644 --- a/.github/workflows/.tests-python.yml +++ b/.github/workflows/.tests-python.yml @@ -129,3 +129,55 @@ jobs: sleep 5 nohup flask worker --processes=1 >> nohup.out 2>&1 & pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 + + end2end_package: + runs-on: ubuntu-latest + needs: ["python"] + container: python:3.10 + services: + postgres: + image: postgres:14 + env: + POSTGRES_DB: fittrackee_test + POSTGRES_USER: fittrackee + POSTGRES_PASSWORD: fittrackee + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + selenium: + image: selenium/standalone-firefox + mailhog: + image: mailhog/mailhog:latest + redis: + image: redis:latest + env: + APP_SETTINGS: fittrackee.config.End2EndTestingConfig + EMAIL_URL: "smtp://mailhog:1025" + REDIS_URL: "redis://redis:6379" + HOST: "0.0.0.0" + PORT: 5000 + steps: + - uses: actions/checkout@v2 + - name: Update pip and install build + run: python3 -m pip install --upgrade pip build + - name: Create and source virtual environment + run: | + python3 -m venv .venv + . .venv/bin/activate + - name: Build fittrackee package + run: python3 -m build + - name: Install fittrackee package + run: python3 -m pip install dist/fittrackee-$(cat VERSION).tar.gz + - name: Run migrations + run: ftcli db upgrade + - name: Install pytest and selenium + run: python3 -m pip install pytest==7.4.0 pytest-selenium==4.0.1 selenium==4.9.0 + - name: Start application and run tests with Selenium + run: | + setsid nohup fittrackee >> nohup.out 2>&1 & + export TEST_APP_URL=http://$(hostname --ip-address):5000 + sleep 5 + nohup flask worker --processes=1 >> nohup.out 2>&1 & + pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 From bc15421b3968eacdd7671a47323a19908f24cb44 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 14 Jul 2023 17:43:39 +0200 Subject: [PATCH 2/3] Tests - add missing e2e test (add a workout w/ gpx) --- .github/workflows/.tests-python.yml | 2 + e2e/test.gpx | 109 ++++++++++++++++++++++++++++ e2e/test_workouts.py | 27 +++++++ 3 files changed, 138 insertions(+) create mode 100644 e2e/test.gpx diff --git a/.github/workflows/.tests-python.yml b/.github/workflows/.tests-python.yml index 6c1dc844..55ce2579 100644 --- a/.github/workflows/.tests-python.yml +++ b/.github/workflows/.tests-python.yml @@ -87,6 +87,7 @@ jobs: run: pytest fittrackee -p no:warnings --cov fittrackee --cov-report term-missing end2end: + name: e2e tests runs-on: ubuntu-latest needs: ["python"] container: python:3.10 @@ -131,6 +132,7 @@ jobs: pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 end2end_package: + name: e2e tests with package runs-on: ubuntu-latest needs: ["python"] container: python:3.10 diff --git a/e2e/test.gpx b/e2e/test.gpx new file mode 100644 index 00000000..5f387ca2 --- /dev/null +++ b/e2e/test.gpx @@ -0,0 +1,109 @@ + +' + + + just a workout + + + 998 + + + + 998 + + + + 994 + + + + 994 + + + + 994 + + + + 993 + + + + 992 + + + + 992 + + + + 987 + + + + 987 + + + + 987 + + + + 987 + + + + 986 + + + + 986 + + + + 986 + + + + 985 + + + + 980 + + + + 980 + + + + 980 + + + + 979 + + + + 981 + + + + 980 + + + + 979 + + + + 979 + + + + 975 + + + + + diff --git a/e2e/test_workouts.py b/e2e/test_workouts.py index 521c3fb6..c7a12211 100644 --- a/e2e/test_workouts.py +++ b/e2e/test_workouts.py @@ -1,3 +1,5 @@ +import os + from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import Select, WebDriverWait @@ -42,3 +44,28 @@ class TestWorkout: assert 'Distance: 10 km' in workout_details assert 'Average Speed: 10 km/h' in workout_details assert 'Max. Speed: 10 km/h' in workout_details + + def test_user_can_add_workout_with_gpx(self, selenium): + register_valid_user(selenium) + app_menu = selenium.find_element(By.CLASS_NAME, 'nav-items-app-menu') + add_workout_link = app_menu.find_elements(By.CLASS_NAME, 'nav-item')[3] + + add_workout_link.click() + selenium.implicitly_wait(1) + + select = Select(selenium.find_element(By.ID, 'sport')) + select.select_by_index(1) + gpx_input = selenium.find_element(By.XPATH, "//input[@type='file']") + gpx_input.send_keys(os.getcwd() + "/e2e/test.gpx") + + confirm_button = selenium.find_elements(By.CLASS_NAME, 'confirm')[-1] + confirm_button.click() + + WebDriverWait(selenium, 30).until( + EC.url_changes(f"{TEST_URL}/workouts/add") + ) + + workout_details = selenium.find_element(By.ID, 'workout-info').text + assert 'Duration: 0:04:10' in workout_details + assert 'Distance: 0.32 km' in workout_details + assert 'Average Speed: 4.61 km/h' in workout_details From 0f33605985268f4d7a7f73b0a7414e837227cfef Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 14 Jul 2023 17:58:23 +0200 Subject: [PATCH 3/3] API - pin pillow version to fix static map generation --- poetry.lock | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index a872e5d7..8b4cbba1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2741,4 +2741,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "affd344c95768f4f0e10df464c78aca095d84812a25931b23eaffc38c8707907" +content-hash = "f124215eb7293511623b07655a619a7660b53422f3645d6a8b47ce730f89cbf4" diff --git a/pyproject.toml b/pyproject.toml index d612f493..1d60a57c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ flask-migrate = "^4.0" gpxpy = "=1.5.0" gunicorn = "^20.1" humanize = "^4.6" +pillow = "9.5.0" psycopg2-binary = "^2.9" pyjwt = "^2.7" pyopenssl = "^23.2"