diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 42eb192..afd452f 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -14,7 +14,7 @@ jobs: username: ${{ secrets.DOCKERHUB_USER }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Checkout - uses: actions/Checkout@v2 + uses: actions/checkout@v2 - name: Test run: docker-compose run --rm app sh -c "python manage.py test" - name: Lint diff --git a/Dockerfile b/Dockerfile index f138cfc..49d23f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9-alpine3.13 +FROM python:3.11-alpine LABEL maintainer="Ram Sevak Mishra" ENV PYTHONUNBUFFERED 1 @@ -16,14 +16,14 @@ ARG DEV=false RUN python -m venv /py && \ /py/bin/pip install --upgrade pip && \ apk add --update --no-cache postgresql-client && \ - apk add --update --no-cache --virtual .tmp-build-dev \ + apk add --update --no-cache --virtual .tmp-build-deps \ build-base postgresql-dev musl-dev && \ /py/bin/pip install -r /tmp/requirements.txt && \ if [ $DEV = "true" ]; \ then /py/bin/pip install -r /tmp/requirements.dev.txt ; \ fi && \ rm -rf /tmp && \ - apk del .tmp-build-dev && \ + apk del .tmp-build-deps && \ adduser \ --disabled-password \ --no-create-home \ diff --git a/app/app/calc.py b/app/app/calc.py index 713c8d2..9535644 100644 --- a/app/app/calc.py +++ b/app/app/calc.py @@ -4,10 +4,12 @@ """ + def add(x, y): "Add x and y values and return result" return x + y + def sub(x, y): "Add x and y values and return result" - return x - y \ No newline at end of file + return x - y diff --git a/app/app/settings.py b/app/app/settings.py index c320c49..4d634bb 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -38,7 +38,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'core' + 'core', ] MIDDLEWARE = [ diff --git a/app/app/tests.py b/app/app/tests.py index a1b3add..f92721a 100644 --- a/app/app/tests.py +++ b/app/app/tests.py @@ -8,14 +8,15 @@ from . import calc + class calcTests(SimpleTestCase): def test_add_numbers(self): - res = calc.add(5,6) + res = calc.add(5, 6) self.assertEqual(res, 11) def test_subtract_numbers(self): - res = calc.sub(15,10) + res = calc.sub(15, 10) - self.assertEqual(res, 5) \ No newline at end of file + self.assertEqual(res, 5) diff --git a/app/core/admin.py b/app/core/admin.py index 8c38f3f..0de000f 100644 --- a/app/core/admin.py +++ b/app/core/admin.py @@ -1,3 +1,2 @@ -from django.contrib import admin -# Register your models here. +# Register your models here.test diff --git a/app/core/management/commands/wait_for_db.py b/app/core/management/commands/wait_for_db.py index 9f8d88f..1489b62 100644 --- a/app/core/management/commands/wait_for_db.py +++ b/app/core/management/commands/wait_for_db.py @@ -3,12 +3,13 @@ """ import time -from psycopg2 import OperationalError as Psycopg2Error +from psycopg2 import OperationalError as Psycopg2OpError from django.db.utils import OperationalError from django.core.management.base import BaseCommand + class Command(BaseCommand): """Django command to wait for database.""" @@ -20,7 +21,8 @@ def handle(self, *args, **options): try: self.check(databases=['default']) db_up = True - except (Psycopg2Error, OperationalError): - self.stdout.write("Database unavailable, waiting 1 second ......") + except (Psycopg2OpError, OperationalError): + self.stdout.write("Database unavailable, waiting 1 second....") time.sleep(1) - self.stdout.write(self.style.SUCCESS("Database available!")) \ No newline at end of file + + self.stdout.write(self.style.SUCCESS("Database available!")) diff --git a/app/core/models.py b/app/core/models.py index 71a8362..35e0d64 100644 --- a/app/core/models.py +++ b/app/core/models.py @@ -1,3 +1,2 @@ -from django.db import models # Create your models here. diff --git a/app/core/tests/test_commands.py b/app/core/tests/test_commands.py index 85c9ad7..232e170 100644 --- a/app/core/tests/test_commands.py +++ b/app/core/tests/test_commands.py @@ -12,6 +12,7 @@ from django.test import SimpleTestCase + @patch('core.management.commands.wait_for_db_command.check') class CommandTests(SimpleTestCase): """Test Command""" @@ -19,9 +20,7 @@ class CommandTests(SimpleTestCase): def test_wait_for_db_ready(self, patched_check): """Test waiting for database if database ready """ patched_check.return_value = True - call_command('wait_for_db') - patched_check.assert_called_once_with(databases=['default']) @patch('time.sleep') @@ -29,8 +28,6 @@ def test_wait_for_db_delay(self, patched_sleep, patched_check): """Test waiting for database when getting OperationalError """ patched_check.side_effect = [Psycopg2Error] * 2 + \ [OperationalError] * 3 + [True] - call_command('wait_for_db') - self.assertEqual(patched_check.call_count, 6) - patched_check.assert_called_with(databases=['default']) \ No newline at end of file + patched_check.assert_called_with(databases=['default']) diff --git a/docker-compose.yml b/docker-compose.yml index 6bdaea0..6142535 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: "3.9" +version: "3.11" services: app: diff --git a/requirements.dev.txt b/requirements.dev.txt index 27d00bc..1ae3ec6 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1 +1 @@ -flake8>=3.9.2,<3.10 \ No newline at end of file +flake8 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8d29a59..cb8e47d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -Django>=3.2.4,<3.3 -djangorestframework>=3.12.4,<3.13 -psycopg2>=2.8.6,<2.9 \ No newline at end of file +Django +djangorestframework +psycopg2 \ No newline at end of file