diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cebe054f..475a64ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,26 +29,12 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - name: Set up backend environment + uses: maykinmedia/setup-django-backend@v1.3 with: + apt-packages: 'libgdal-dev gdal-bin' python-version: '3.11' - - uses: actions/setup-node@v4 - with: - node-version: '18' - - - name: Install system packages - run: | - sudo apt-get update \ - && sudo apt-get install -y --no-install-recommends \ - libgdal-dev \ - gdal-bin - - - name: Install dependencies - run: pip install -r requirements/ci.txt codecov - - name: Build frontend - run: | - npm ci - npm run build + setup-node: true - name: Run tests run: | @@ -61,7 +47,7 @@ jobs: DB_PASSWORD: '' - name: Publish coverage report - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 docs: runs-on: ubuntu-latest @@ -69,19 +55,13 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - name: Set up backend environment + uses: maykinmedia/setup-django-backend@v1.3 with: + apt-packages: 'libgdal-dev gdal-bin' python-version: '3.11' - cache: 'pip' - cache-dependency-path: 'requirements/*.txt' - - name: Install system packages - run: | - sudo apt-get update \ - && sudo apt-get install -y --no-install-recommends \ - libgdal-dev \ - gdal-bin - - name: Install dependencies - run: pip install -r requirements/ci.txt pytest + setup-node: false + - name: Generate environment variable documentation using OAf and check if it was updated run: | bin/generate_envvar_docs.sh @@ -94,81 +74,35 @@ jobs: env: DJANGO_SETTINGS_MODULE: objects.conf.ci - docker: - needs: tests - - name: Build (and push) Docker image + store-reusable-workflow-vars: + name: create values which can be passed through a reusable workflow runs-on: ubuntu-latest + outputs: + image-name: ${{ steps.image-name.outputs.image-name }} steps: - - uses: actions/checkout@v4 - - - name: Set tag - id: vars - run: | - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - - # Strip "v" prefix from tag name (if present at all) - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - - # Use Docker `latest` tag convention - [ "$VERSION" == "master" ] && VERSION=latest - - echo ::set-output name=tag::${VERSION} - - - name: Build the Docker image - env: - RELEASE_VERSION: ${{ steps.vars.outputs.tag }} - run: docker build . --tag $IMAGE_NAME:$RELEASE_VERSION - - - run: docker image save -o image.tar $IMAGE_NAME:${{ steps.vars.outputs.tag }} - - - name: Store image artifact - uses: actions/upload-artifact@v3 - with: - name: docker-image - path: image.tar - retention-days: 1 + - run: echo "image-name=$IMAGE_NAME" >> $GITHUB_OUTPUT + name: 'Store the docker image name' + id: image-name - publish: + open-api-ci: + uses: maykinmedia/open-api-workflows/.github/workflows/ci.yml@v1 + needs: + - store-reusable-workflow-vars + with: + main-branch: 'master' + python-version: '3.11' + docker-image-name: ${{ needs.store-reusable-workflow-vars.outputs.image-name }} + + open-api-publish: + uses: maykinmedia/open-api-workflows/.github/workflows/publish.yml@v1 needs: + - store-reusable-workflow-vars + - open-api-ci - tests - - docker - - name: Push Docker image - runs-on: ubuntu-latest - if: github.event_name == 'push' # exclude PRs - - steps: - - uses: actions/checkout@v4 - - name: Download built image - uses: actions/download-artifact@v3 - with: - name: docker-image - - - name: Determine tag - id: vars - run: | - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - - # Strip "v" prefix from tag name (if present at all) - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - - # Use Docker `latest` tag convention - [ "$VERSION" == "master" ] && VERSION=latest - - echo ::set-output name=tag::${VERSION} - - - name: Load image - run: | - docker image load -i image.tar - - - name: Log into registry - run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin - - - name: Push the Docker image - env: - RELEASE_VERSION: ${{ steps.vars.outputs.tag }} - run: docker push $IMAGE_NAME:$RELEASE_VERSION + with: + docker-image-name: ${{ needs.store-reusable-workflow-vars.outputs.image-name }} + repository-owner: 'maykinmedia' + secrets: + docker-username: ${{ secrets.DOCKER_USERNAME }} + docker-token: ${{ secrets.DOCKER_TOKEN }} diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index a9889071..31856cec 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -1,74 +1,25 @@ name: code-quality -on: [push] +on: + push: + branches: + - master + paths: + - '**.py' + - '**.yml' + pull_request: + paths: + - '**.py' + - '**.yml' + workflow_dispatch: jobs: - isort: - name: Check import sorting - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: isort/isort-action@v1 - with: - requirementsFiles: requirements/dev.txt - sortPaths: "src docs" - configuration: '--check-only --diff' - - black: - name: Check code formatting with black - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - name: Install dependencies - run: | - pip install -r requirements/dev.txt - - name: Run black - run: | - black --check src docs - - oas-up-to-date: - name: Check for unexpected OAS changes - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - uses: actions/setup-node@v4 - with: - node-version: '18' - - - name: Install system packages - run: | - sudo apt-get update \ - && sudo apt-get install -y --no-install-recommends \ - libgdal-dev \ - gdal-bin - - - name: Install dependencies - run: pip install -r requirements/ci.txt - - - name: Generate OAS files - run: ./bin/generate_schema.sh openapi.yaml - env: - DJANGO_SETTINGS_MODULE: objects.conf.ci - - - name: Check for OAS changes - run: | - diff openapi.yaml src/objects/api/v2/openapi.yaml - - name: Write failure markdown - if: ${{ failure() }} - run: | - echo 'Run the following command locally and commit the changes' >> $GITHUB_STEP_SUMMARY - echo '' >> $GITHUB_STEP_SUMMARY - echo '```bash' >> $GITHUB_STEP_SUMMARY - echo './bin/generate_schema.sh' >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY + open-api-workflow-code-quality: + uses: maykinmedia/open-api-workflows/.github/workflows/code-quality.yml@v1 + with: + apt-packages: 'libgdal-dev gdal-bin' + python-version: '3.11' + node-version: '18' + postgres-image: 'postgis/postgis:12-2.5' + + django-settings-module: 'objects.conf.ci' diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9d965905..b87b901a 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -21,52 +21,5 @@ on: - cron: '36 0 * * 0' jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'javascript', 'python' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + open-api-workflow-code-analysis: + uses: maykinmedia/open-api-workflows/.github/workflows/code-analysis.yml@v1 diff --git a/.github/workflows/generate-postman-collection.yml b/.github/workflows/generate-postman-collection.yml index b0bca4ac..1fba3076 100644 --- a/.github/workflows/generate-postman-collection.yml +++ b/.github/workflows/generate-postman-collection.yml @@ -10,19 +10,12 @@ on: workflow_dispatch: jobs: - run: - runs-on: ubuntu-latest - name: Generate Postman collection - - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: '18' - - name: Install dependencies - run: npm install -g openapi-to-postmanv2 - - name: Create tests folder - run: mkdir -p ./tests/postman - - name: Generate Postman collection - run: openapi2postmanv2 -s ./src/objects/api/v2/openapi.yaml -o ./tests/postman/collection.json --pretty + open-api-workflow-generate-postman-collection: + uses: maykinmedia/open-api-workflows/.github/workflows/generate-postman-collection.yml@v1 + strategy: + matrix: + version: + - v2 + with: + node-version: '18' + schema-path: 'src/objects/api/${{ matrix.version }}/openapi.yaml' diff --git a/.github/workflows/generate-sdks.yml b/.github/workflows/generate-sdks.yml index 959a9c25..cd943333 100644 --- a/.github/workflows/generate-sdks.yml +++ b/.github/workflows/generate-sdks.yml @@ -10,32 +10,12 @@ on: workflow_dispatch: jobs: - run: - runs-on: ubuntu-latest - name: Generate SDKs - - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: '18' - - name: Install dependencies - run: npm install -g @openapitools/openapi-generator-cli - - name: Determing oas path - id: vars - run: echo ::set-output name=oas::./src/objects/api/v2/openapi.yaml - - name: Validate schema - run: openapi-generator-cli validate -i ${{ steps.vars.outputs.oas }} - - name: Generate Java client - run: openapi-generator-cli generate -i ${{ steps.vars.outputs.oas }} --global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ - -o ./sdks/java -g java --additional-properties=dateLibrary=java8,java8=true,optionalProjectFile=false,optionalAssemblyInfo=false -# - name: Generate .NET Core client -# run: openapi-generator-cli generate -i ${{ steps.vars.outputs.oas }} --global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ -# -o ./sdks/netcore -g csharp-netcore --additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false -# - name: Generate .NET Full Framework client -# run: openapi-generator-cli generate -i ${{ steps.vars.outputs.oas }} --global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ -# -o ./sdks/net -g csharp --additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false - - name: Generate Python client - run: openapi-generator-cli generate -i ${{ steps.vars.outputs.oas }} --global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ - -o ./sdks/python -g python --additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false+ + open-api-workflow-generate-sdks: + uses: maykinmedia/open-api-workflows/.github/workflows/generate-sdks.yml@v1 + strategy: + matrix: + version: + - v2 + with: + node-version: '18' + schema-path: 'src/objects/api/${{ matrix.version }}/openapi.yaml' diff --git a/.github/workflows/lint-oas.yml b/.github/workflows/lint-oas.yml index 850478e3..cffa24a6 100644 --- a/.github/workflows/lint-oas.yml +++ b/.github/workflows/lint-oas.yml @@ -10,17 +10,12 @@ on: workflow_dispatch: jobs: - run: - runs-on: ubuntu-latest - name: Lint OAS - - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: '18' - - name: Install spectral - run: npm install -g @stoplight/spectral@5 - - name: Run OAS linter - run: spectral lint ./src/objects/api/v2/openapi.yaml + open-api-workflow-lint-oas: + uses: maykinmedia/open-api-workflows/.github/workflows/lint-oas.yml@v1 + strategy: + matrix: + version: + - v2 + with: + node-version: '18' + schema-path: 'src/objects/api/${{ matrix.version }}/openapi.yaml' diff --git a/.github/workflows/oas-check.yml b/.github/workflows/oas-check.yml new file mode 100644 index 00000000..334ca86f --- /dev/null +++ b/.github/workflows/oas-check.yml @@ -0,0 +1,24 @@ +name: check-oas + +on: + push: + paths: + - "src/objects/api/*/openapi.yaml" + - .github/workflows/oas-check.yml + branches: + - '**' + workflow_dispatch: + +jobs: + open-api-workflow-check-oas: + uses: maykinmedia/open-api-workflows/.github/workflows/oas-check.yml@v1 + strategy: + matrix: + version: + - v2 + with: + schema-path: 'src/objects/api/${{ matrix.version }}/openapi.yaml' + schema-options: "--api-version ${{ matrix.version }}" + python-version: '3.11' + django-settings-module: 'objects.conf.ci' + apt-packages: 'libgdal-dev gdal-bin' diff --git a/bin/compile_dependencies.bat b/bin/compile_dependencies.bat index ece1920f..08293fb5 100644 --- a/bin/compile_dependencies.bat +++ b/bin/compile_dependencies.bat @@ -16,12 +16,14 @@ pip-compile^ --output-file requirements/ci.txt^ %*^ requirements/base.txt^ - requirements/test-tools.in + requirements/test-tools.in^ + requirements/ci.in -REM Dev depedencies - exact same set as CI + some extra tooling +REM Dev depedencies pip-compile^ --no-emit-index-url^ --output-file requirements/dev.txt^ %*^ - requirements/ci.txt^ + requirements/base.txt^ + requirements/test-tools.in^ requirements/dev.in diff --git a/bin/compile_dependencies.sh b/bin/compile_dependencies.sh index bfd27062..829b73c9 100755 --- a/bin/compile_dependencies.sh +++ b/bin/compile_dependencies.sh @@ -31,12 +31,14 @@ pip-compile \ --output-file requirements/ci.txt \ "$@" \ requirements/base.txt \ - requirements/test-tools.in + requirements/test-tools.in \ + requirements/ci.in -# Dev depedencies - exact same set as CI + some extra tooling +# Dev depedencies pip-compile \ --no-emit-index-url \ --output-file requirements/dev.txt \ "$@" \ - requirements/ci.txt \ + requirements/base.txt \ + requirements/test-tools.in \ requirements/dev.in diff --git a/requirements/ci.in b/requirements/ci.in new file mode 100644 index 00000000..76375907 --- /dev/null +++ b/requirements/ci.in @@ -0,0 +1,2 @@ +codecov +pytest diff --git a/requirements/ci.txt b/requirements/ci.txt index be1aa5b3..0222dfeb 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.11 # by the following command: # -# pip-compile --no-emit-index-url --output-file=requirements/ci.txt requirements/base.txt requirements/test-tools.in +# pip-compile --no-emit-index-url --output-file=requirements/ci.txt requirements/base.txt requirements/ci.in requirements/test-tools.in # amqp==5.2.0 # via @@ -33,6 +33,8 @@ billiard==4.2.0 # via # -r requirements/base.txt # celery +black==24.8.0 + # via -r requirements/test-tools.in bleach==6.1.0 # via # -r requirements/base.txt @@ -70,6 +72,7 @@ charset-normalizer==3.3.2 click==8.1.7 # via # -r requirements/base.txt + # black # celery # click-didyoumean # click-plugins @@ -86,6 +89,8 @@ click-repl==0.3.0 # via # -r requirements/base.txt # celery +codecov==2.1.13 + # via -r requirements/ci.in commonground-api-common==1.13.0 # via # -r requirements/base.txt @@ -99,7 +104,9 @@ coreschema==0.0.4 # -r requirements/base.txt # coreapi coverage==4.5.4 - # via -r requirements/test-tools.in + # via + # -r requirements/test-tools.in + # codecov cryptography==42.0.4 # via # -r requirements/base.txt @@ -299,6 +306,8 @@ factory-boy==3.2.0 # via -r requirements/test-tools.in faker==8.1.0 # via factory-boy +flake8==7.1.1 + # via -r requirements/test-tools.in flower==2.0.1 # via # -r requirements/base.txt @@ -333,6 +342,8 @@ inflection==0.5.1 # -r requirements/base.txt # drf-spectacular # drf-yasg +iniconfig==2.0.0 + # via pytest iso-639==0.4.5 # via # -r requirements/base.txt @@ -341,6 +352,8 @@ isodate==0.6.0 # via # -r requirements/base.txt # commonground-api-common +isort==5.13.2 + # via -r requirements/test-tools.in itypes==1.2.0 # via # -r requirements/base.txt @@ -371,6 +384,8 @@ maykin-2fa==1.0.1 # via # -r requirements/base.txt # open-api-framework +mccabe==0.7.0 + # via flake8 mozilla-django-oidc==4.0.0 # via # -r requirements/base.txt @@ -381,6 +396,8 @@ mozilla-django-oidc-db==0.19.0 # open-api-framework multidict==6.0.5 # via yarl +mypy-extensions==1.0.0 + # via black notifications-api-common==0.2.2 # via # -r requirements/base.txt @@ -398,11 +415,19 @@ oyaml==1.0 packaging==23.2 # via # -r requirements/base.txt + # black # drf-yasg + # pytest +pathspec==0.12.1 + # via black phonenumberslite==8.13.30 # via # -r requirements/base.txt # django-two-factor-auth +platformdirs==4.3.3 + # via black +pluggy==1.5.0 + # via pytest prometheus-client==0.20.0 # via # -r requirements/base.txt @@ -415,10 +440,14 @@ psycopg2==2.9.9 # via # -r requirements/base.txt # open-api-framework +pycodestyle==2.12.1 + # via flake8 pycparser==2.20 # via # -r requirements/base.txt # cffi +pyflakes==3.2.0 + # via flake8 pyjwt==2.4.0 # via # -r requirements/base.txt @@ -437,6 +466,8 @@ pyrsistent==0.17.3 # via # -r requirements/base.txt # jsonschema +pytest==8.3.3 + # via -r requirements/ci.in python-dateutil==2.9.0.post0 # via # -r requirements/base.txt @@ -477,6 +508,7 @@ requests==2.32.3 # via # -r requirements/base.txt # ape-pie + # codecov # commonground-api-common # coreapi # django-log-outgoing-requests diff --git a/requirements/dev.in b/requirements/dev.in index 952e6545..b0491726 100644 --- a/requirements/dev.in +++ b/requirements/dev.in @@ -2,11 +2,6 @@ pip-tools bumpversion -# Code formatting -black -isort -flake8 - # Debug tooling django-debug-toolbar django-extensions diff --git a/requirements/dev.txt b/requirements/dev.txt index 8d3f0aff..7e03d906 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -2,52 +2,50 @@ # This file is autogenerated by pip-compile with Python 3.11 # by the following command: # -# pip-compile --no-emit-index-url --output-file=requirements/dev.txt requirements/ci.txt requirements/dev.in +# pip-compile --no-emit-index-url --output-file=requirements/dev.txt requirements/base.txt requirements/dev.in requirements/test-tools.in # alabaster==0.7.12 # via sphinx amqp==5.2.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # kombu ape-pie==0.2.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # zgw-consumers asgiref==3.7.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django # django-axes # django-cors-headers asn1crypto==1.5.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # webauthn attrs==20.3.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # glom # jsonschema babel==2.9.1 # via sphinx beautifulsoup4==4.9.3 - # via - # -r requirements/ci.txt - # webtest + # via webtest billiard==4.2.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # celery black==24.3.0 - # via -r requirements/dev.in + # via -r requirements/test-tools.in bleach==6.1.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework boltons==21.0.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # face # glom build==1.0.3 @@ -58,32 +56,32 @@ bumpversion==0.6.0 # via -r requirements/dev.in cbor2==5.6.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # webauthn celery==5.4.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # flower # notifications-api-common # open-api-framework certifi==2024.7.4 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-simple-certmanager # elastic-apm # requests # sentry-sdk cffi==1.16.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # cryptography charset-normalizer==3.3.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # requests click==8.1.7 # via - # -r requirements/ci.txt + # -r requirements/base.txt # black # celery # click-didyoumean @@ -92,47 +90,45 @@ click==8.1.7 # pip-tools click-didyoumean==0.3.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # celery click-plugins==1.1.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # celery click-repl==0.3.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # celery commonground-api-common==1.13.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework commonmark==0.9.1 # via recommonmark coreapi==2.3.3 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common coreschema==0.0.4 # via - # -r requirements/ci.txt + # -r requirements/base.txt # coreapi coverage==4.5.4 - # via -r requirements/ci.txt + # via -r requirements/test-tools.in cryptography==42.0.4 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-simple-certmanager # josepy # mozilla-django-oidc # pyopenssl # webauthn cssselect==1.1.0 - # via - # -r requirements/ci.txt - # pyquery + # via pyquery django==4.2.15 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common # django-admin-index # django-appconf @@ -171,23 +167,23 @@ django==4.2.15 # zgw-consumers django-admin-index==3.1.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework django-appconf==1.0.6 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-log-outgoing-requests django-axes==6.5.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework django-cors-headers==4.4.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework django-csp==3.8 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework django-debug-toolbar==4.2.0 # via -r requirements/dev.in @@ -195,69 +191,69 @@ django-extensions==3.2.3 # via -r requirements/dev.in django-filter==24.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common # open-api-framework django-formtools==2.3 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-two-factor-auth django-jsonform==2.22.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # mozilla-django-oidc-db # open-api-framework django-log-outgoing-requests==0.6.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework django-markup==1.8.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework django-ordered-model==3.7.4 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-admin-index django-otp==1.0.6 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-two-factor-auth django-phonenumber-field==5.2.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-two-factor-auth django-privates==2.0.0.post0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-simple-certmanager django-redis==5.4.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework django-relativedelta==2.0.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # zgw-consumers django-rest-framework-condition==0.1.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common django-sendfile2==0.7.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-privates django-setup-configuration==0.1.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework django-simple-certmanager==1.4.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # zgw-consumers django-solo==2.2.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common # django-log-outgoing-requests # mozilla-django-oidc-db @@ -265,13 +261,13 @@ django-solo==2.2.0 # zgw-consumers django-two-factor-auth[phonenumberslite,webauthn]==1.17.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # maykin-2fa django-webtest==1.9.7 - # via -r requirements/ci.txt + # via -r requirements/test-tools.in djangorestframework==3.15.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common # djangorestframework-gis # djangorestframework-inclusions @@ -282,16 +278,16 @@ djangorestframework==3.15.2 # open-api-framework djangorestframework-camel-case==1.4.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common # notifications-api-common djangorestframework-gis==1.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework djangorestframework-inclusions==1.2.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework docutils==0.18.1 # via @@ -301,152 +297,146 @@ docutils==0.18.1 # sphinx-tabs drf-nested-routers==0.93.3 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common drf-spectacular[sidecar]==0.27.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework drf-spectacular-sidecar==2024.7.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # drf-spectacular drf-yasg==1.21.7 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common ecs-logging==2.1.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # elastic-apm elastic-apm==6.23.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework face==20.1.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # glom factory-boy==3.2.0 - # via -r requirements/ci.txt + # via -r requirements/test-tools.in faker==8.1.0 - # via - # -r requirements/ci.txt - # factory-boy + # via factory-boy flake8==7.0.0 - # via -r requirements/dev.in + # via -r requirements/test-tools.in flower==2.0.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework freezegun==1.1.0 - # via -r requirements/ci.txt + # via -r requirements/test-tools.in furl==2.1.3 # via - # -r requirements/ci.txt + # -r requirements/base.txt # ape-pie gemma-zds-client==2.0.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common # notifications-api-common # zgw-consumers glom==23.5.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # mozilla-django-oidc-db humanize==4.9.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # flower idna==3.7 # via - # -r requirements/ci.txt + # -r requirements/base.txt # requests # yarl imagesize==1.4.1 # via sphinx inflection==0.5.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # drf-spectacular # drf-yasg iso-639==0.4.5 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common isodate==0.6.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common isort==5.13.2 - # via -r requirements/dev.in + # via -r requirements/test-tools.in itypes==1.2.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # coreapi jinja2==3.1.4 # via - # -r requirements/ci.txt + # -r requirements/base.txt # coreschema # sphinx josepy==1.9.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # mozilla-django-oidc jsonschema==4.17.3 # via - # -r requirements/ci.txt + # -r requirements/base.txt # drf-spectacular kombu==5.3.5 # via - # -r requirements/ci.txt + # -r requirements/base.txt # celery lxml==4.9.4 - # via - # -r requirements/ci.txt - # pyquery + # via pyquery markupsafe==2.1.3 # via - # -r requirements/ci.txt + # -r requirements/base.txt # jinja2 maykin-2fa==1.0.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework mccabe==0.7.0 # via flake8 mozilla-django-oidc==4.0.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # mozilla-django-oidc-db mozilla-django-oidc-db==0.19.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework multidict==6.0.5 - # via - # -r requirements/ci.txt - # yarl + # via yarl mypy-extensions==0.4.3 # via black notifications-api-common==0.2.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common open-api-framework==0.8.1 - # via -r requirements/ci.txt + # via -r requirements/base.txt orderedmultidict==1.0.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # furl oyaml==1.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common packaging==23.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # black # build # drf-yasg @@ -455,7 +445,7 @@ pathspec==0.11.2 # via black phonenumberslite==8.13.30 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-two-factor-auth pip-tools==7.4.1 # via -r requirements/dev.in @@ -463,21 +453,21 @@ platformdirs==4.0.0 # via black prometheus-client==0.20.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # flower prompt-toolkit==3.0.43 # via - # -r requirements/ci.txt + # -r requirements/base.txt # click-repl psycopg2==2.9.9 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework pycodestyle==2.11.1 # via flake8 pycparser==2.20 # via - # -r requirements/ci.txt + # -r requirements/base.txt # cffi pyflakes==3.2.0 # via flake8 @@ -487,12 +477,12 @@ pygments==2.17.2 # sphinx-tabs pyjwt==2.4.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # commonground-api-common # gemma-zds-client pyopenssl==24.0.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-simple-certmanager # josepy # webauthn @@ -502,35 +492,35 @@ pyproject-hooks==1.0.0 # build # pip-tools pyquery==1.4.3 - # via -r requirements/ci.txt + # via -r requirements/test-tools.in pyrsistent==0.17.3 # via - # -r requirements/ci.txt + # -r requirements/base.txt # jsonschema python-dateutil==2.9.0.post0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # celery # django-relativedelta # faker # freezegun python-decouple==3.8 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework python-dotenv==1.0.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework pytz==2024.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # babel # drf-yasg # flower pyyaml==6.0.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # drf-spectacular # drf-yasg # gemma-zds-client @@ -538,17 +528,17 @@ pyyaml==6.0.1 # vcrpy qrcode==6.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-two-factor-auth recommonmark==0.7.1 # via -r requirements/dev.in redis==3.5.3 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-redis requests==2.32.3 # via - # -r requirements/ci.txt + # -r requirements/base.txt # ape-pie # commonground-api-common # coreapi @@ -560,14 +550,14 @@ requests==2.32.3 # sphinx # zgw-consumers requests-mock==1.8.0 - # via -r requirements/ci.txt + # via -r requirements/test-tools.in sentry-sdk==2.12.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework six==1.16.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # bleach # furl # isodate @@ -579,9 +569,7 @@ six==1.16.0 snowballstemmer==2.1.0 # via sphinx soupsieve==2.2.1 - # via - # -r requirements/ci.txt - # beautifulsoup4 + # via beautifulsoup4 sphinx==7.1.2 # via # -r requirements/dev.in @@ -609,89 +597,79 @@ sphinxcontrib-serializinghtml==1.1.5 # via sphinx sqlparse==0.5.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django # django-debug-toolbar tblib==1.7.0 - # via -r requirements/ci.txt + # via -r requirements/test-tools.in text-unidecode==1.3 - # via - # -r requirements/ci.txt - # faker + # via faker tornado==6.4.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # flower typing-extensions==4.9.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # mozilla-django-oidc-db tzdata==2024.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # celery uritemplate==3.0.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # coreapi # drf-spectacular # drf-yasg urllib3==2.2.2 # via - # -r requirements/ci.txt + # -r requirements/base.txt # elastic-apm # requests # sentry-sdk uwsgi==2.0.23 # via - # -r requirements/ci.txt + # -r requirements/base.txt # open-api-framework vcrpy==6.0.1 - # via -r requirements/ci.txt + # via -r requirements/test-tools.in vine==5.1.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # amqp # celery # kombu waitress==2.1.2 - # via - # -r requirements/ci.txt - # webtest + # via webtest wcwidth==0.2.13 # via - # -r requirements/ci.txt + # -r requirements/base.txt # prompt-toolkit webauthn==2.0.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # django-two-factor-auth webencodings==0.5.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # bleach webob==1.8.8 - # via - # -r requirements/ci.txt - # webtest + # via webtest webtest==2.0.35 - # via - # -r requirements/ci.txt - # django-webtest + # via django-webtest wheel==0.42.0 # via pip-tools wrapt==1.14.1 # via - # -r requirements/ci.txt + # -r requirements/base.txt # elastic-apm # vcrpy yarl==1.9.4 - # via - # -r requirements/ci.txt - # vcrpy + # via vcrpy zgw-consumers==0.29.0 # via - # -r requirements/ci.txt + # -r requirements/base.txt # notifications-api-common # open-api-framework diff --git a/requirements/test-tools.in b/requirements/test-tools.in index e9d49af0..9af8e834 100644 --- a/requirements/test-tools.in +++ b/requirements/test-tools.in @@ -7,3 +7,8 @@ pyquery # integrates with webtest requests-mock tblib vcrpy + +# Code formatting +black +isort +flake8 diff --git a/setup.cfg b/setup.cfg index a2ec2f83..91adacab 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,8 @@ -[pycodestyle] -ignore=W293,W291,E501,E261 -max-line-length=88 -exclude=migrations,static,media +[flake8] +; absolute maximum - more lenient than black's 88 +max-line-length = 119 +ignore = E121,E123,E126,E226,E24,E704,W503,W504,E231,F405,E203 +exclude = migrations,static,media [isort] profile = black diff --git a/src/objects/api/serializers.py b/src/objects/api/serializers.py index 054e1371..f6221636 100644 --- a/src/objects/api/serializers.py +++ b/src/objects/api/serializers.py @@ -126,7 +126,7 @@ def create(self, validated_data): @transaction.atomic def update(self, instance, validated_data): # object_data is not used since all object attributes are immutable - object_data = validated_data.pop("object", None) + validated_data.pop("object", None) validated_data["object"] = instance.object # version should be set if "version" not in validated_data: diff --git a/src/objects/api/v2/openapi.yaml b/src/objects/api/v2/openapi.yaml index 8dc2885b..a3274cbd 100644 --- a/src/objects/api/v2/openapi.yaml +++ b/src/objects/api/v2/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.3 info: title: Objects API - version: 2.4.3 + version: 2.4.3 (v2) description: | An API to manage Objects. diff --git a/src/objects/config/objecttypes.py b/src/objects/config/objecttypes.py index c0e52b9e..919fdff7 100644 --- a/src/objects/config/objecttypes.py +++ b/src/objects/config/objecttypes.py @@ -56,4 +56,4 @@ def test_configuration(self) -> None: try: response.json() except requests.exceptions.JSONDecodeError: - raise SelfTestFailed(f"Object type version didn't have any data") + raise SelfTestFailed("Object type version didn't have any data") diff --git a/src/objects/core/models.py b/src/objects/core/models.py index 1a9e08a6..ccf4fd36 100644 --- a/src/objects/core/models.py +++ b/src/objects/core/models.py @@ -51,7 +51,7 @@ def clean(self): try: object_type_data = response.json() except requests.exceptions.JSONDecodeError: - ValidationError(f"Object type version didn't have any data") + ValidationError("Object type version didn't have any data") if not self._name: self._name = object_type_data["name"] diff --git a/src/objects/tests/commands/test_setup_configuration.py b/src/objects/tests/commands/test_setup_configuration.py index 6c4277c5..d8554a31 100644 --- a/src/objects/tests/commands/test_setup_configuration.py +++ b/src/objects/tests/commands/test_setup_configuration.py @@ -59,7 +59,7 @@ def test_setup_configuration(self, m): f"{ObjecttypesStep()} is successfully configured", f"Configuring {DemoUserStep()}...", f"{DemoUserStep()} is successfully configured", - f"Instance configuration completed.", + "Instance configuration completed.", ] self.assertEqual(command_output, expected_output) diff --git a/src/objects/tests/config/test_objecttypes_configuration.py b/src/objects/tests/config/test_objecttypes_configuration.py index 95fee463..37f8c336 100644 --- a/src/objects/tests/config/test_objecttypes_configuration.py +++ b/src/objects/tests/config/test_objecttypes_configuration.py @@ -1,5 +1,3 @@ -from unittest.mock import patch - from django.test import TestCase, override_settings import requests diff --git a/src/objects/tests/v2/test_filters.py b/src/objects/tests/v2/test_filters.py index 186cf0ea..f0e6eaa1 100644 --- a/src/objects/tests/v2/test_filters.py +++ b/src/objects/tests/v2/test_filters.py @@ -366,7 +366,7 @@ def test_filter_exclude_old_records(self): start_at=date.today() - timedelta(days=10), end_at=date.today() - timedelta(days=1), ) - record_new = ObjectRecordFactory.create( + ObjectRecordFactory.create( data={"diameter": 50}, object=record_old.object, start_at=record_old.end_at ) @@ -378,7 +378,7 @@ def test_filter_exclude_old_records(self): self.assertEqual(len(data), 0) def test_filter_date_field_gte(self): - record = ObjectRecordFactory.create( + ObjectRecordFactory.create( data={"dateField": "2000-10-10"}, object__object_type=self.object_type ) @@ -445,7 +445,7 @@ def test_filter_date_detail(self): record1 = ObjectRecordFactory.create( object=object, start_at="2020-01-01", end_at="2020-12-31" ) - record2 = ObjectRecordFactory.create(object=object, start_at="2021-01-01") + ObjectRecordFactory.create(object=object, start_at="2021-01-01") url = reverse_lazy("object-detail", args=[object.uuid]) @@ -459,7 +459,7 @@ def test_filter_date_detail(self): def test_filter_date_detail_no_actual_record(self): object = ObjectFactory.create(object_type=self.object_type) - record = ObjectRecordFactory.create(object=object, start_at="2021-01-01") + ObjectRecordFactory.create(object=object, start_at="2021-01-01") url = reverse_lazy("object-detail", args=[object.uuid]) @@ -473,9 +473,9 @@ def test_filter_date_list(self): record11 = ObjectRecordFactory.create( object=object1, start_at="2020-01-01", end_at="2020-12-31" ) - record12 = ObjectRecordFactory.create(object=object1, start_at="2021-01-01") + ObjectRecordFactory.create(object=object1, start_at="2021-01-01") # object 2 - don't show - record21 = ObjectRecordFactory.create( + ObjectRecordFactory.create( object__object_type=self.object_type, start_at="2021-01-01" ) @@ -498,9 +498,7 @@ def test_filter_registration_date_detail(self): object=object, registration_at="2020-01-01", ) - record2 = ObjectRecordFactory.create( - object=object, registration_at="2021-01-01" - ) + ObjectRecordFactory.create(object=object, registration_at="2021-01-01") url = reverse_lazy("object-detail", args=[object.uuid]) @@ -514,7 +512,7 @@ def test_filter_registration_date_detail(self): def test_filter_registration_date_detail_no_record(self): object = ObjectFactory.create(object_type=self.object_type) - record = ObjectRecordFactory.create(object=object, registration_at="2021-01-01") + ObjectRecordFactory.create(object=object, registration_at="2021-01-01") url = reverse_lazy("object-detail", args=[object.uuid]) @@ -528,11 +526,9 @@ def test_filter_registration_date_list(self): record11 = ObjectRecordFactory.create( object=object1, registration_at="2020-01-01" ) - record12 = ObjectRecordFactory.create( - object=object1, registration_at="2021-01-01" - ) + ObjectRecordFactory.create(object=object1, registration_at="2021-01-01") # object 2 - don't show - record21 = ObjectRecordFactory.create( + ObjectRecordFactory.create( object__object_type=self.object_type, registration_at="2021-01-01" ) diff --git a/src/objects/tests/v2/test_object_api.py b/src/objects/tests/v2/test_object_api.py index bb160368..c80c6696 100644 --- a/src/objects/tests/v2/test_object_api.py +++ b/src/objects/tests/v2/test_object_api.py @@ -48,7 +48,7 @@ def test_list_actual_objects(self, m): object__object_type=self.object_type, start_at=date.today(), ) - object_record2 = ObjectRecordFactory.create( + ObjectRecordFactory.create( object__object_type=self.object_type, start_at=date.today() - timedelta(days=10), end_at=date.today() - timedelta(days=1), diff --git a/src/objects/tests/v2/test_stuf.py b/src/objects/tests/v2/test_stuf.py index f601f4fe..5c1cdfb2 100644 --- a/src/objects/tests/v2/test_stuf.py +++ b/src/objects/tests/v2/test_stuf.py @@ -24,7 +24,7 @@ class Stuf21Tests(TokenAuthMixin, APITestCase): - """ + """# noqa Test cases based on the Table 2.1 in the StUF 03.01 |PersoonsId|volgnummer|geslachtsnaam|voorvoegsel|voorletters|geboortedatum|burgerlijkestaat|beginGeldigheid| |----------|----------|-------------|-----------|-----------|-------------|----------------|---------------| @@ -103,7 +103,7 @@ def test_2a_2_records_found(self): Test 2a: If records 1 and 40 exists, material history and formal history on 01-01-2020 should say: Record 40 """ - record_1 = ObjectRecordFactory.create( + ObjectRecordFactory.create( object=self.object, data={ "geslachtsnaam": "Poepenstaart", @@ -177,7 +177,7 @@ def test_3a_3_records_found(self): Test 3a: If records 1, 40 and 50 exists, material history and formal history on 01-01-2020 should say: Record 50 """ - record_1 = ObjectRecordFactory.create( + ObjectRecordFactory.create( object=self.object, data={ "geslachtsnaam": "Poepenstaart", @@ -189,7 +189,7 @@ def test_3a_3_records_found(self): end_at=date(2001, 9, 3), registration_at=date(1977, 8, 7), ) - record_40 = ObjectRecordFactory.create( + ObjectRecordFactory.create( object=self.object, data={ "geslachtsnaam": "Bergh", @@ -274,7 +274,7 @@ def test_3b_3_records_not_found(self): class Stuf22Tests(TokenAuthMixin, APITestCase): - """ + """# noqa Test cases based on the Table 2.2 in the StUF 03.01 |PersoonsId|volgnummer|geslachtsnaam|voorvoegsel|voorletters|geboortedatum|burgerlijkestaat|beginGeldigheid|tijdstipRegistratie| |----------|----------|-------------|-----------|-----------|-------------|----------------|---------------|-------------------| @@ -403,7 +403,7 @@ def test_4d_not_found(self): class Stuf23Tests(TokenAuthMixin, APITestCase): - """ + """# noqa Test cases based on the Table 2.2 in the StUF 03.01 |PersoonsId|volgnummer|geslachtsnaam|voorvoegsel|voorletters|geboortedatum|burgerlijkestaat|beginGeldigheid|tijdstipRegistratie|volgnrNaCorrectie| |----------|----------|-------------|-----------|-----------|-------------|----------------|---------------|-------------------|-----------------|