]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Added minimal Django integration tests.
authorFlorian Apolloner <florian@apolloner.eu>
Sat, 15 Apr 2023 08:13:34 +0000 (10:13 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 3 May 2023 10:11:54 +0000 (12:11 +0200)
.github/workflows/3rd-party-tests.yml

index ea88d9ff7b0f6c2d03bfa776b5fcb29edbb40d85..0a30728c5c9b719fcad12b4e77cc3eabe9ee5bfc 100644 (file)
@@ -5,6 +5,7 @@ on:
     branches:
       - "master"
       - "sqlalchemy_pipeline"
+      - "django_pipeline"
     paths-ignore:
       - "docs/*"
       - "tools/*"
@@ -110,3 +111,131 @@ jobs:
           URL: postgresql+psycopg://postgres:password@127.0.0.1/test
         working-directory: sa_home/sa
         run: pytest -n 2 -q --dburi $URL --backend-only --dropfirst --color=yes
+
+  django:
+    # linux should be enough to test if everything works.
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        django_label:
+          # what version of django to download is defined in the "include" section below,
+          # in the variable pip_django
+          - git_main
+          - lts
+        impl:
+          - c
+          - python
+        include:
+          - django_label: git_main
+            pip_django: git+https://github.com/django/django.git#egg=Django
+            python-version: "3.11"
+          # TODO: Needs updating with new LTS releases, is this something we want?
+          #       Also needs consideration against which python we wanna test.
+          #       Current logic is test oldest in lts and newest in main
+          - django_label: lts
+            pip_django: "'Django>=4.2,<4.3'"
+            python-version: "3.8"
+
+    env:
+      DEPS: ./psycopg
+
+    services:
+      postgresql:
+        image: postgres:15
+        env:
+          POSTGRES_PASSWORD: password
+          POSTGRES_DB: postgres
+        ports:
+          - 5432:5432
+        # Wait until postgres has started
+        options: >-
+          --health-cmd pg_isready
+          --health-interval 10s
+          --health-timeout 5s
+          --health-retries 5
+
+    steps:
+      - uses: actions/checkout@v3
+
+      - uses: actions/setup-python@v4
+        with:
+          python-version: ${{ matrix.python-version }}
+
+      - name: Setup PG
+        env:
+          PGPASSWORD: password
+        run: |
+          psql -AXqte "host=127.0.0.1 dbname=postgres user=postgres" << HERE
+          SELECT version();
+          HERE
+
+      - name: Include psycopg-c to the packages to install
+        if: ${{ matrix.impl == 'c' }}
+        run: |
+          echo "DEPS=$DEPS ./psycopg_c" >> $GITHUB_ENV
+
+      - name: Install pycopg packages
+        run: pip install $DEPS
+
+      - name: Download and configure Django
+        run: |
+          pip download --no-deps --no-binary :all: ${{ matrix.pip_django }}
+          mkdir django_home
+          case $(file --brief --mime-type Django*) in
+            application/gzip)
+              tar -C django_home -xzf Django*
+              ;;
+            application/zip)
+              unzip -d django_home -q Django*
+              ;;
+            *)
+              echo "Unexpected format for $(file --mime-type Django*)" >&2
+              exit 1
+              ;;
+          esac
+          mv django_home/$( ls django_home ) django_home/django
+          cat << HERE > django_home/django/tests/test_postgresql.py
+          DATABASES = {
+              "default": {
+                  "ENGINE": "django.db.backends.postgresql",
+                  "HOST": "127.0.0.1",
+                  "USER": "postgres",
+                  "PASSWORD": "password",
+              },
+              "other": {
+                  "ENGINE": "django.db.backends.postgresql",
+                  "HOST": "127.0.0.1",
+                  "USER": "postgres",
+                  "PASSWORD": "password",
+              },
+          }
+
+          SECRET_KEY = "django_tests_secret_key"
+
+          # Use a fast hasher to speed up tests.
+          PASSWORD_HASHERS = [
+              "django.contrib.auth.hashers.MD5PasswordHasher",
+          ]
+
+          DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
+
+          USE_TZ = False
+          HERE
+
+      - uses: actions/cache@v3
+        with:
+          path: ~/.cache/pip
+          key: ${{ matrix.python-version }}-pip-${{ hashFiles('django_home/django/tests/requirements/py3.txt', 'django_home/django/setup.cfg') }}
+          restore-keys: |
+            ${{ matrix.python-version }}-pip-
+
+      - name: Install Django and dependencies
+        working-directory: django_home/django
+        run: |
+          pip install .
+          pip install -r tests/requirements/py3.txt
+
+      - name: Run Django tests
+        working-directory: django_home/django/tests
+        run: ./runtests.py --settings=test_postgresql postgres_tests backends queries