Skip to content

Commit

Permalink
test: add mysql 8 tests (#36)
Browse files Browse the repository at this point in the history
* chore: add tests for mysql 8

* chore: ci allow tests for `feat/*` branches

* chore: fix typo

* chore: add env to tests

* docs: remove official python 3.7 support
  • Loading branch information
OrbisK authored Nov 15, 2024
1 parent 4111b5d commit bcd5543
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 13 deletions.
28 changes: 25 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ on:
workflow_dispatch:
inputs:
version:
description: Version to publish (3.7, 3.8, all,...) (only one)
description: Version to publish (3.8, all,...) (only one)
required: true
push:
branches:
- 'main'
- 'feature/*'
- 'feat/*'

jobs:
build:
Expand All @@ -21,6 +22,12 @@ jobs:
MYSQL_PASSWORD: password
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_PORT: 33061
MYSQL_8_HOST: 127.0.0.1
MYSQL_8_DATABASE: test_db
MYSQL_8_USER: test_user
MYSQL_8_PASSWORD: password
MYSQL_8_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_8_PORT: 33063
MARIADB_HOST: 127.0.0.1
MARIADB_DATABASE: test_db
MARIADB_USER: test_user
Expand Down Expand Up @@ -65,6 +72,17 @@ jobs:
ports:
- 33061:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
mysql-8:
image: mysql:8
env:
MYSQL_ALLOW_EMPTY_PASSWORD: ${{env.MYSQL_8_ALLOW_EMPTY_PASSWORD}}
MYSQL_USER: ${{env.MYSQL_8_USER}}
MYSQL_PASSWORD: ${{env.MYSQL_8_PASSWORD}}
MYSQL_ROOT_PASSWORD: ${{env.MYSQL_8_ROOT_PASSWORD}}
MYSQL_DATABASE: ${{env.MYSQL_8_DATABASE}}
ports:
- 33063:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
mariadb:
image: mariadb
env:
Expand Down Expand Up @@ -92,7 +110,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: [ "3.7","3.8","3.9","3.10","3.11","3.12","3.13" ]
version: [ "3.8","3.9","3.10","3.11","3.12","3.13" ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down Expand Up @@ -123,14 +141,18 @@ jobs:
if: steps.changes.outputs.src == 'true' || steps.changes.outputs.docker == 'true' || github.event.inputs.version == 'all' || github.event.inputs.version == matrix.version
run: |
echo "GRANT ALL on *.* to '${{env.MYSQL_USER}}';"| mysql -u root -h ${{env.MYSQL_HOST}} --port=${{env.MYSQL_PORT}}
- name: Mysql 8 Grant
if: steps.changes.outputs.src == 'true' || steps.changes.outputs.docker == 'true' || github.event.inputs.version == 'all' || github.event.inputs.version == matrix.version
run: |
echo "GRANT ALL on *.* to '${{env.MYSQL_8_USER}}';"| mysql -u root -h ${{env.MYSQL_8_HOST}} --port=${{env.MYSQL_8_PORT}}
- name: MariaDB Grant
if: steps.changes.outputs.src == 'true' || steps.changes.outputs.docker == 'true' || github.event.inputs.version == 'all' || github.event.inputs.version == matrix.version
run: |
echo "GRANT ALL on *.* to '${{env.MARIADB_USER}}';"| mysql -u root -h ${{env.MARIADB_HOST}} --port=${{env.MARIADB_PORT}}
- name: Test Databases
if: steps.changes.outputs.src == 'true' || steps.changes.outputs.docker == 'true' || github.event.inputs.version == 'all' || github.event.inputs.version == matrix.version
run: |
docker run --network host -v /"$(pwd)/tests":/app -w /app -e MYSQL_HOST=$MYSQL_HOST -e MYSQL_DATABASE=$MYSQL_DATABASE -e MYSQL_USER=$MYSQL_USER -e MYSQL_PORT=$MYSQL_PORT -e MYSQL_PASSWORD=$MYSQL_PASSWORD -e MARIADB_HOST=$MARIADB_HOST -e MARIADB_DATABASE=$MARIADB_DATABASE -e MARIADB_USER=$MARIADB_USER -e MARIADB_PORT=$MARIADB_PORT -e MARIADB_PASSWORD=$MARIADB_PASSWORD -e POSTGRES_HOST=$POSTGRES_HOST -e POSTGRES_DB=$POSTGRES_DB -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PORT=$POSTGRES_PORT -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e MSSQL_HOST -e MSSQL_PORT -e MSSQL_DATABASE -e MSSQL_USER -e MSSQL_PASSWORD orbisk/django-test:${{env.PYTHON_VERSION}} sh -c "cd /app && pip install -r requirements.txt && python manage.py test"
docker run --network host -v /"$(pwd)/tests":/app -w /app -e MYSQL_HOST=$MYSQL_HOST -e MYSQL_DATABASE=$MYSQL_DATABASE -e MYSQL_USER=$MYSQL_USER -e MYSQL_PORT=$MYSQL_PORT -e MYSQL_PASSWORD=$MYSQL_PASSWORD -e MYSQL_8_HOST=$MYSQL_8_HOST -e MYSQL_8_DATABASE=$MYSQL_8_DATABASE -e MYSQL_8_USER=$MYSQL_8_USER -e MYSQL_8_PORT=$MYSQL_8_PORT -e MYSQL_8_PASSWORD=$MYSQL_8_PASSWORD -e MARIADB_HOST=$MARIADB_HOST -e MARIADB_DATABASE=$MARIADB_DATABASE -e MARIADB_USER=$MARIADB_USER -e MARIADB_PORT=$MARIADB_PORT -e MARIADB_PASSWORD=$MARIADB_PASSWORD -e POSTGRES_HOST=$POSTGRES_HOST -e POSTGRES_DB=$POSTGRES_DB -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PORT=$POSTGRES_PORT -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e MSSQL_HOST -e MSSQL_PORT -e MSSQL_DATABASE -e MSSQL_USER -e MSSQL_PASSWORD orbisk/django-test:${{env.PYTHON_VERSION}} sh -c "cd /app && pip install -r requirements.txt && python manage.py test"
- name: Push Image
if: (steps.changes.outputs.src == 'true' || steps.changes.outputs.docker == 'true' || github.event.inputs.version == 'all' || github.event.inputs.version == matrix.version) && github.ref == 'refs/heads/main'
run: docker push -a orbisk/django-test
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ started.
- 🟠 Beta/Experimental (please share your experiences)
- 🔴 Currently not Supported (open an Issue or Pull request if needed)

| Python version | | uv preinstalled |
|----------------|----|-----------------|
| `^3.13.0` | 🟢 | 🟢 (`^3.13.0`) |
| `^3.12.4` | 🟢 | 🟢 (`^3.12.7`) |
| `^3.11.2` | 🟢 | 🟢 (`^3.11.10`) |
| `^3.10.10` | 🟢 | 🟢 (`^3.10.15`) |
| `^3.9.16` | 🟢 | 🟢 (`^3.9.20`) |
| `^3.8.16` | 🟢 | 🟢 (`^3.8.20`) |
| `^3.7.16` | 🟢 | 🔴 |
| `^2.x` | 🔴 | 🔴 |
| Python version | | uv preinstalled |
|----------------|------------------------|:----------------|
| `^3.13.0` | 🟢 | 🟢 (`^3.13.0`) |
| `^3.12.4` | 🟢 | 🟢 (`^3.12.7`) |
| `^3.11.2` | 🟢 | 🟢 (`^3.11.10`) |
| `^3.10.10` | 🟢 | 🟢 (`^3.10.15`) |
| `^3.9.16` | 🟢 | 🟢 (`^3.9.20`) |
| `^3.8.16` | 🟢 | 🟢 (`^3.8.20`) |
| `^3.7.16` | 🟡 ([see](#python-37)) | 🔴 |
| `^2.x` | 🔴 | 🔴 |

| MySQL*️⃣ | |
|----------|----|
| `^9.0.0` | 🟢 |
| `^8.0.0` | 🟢 |
| `<=5.7` | 🟡 |

Expand Down Expand Up @@ -138,3 +139,10 @@ MSSQL is currently only supported/tested with the following versions:
Microsoft ODBC Driver 18 for SQL Server' does currently not work with mssql as ci service with self-signed ssl certs.
If you have any solution, feel free to open an Issue or PR)

## Limitations

### Python 3.7

Python 3.7 is not covered by our CI/CD tests anymore. This means that we can't guarantee that the image will work as
expected with Python 3.7. The reason is that packages like `mssql-django` dropped support for Python 3.7, so we can't
test it anymore.
Empty file added tests/app_mysql_8/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions tests/app_mysql_8/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.1.7 on 2023-03-14 13:46

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='TestModel',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.IntegerField()),
],
),
]
Empty file.
8 changes: 8 additions & 0 deletions tests/app_mysql_8/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models


# Create your models here.


class TestModel(models.Model):
value = models.IntegerField()
8 changes: 8 additions & 0 deletions tests/app_mysql_8/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf import settings

from tests.base_db_router import BaseDBRouter


class DBRouter(BaseDBRouter):
route_app_labels = {"app_mysql_8"}
db = settings.DB_MYSQL_8
9 changes: 9 additions & 0 deletions tests/app_mysql_8/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.conf import settings
from django.test import TestCase


class Test(TestCase):
databases = ['default', settings.DB_MYSQL_8]

def test(self):
self.assertTrue(True)
11 changes: 11 additions & 0 deletions tests/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
"app_mysql",
"app_mysql_8",
"app_mariadb",
"app_postgres",
"app_mssql",
Expand Down Expand Up @@ -79,6 +80,7 @@
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DB_MYSQL = "mysql"
DB_MYSQL_8 = "mysql_8"
DB_MARIADB = "mariadb"
DB_MSSQL = "mssql"
DB_POSTGRES = "postgres"
Expand All @@ -97,6 +99,14 @@
"USER": env.str("MYSQL_USER"),
"PASSWORD": env.str("MYSQL_PASSWORD"),
},
DB_MYSQL_8: {
"ENGINE": "django.db.backends.mysql",
"HOST": env.str("MYSQL_8_HOST"),
"PORT": env.int("MYSQL_8_PORT"),
"NAME": env.str("MYSQL_8_DATABASE"),
"USER": env.str("MYSQL_8_USER"),
"PASSWORD": env.str("MYSQL_8_PASSWORD"),
},
DB_MARIADB: {
"ENGINE": "django.db.backends.mysql",
"HOST": env.str("MARIADB_HOST"),
Expand Down Expand Up @@ -125,6 +135,7 @@

DATABASE_ROUTERS = [
'app_mysql.router.DBRouter',
'app_mysql_8.router.DBRouter',
'app_mariadb.router.DBRouter',
'app_postgres.router.DBRouter',
'app_mssql.router.DBRouter',
Expand Down

0 comments on commit bcd5543

Please sign in to comment.