diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 527e21f3..5feb9852 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -10,18 +10,18 @@ jobs: tests: strategy: matrix: - python: ["3.5", "3.6", "3.8"] - runs-on: ubuntu-20.04 - container: "python:${{matrix.python}}-slim-buster" + python: ["3.10"] #3.10 + runs-on: ubuntu-22.04 #ubuntu:jammy-20231004 + # container: "python:${{matrix.python}}-slim-buster" steps: - uses: actions/checkout@v3 - name: Update apt-get sources - run: apt-get update + run: sudo apt-get update - name: Install PostgreSQL, PostGIS and GDAL run: > - apt-get install -y + sudo apt-get install -y gdal-bin python3-gdal postgis @@ -32,14 +32,14 @@ jobs: build-essential - name: Start PostgreSQL server - run: /etc/init.d/postgresql start + run: sudo /etc/init.d/postgresql start - - name: Allow root to create PostgreSQL databases - run: su - postgres -c "createuser --createdb root" + - name: Allow runner to create PostgreSQL databases + run: sudo su - postgres -c "createuser --createdb runner" - name: Create PostGIS extension run: > - su - postgres + sudo su - postgres -c "psql template1 -c 'create extension postgis'" - name: Install Tox and tox-gh-actions @@ -52,7 +52,7 @@ jobs: uses: codecov/codecov-action@v3 test-dockerization: - runs-on: ubuntu-22.04 + runs-on: ubuntu-22.04 #ubuntu:jammy-20231004 steps: - uses: actions/checkout@v3 @@ -72,14 +72,14 @@ jobs: strategy: matrix: toxenv: [style, requirements, sanitizer] - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 #ubuntu:jammy-20231004 steps: - uses: actions/checkout@v3 - name: Setup Python uses: actions/setup-python@v3.1.2 with: - python-version: "3.5" + python-version: "3.10" #3.10 - name: Install GDAL run: sudo apt-get install -y gdal-bin diff --git a/Dockerfile b/Dockerfile index bd7ad5a7..96ed8ddd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ RUN touch /.dockerenv RUN apt-get update \ && apt-get install --yes \ git \ + netcat \ sudo \ vim \ zsh \ diff --git a/parkings/api/auth/drf_jwt_2fa_urls.py b/parkings/api/auth/drf_jwt_2fa_urls.py index 2442bcb7..dcf84c04 100644 --- a/parkings/api/auth/drf_jwt_2fa_urls.py +++ b/parkings/api/auth/drf_jwt_2fa_urls.py @@ -1,5 +1,4 @@ from django.urls import re_path - from drf_jwt_2fa import views urlpatterns = [ @@ -7,4 +6,4 @@ re_path('^auth/', views.obtain_auth_token, name='auth'), re_path('^refresh/', views.refresh_auth_token, name='refresh'), re_path('^verify/', views.verify_auth_token, name='verify'), -] \ No newline at end of file +] diff --git a/parkings/api/enforcement/valid_permit_item.py b/parkings/api/enforcement/valid_permit_item.py index b658c3cb..94ee8ee9 100644 --- a/parkings/api/enforcement/valid_permit_item.py +++ b/parkings/api/enforcement/valid_permit_item.py @@ -42,7 +42,6 @@ def to_representation(self, instance): return representation - class ValidPermitItemFilter(django_filters.rest_framework.FilterSet): reg_num = django_filters.CharFilter( label=_("Registration number"), method='filter_reg_num') diff --git a/parkings/api/url_utils.py b/parkings/api/url_utils.py index 8e21aaa2..cecfcf85 100644 --- a/parkings/api/url_utils.py +++ b/parkings/api/url_utils.py @@ -1,5 +1,6 @@ from django.urls import include, re_path + def versioned_url(version, include_urls, regexp=r'^'): return re_path( '{regexp}{version}/'.format(regexp=regexp, version=version), diff --git a/parkings/models/parking_check.py b/parkings/models/parking_check.py index 35887e3e..7d1cab8f 100644 --- a/parkings/models/parking_check.py +++ b/parkings/models/parking_check.py @@ -1,8 +1,8 @@ from django.conf import settings from django.contrib.gis.db import models as gis_models -from django.db.models import JSONField from django.core.serializers.json import DjangoJSONEncoder from django.db import models +from django.db.models import JSONField from django.utils.translation import gettext_lazy as _ from .constants import WGS84_SRID diff --git a/parkings/models/permit.py b/parkings/models/permit.py index c9caaf60..17618be6 100644 --- a/parkings/models/permit.py +++ b/parkings/models/permit.py @@ -2,9 +2,9 @@ from django.conf import settings from django.contrib.gis.db import models as gis_models -from django.contrib.postgres.fields import JSONField from django.core.serializers.json import DjangoJSONEncoder from django.db import connections, models, router, transaction +from django.db.models import JSONField from django.db.models.expressions import RawSQL from django.utils import timezone from django.utils.translation import gettext_lazy as _ diff --git a/parkings/tests/api/monitoring/test_valid_parking.py b/parkings/tests/api/monitoring/test_valid_parking.py index 944b6bda..5bff92fd 100644 --- a/parkings/tests/api/monitoring/test_valid_parking.py +++ b/parkings/tests/api/monitoring/test_valid_parking.py @@ -52,7 +52,7 @@ def test_list_endpoint_data(monitoring_api_client, parking): def check_parking_feature_shape(parking_feature): assert set(parking_feature.keys()) == { - 'id', 'type','time_start', 'time_end', 'geometry', 'properties'} + 'id', 'type', 'time_start', 'time_end', 'geometry', 'properties'} assert parking_feature['type'] == 'Feature' assert set(parking_feature['geometry'].keys()) == { 'type', 'coordinates'} diff --git a/parkkihubi/settings.py b/parkkihubi/settings.py index 91813f4d..006c6193 100644 --- a/parkkihubi/settings.py +++ b/parkkihubi/settings.py @@ -1,6 +1,9 @@ import os from datetime import timedelta +import django +from django.utils.encoding import smart_str +from django.utils.translation import gettext, gettext_lazy from environ import Env from raven import fetch_git_sha from raven.exceptions import InvalidGitRepository @@ -8,12 +11,8 @@ # Prevent warning regarding DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' -import django -from django.utils.translation import gettext_lazy django.utils.translation.ugettext_lazy = gettext_lazy -from django.utils.translation import gettext django.utils.translation.ugettext = gettext -from django.utils.encoding import smart_str django.utils.encoding.smart_text = smart_str diff --git a/parkkihubi/urls.py b/parkkihubi/urls.py index 00509e3b..7deec2f8 100644 --- a/parkkihubi/urls.py +++ b/parkkihubi/urls.py @@ -1,6 +1,6 @@ from django.conf import settings -from django.urls import include, re_path from django.contrib import admin +from django.urls import include, re_path from parkings.api.auth import urls as auth_urls from parkings.api.enforcement import urls as enforcement_urls diff --git a/post-update b/post-update index d0c63463..295f239d 100755 --- a/post-update +++ b/post-update @@ -26,8 +26,8 @@ fi # Update the backend pip install -r requirements-pip.txt -pip install -r requirements-prequ.txt -prequ sync requirements.txt +# pip install -r requirements-prequ.txt +# prequ sync requirements.txt ./manage.py collectstatic --noinput diff --git a/requirements-test.txt b/requirements-test.txt index a556aa11..ebd274b2 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -59,7 +59,7 @@ python-dateutil==2.8.2 # freezegun pyyaml==6.0.1 # via -r requirements-test.in -requests==2.24.0 +requests==2.25.1 # via # -c requirements-cov.txt # requests-mock diff --git a/requirements.txt b/requirements.txt index c812a96e..0bc99602 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,7 @@ django-environ==0.4.5 # via -r requirements.in django-filter==2.3.0 # via -r requirements.in -django-sanitized-dump==1.2.1 +django-sanitized-dump==1.2.2 # via -r requirements.in djangorestframework==3.14.0 # via @@ -52,7 +52,7 @@ pyproj==3.3.0 # via # -r requirements.in # owslib -python-dateutil==2.8.1 +python-dateutil==2.8.2 # via owslib python-memcached==1.59 # via -r requirements.in @@ -61,7 +61,7 @@ pytz==2023.3.post1 # -r requirements.in # django # owslib -pyyaml==5.3.1 +pyyaml==6.0.1 # via # database-sanitizer # django-sanitized-dump @@ -72,7 +72,7 @@ requests==2.25.1 # via # -r requirements.in # owslib -six==1.15.0 +six==1.16.0 # via # database-sanitizer # django-sanitized-dump diff --git a/run-pytest b/run-pytest index f5938c62..9e26c03e 100755 --- a/run-pytest +++ b/run-pytest @@ -1,7 +1,7 @@ #!/bin/bash -# Run pytest locally or on docker-compose app service +# Run pytest locally or on docker-compose runserver service # -# When using docker-compose app service, the options passed by VSCodium +# When using docker-compose runserver service, the options passed by VSCodium # will be handled specially to make its pytest integration smoother. # # To run pytest within docker, set USE_DOCKER environment variable to 1 @@ -16,6 +16,14 @@ fi if [[ "$USE_DOCKER" == "1" ]] || [[ "$USE_DOCKER" == "yes" ]]; then docker-compose up -d + # Check if the container is running + container_id=$(docker-compose ps -q) + if [[ -z "$container_id" ]]; then + echo "Error: Container failed to start." + exit 1 + fi + + echo "Container is running with ID: $container_id" else exec pytest "$@" exit $? @@ -23,6 +31,7 @@ fi unset xml_file opts=() + while [[ $# -gt 0 ]]; do opt="$1" shift @@ -44,17 +53,23 @@ docker_compose_exec=("docker-compose" "exec") if ! tty -s; then docker_compose_exec+=("-T") # If there is no TTY available, pass -T fi - +echo "here 0" # Wait until the database is ready -"${docker_compose_exec[@]}" -e RUN_MIGRATIONS=0 app ./docker-entrypoint /bin/true +"${docker_compose_exec[@]}" -e RUN_MIGRATIONS=0 runserver ./docker-entrypoint /bin/true +echo "here 1" set +e -"${docker_compose_exec[@]}" app pytest "${misc_opts[@]}" "${opts[@]}" +output="$("${docker_compose_exec[@]}" runserver pytest "${misc_opts[@]}" "${opts[@]}" 2>&1)" exit_code=$? set -e - +echo "here 2" if [[ -n "$xml_file" ]]; then - "${docker_compose_exec[@]}" app cat /tmp/pytest_junit.xml > "$xml_file" + "${docker_compose_exec[@]}" runserver cat /tmp/pytest_junit.xml > "$xml_file" +fi +echo "here 3" + +if [ $exit_code -ne 0 ]; then + echo "$output" fi exit $exit_code diff --git a/tox.ini b/tox.ini index e409a6d6..1d2acaa3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{35,36,37,38},requirements,style +envlist = py310,requirements,style skipsdist = True [testenv] @@ -12,28 +12,26 @@ setenv = SECRET_KEY=topsecret123 commands = pytest -ra -vvv --strict --doctest-modules \ + --exitfirst \ # DEBUGGING ONLY {posargs:--cov=. --cov-report=term --cov-report=xml} [testenv:requirements] -basepython = python3.5 +basepython = python3.10 deps = -rrequirements-pip.txt - -rrequirements-prequ.txt -commands = prequ {posargs:check -v} +commands = pip {posargs:check} [testenv:style] -basepython = python3.5 +basepython = python3.10 deps = -rrequirements-style.txt commands = flake8 {posargs:--enable=T} [testenv:sanitizer] -basepython = python3.5 +basepython = python3.10 deps = -rrequirements.txt -commands = ./manage.py check_sanitizerconfig +commands = {base_python} manage.py check_sanitizerconfig [gh-actions] python = - 3.5: py35 - 3.6: py36 - 3.8: py38 + 3.10: py310 problem_matcher = False