diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 86c37fc..7f78a75 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,7 @@ on: push: branches: - 'main' + - 'feature/*' jobs: build: @@ -32,8 +33,21 @@ jobs: POSTGRES_USER: test_user POSTGRES_PASSWORD: password POSTGRES_PORT: 5432 + MSSQL_HOST: 127.0.0.1 + MSSQL_DATABASE: test_db + MSSQL_USER: sa + MSSQL_PASSWORD: yourStrong(!)Password + MSSQL_PORT: 1443 services: # Label used to access the service container + mssql: + image: mcr.microsoft.com/mssql/server:2019-latest + env: + MSSQL_SA_PASSWORD: ${{secrets.MSSQL_PASSWORD}} + ACCEPT_EULA: Y + ports: + - 1433:1433 + options: --health-cmd="sqlcmd -U sa -P ${{secrets.MSSQL_PASSWORD}} -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3 mysql: image: mysql env: @@ -110,7 +124,7 @@ jobs: - 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 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 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 + 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 diff --git a/README.md b/README.md index 58ed5e9..668bded 100644 --- a/README.md +++ b/README.md @@ -31,46 +31,55 @@ started. - 🟢 Supported/Tested - 🟡 Unknown/Untested +- 🟠 Beta/Experimental (please share your experiences) - 🔴 Currently not Supported (open an Issue or Pull request if needed) -| Python version | | -|----------------|-----| -| `^2.x` | 🔴 | -| `^3.7.16` | 🟢 | -| `^3.8.16` | 🟢 | -| `^3.9.16` | 🟢 | -| `^3.10.10` | 🟢 | -| `^3.11.2` | 🟢 | - -| MySQL*️⃣ | | -|----------|-----| -| `^8.0.0` | 🟢 | -| `<=5.7` | 🟡 | - -| MariaDB*️⃣ | | -|------------|-----| -| `^11.0.0` | 🟡 | -| `^10.7.8` | 🟢 | -| `<10.7.8` | 🟡 | - -| Postgres | | -|----------|-----| -| `^15.2` | 🟢 | -| `<15.2` | 🟡 | +| Python version | | +|--------------|----| +| `^3.12` | 🔴 | +| `^3.11.2` | 🟢 | +| `^3.10.10` | 🟢 | +| `^3.9.16` | 🟢 | +| `^3.8.16` | 🟢 | +| `^3.7.16` | 🟢 | +| `^2.x` | 🔴 | + +| MySQL*️⃣ | | +|----------|----| +| `^8.0.0` | 🟢 | +| `<=5.7` | 🟡 | + +| MariaDB*️⃣ | | +|------------|----| +| `^11.0.0` | 🟡 | +| `^10.7.8` | 🟢 | +| `<10.7.8` | 🟡 | + +| Postgres | | +|----------|----| +| `^15.2` | 🟢 | +| `<15.2` | 🟡 | + +| MSSQL | | +|---------------------------|----| +| `>=2022` | 🟠 | +| `^2019-CU23-ubuntu-20.04` | 🟠 | +| `<=2017` | 🟠 | *️⃣ Additional step required see: [Error creating the test database](#error-creating-the-test-database) ## Common issues ### Error creating the test database + `Got an error creating the test database: (1044, "1044 (42000): Access denied for user ''@'%' to database 'test_'", '42000')` -The MYSQL user is only granted permissions for the MYSQL_DB, which means that Django is unable to create a test database. +The MYSQL user is only granted permissions for the MYSQL_DB, which means that Django is unable to create a test +database. To use MySQL and MariaDB with a non-root user, you need to grant privileges to your test user. `echo "GRANT ALL on *.* to '$MYSQL_USER';"| mysql -u root --password="$MYSQL_ROOT_PASSWORD" -h -p ` - ## CI Examples ### GitLab CI @@ -98,6 +107,4 @@ django-tests: ## Feedback - - If you have any problems with or questions about this image, please open an issue on GitHub. diff --git a/tests/app_mssql/__init__.py b/tests/app_mssql/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/app_mssql/migrations/0001_initial.py b/tests/app_mssql/migrations/0001_initial.py new file mode 100644 index 0000000..ddd3b6c --- /dev/null +++ b/tests/app_mssql/migrations/0001_initial.py @@ -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()), + ], + ), + ] diff --git a/tests/app_mssql/migrations/__init__.py b/tests/app_mssql/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/app_mssql/models.py b/tests/app_mssql/models.py new file mode 100644 index 0000000..9262bc0 --- /dev/null +++ b/tests/app_mssql/models.py @@ -0,0 +1,8 @@ +from django.db import models + + +# Create your models here. + + +class TestModel(models.Model): + value = models.IntegerField() diff --git a/tests/app_mssql/router.py b/tests/app_mssql/router.py new file mode 100644 index 0000000..3fe56f4 --- /dev/null +++ b/tests/app_mssql/router.py @@ -0,0 +1,8 @@ +from django.conf import settings + +from tests.base_db_router import BaseDBRouter + + +class DBRouter(BaseDBRouter): + route_app_labels = {"app_mssql"} + db = settings.DB_MSSQL diff --git a/tests/app_mssql/tests.py b/tests/app_mssql/tests.py new file mode 100644 index 0000000..26f0d7f --- /dev/null +++ b/tests/app_mssql/tests.py @@ -0,0 +1,9 @@ +from django.conf import settings +from django.test import TestCase + + +class Test(TestCase): + databases = ['default', settings.DB_POSTGRES] + + def test(self): + self.assertTrue(True) diff --git a/tests/requirements.txt b/tests/requirements.txt index a90e2d9..d70d1a8 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -3,3 +3,4 @@ coverage mysqlclient django-environ psycopg2 +mssql-django \ No newline at end of file diff --git a/tests/tests/settings.py b/tests/tests/settings.py index 93b17a0..46f9d8b 100644 --- a/tests/tests/settings.py +++ b/tests/tests/settings.py @@ -112,11 +112,21 @@ "USER": env.str("POSTGRES_USER"), "PASSWORD": env.str("POSTGRES_PASSWORD"), }, + DB_MSSQL: { + "ENGINE": "mssql", + "HOST": env.str("MSSQL_HOST"), + "PORT": env.int("MSSQL_PORT"), + "NAME": env.str("MSSQL_DATABASE"), + "USER": env.str("MSSQL_USER"), + "PASSWORD": env.str("MSSQL_PASSWORD"), + } } DATABASE_ROUTERS = [ 'app_mysql.router.DBRouter', 'app_mariadb.router.DBRouter', + 'app_postgres.router.DBRouter', + 'app_mssql.router.DBRouter', ] # Password validation