diff --git a/.github/workflows/.tests-python.yml b/.github/workflows/.tests-python.yml index 7f701496..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 @@ -129,3 +130,56 @@ 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: + name: e2e tests with 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 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 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"