From 204556f49507ba9c26a27b4ef627286f4256200d Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Tue, 13 Jul 2021 18:30:31 +0200 Subject: [PATCH] format --- app/libros/apps.py | 4 +- app/libros/models.py | 2 +- app/libros/views.py | 6 +-- manage.py | 4 +- proyecto/asgi.py | 2 +- proyecto/settings.py | 78 +++++++++++++++---------------- proyecto/urls.py | 2 +- proyecto/wsgi.py | 2 +- tests/libros/test_create_model.py | 3 +- tests/libros/test_serializers.py | 1 + tests/libros/test_views.py | 10 ++-- tests/test_ejemplo.py | 2 +- tests/test_ping.py | 3 +- 13 files changed, 59 insertions(+), 60 deletions(-) diff --git a/app/libros/apps.py b/app/libros/apps.py index 085be30..bccaec3 100644 --- a/app/libros/apps.py +++ b/app/libros/apps.py @@ -2,5 +2,5 @@ from django.apps import AppConfig class LibrosConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'app.libros' + default_auto_field = "django.db.models.BigAutoField" + name = "app.libros" diff --git a/app/libros/models.py b/app/libros/models.py index 7136479..9b1f313 100644 --- a/app/libros/models.py +++ b/app/libros/models.py @@ -22,4 +22,4 @@ class Libros(models.Model): verbose_name_plural = "Libros" def __str__(self): - return self.title \ No newline at end of file + return self.title diff --git a/app/libros/views.py b/app/libros/views.py index ad927c9..b1771b7 100644 --- a/app/libros/views.py +++ b/app/libros/views.py @@ -14,9 +14,8 @@ def ping(request): class LibrosList(APIView): - def get(self, request): - libros = Libros.objects.all().order_by('created_at') + libros = Libros.objects.all().order_by("created_at") serializer = LibroSerializer(libros, many=True) return Response(serializer.data, status=status.HTTP_200_OK) @@ -29,7 +28,6 @@ class LibrosList(APIView): class LibrosDetails(APIView): - def get(self, request, pk): libro = Libros.objects.filter(pk=pk).first() if libro: @@ -37,7 +35,6 @@ class LibrosDetails(APIView): return Response(serializer.data, status=status.HTTP_200_OK) return Response(status=status.HTTP_404_NOT_FOUND) - def put(self, request, pk): libro = Libros.objects.filter(pk=pk).first() serializer = LibroSerializer(libro, data=request.data) @@ -46,7 +43,6 @@ class LibrosDetails(APIView): return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - def delete(self, request, pk): libro = Libros.objects.filter(pk=pk).first() if libro: diff --git a/manage.py b/manage.py index 5cd4202..88c5155 100755 --- a/manage.py +++ b/manage.py @@ -6,7 +6,7 @@ import sys def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proyecto.settings') + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proyecto.settings") try: from django.core.management import execute_from_command_line except ImportError as exc: @@ -18,5 +18,5 @@ def main(): execute_from_command_line(sys.argv) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/proyecto/asgi.py b/proyecto/asgi.py index a3b9f57..ba5272b 100644 --- a/proyecto/asgi.py +++ b/proyecto/asgi.py @@ -11,6 +11,6 @@ import os from django.core.asgi import get_asgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proyecto.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proyecto.settings") application = get_asgi_application() diff --git a/proyecto/settings.py b/proyecto/settings.py index dcfdbf6..d7d113d 100644 --- a/proyecto/settings.py +++ b/proyecto/settings.py @@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-+j!b+4cv@q0$^$2%5o+&c&@!hf1bfgpl#f^71dfgzijt2fek9#' +SECRET_KEY = "django-insecure-+j!b+4cv@q0$^$2%5o+&c&@!hf1bfgpl#f^71dfgzijt2fek9#" # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -31,54 +31,54 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'rest_framework', # nuevo - 'app.libros', # nuevo + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "rest_framework", # nuevo + "app.libros", # nuevo ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'proyecto.urls' +ROOT_URLCONF = "proyecto.urls" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", ], }, }, ] -WSGI_APPLICATION = 'proyecto.wsgi.application' +WSGI_APPLICATION = "proyecto.wsgi.application" # Database # https://docs.djangoproject.com/en/3.2/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", } } @@ -88,16 +88,16 @@ DATABASES = { AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] @@ -105,9 +105,9 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/3.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = "en-us" -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_I18N = True @@ -119,11 +119,11 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.2/howto/static-files/ -STATIC_URL = '/static/' +STATIC_URL = "/static/" # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" -AUTH_USER_MODEL = 'libros.CustomUser' \ No newline at end of file +AUTH_USER_MODEL = "libros.CustomUser" diff --git a/proyecto/urls.py b/proyecto/urls.py index e880062..19c11e9 100644 --- a/proyecto/urls.py +++ b/proyecto/urls.py @@ -6,4 +6,4 @@ from django.urls import path, include urlpatterns = [ path("admin/", admin.site.urls), path("", include("app.libros.urls")), -] \ No newline at end of file +] diff --git a/proyecto/wsgi.py b/proyecto/wsgi.py index 022bae0..4893b71 100644 --- a/proyecto/wsgi.py +++ b/proyecto/wsgi.py @@ -11,6 +11,6 @@ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proyecto.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proyecto.settings") application = get_wsgi_application() diff --git a/tests/libros/test_create_model.py b/tests/libros/test_create_model.py index bfa7e2b..9f9afe9 100644 --- a/tests/libros/test_create_model.py +++ b/tests/libros/test_create_model.py @@ -4,6 +4,7 @@ import pytest from app.libros.models import Libros + @pytest.mark.django_db def test_libros_model(): @@ -26,4 +27,4 @@ def test_libros_model(): assert libro.author == "Isaac Asimov" assert libro.created_at assert libro.updated_at - assert str(libro) == libro.title \ No newline at end of file + assert str(libro) == libro.title diff --git a/tests/libros/test_serializers.py b/tests/libros/test_serializers.py index ac12841..78c29cd 100644 --- a/tests/libros/test_serializers.py +++ b/tests/libros/test_serializers.py @@ -2,6 +2,7 @@ from app.libros.serializers import LibroSerializer + def test_valid_libro_serializer(): valid_serializer_data = { "title": "Raising Arizona", diff --git a/tests/libros/test_views.py b/tests/libros/test_views.py index f26a529..fd79d20 100644 --- a/tests/libros/test_views.py +++ b/tests/libros/test_views.py @@ -20,7 +20,7 @@ def test_add_book(client): "author": "Isaac Asimov", "year": "1955", }, - content_type="application/json" + content_type="application/json", ) # Then @@ -40,7 +40,7 @@ def test_get_single_book(client): genre="Ciencia Ficción", author="Isaac Asimov", year="1955", - ) + ) # When resp = client.get(f"/api/libros/{libro.id}/") @@ -154,7 +154,7 @@ def test_update_book(client): "author": "Frank Herbert", "year": "1965", }, - content_type="application/json" + content_type="application/json", ) # Then @@ -195,8 +195,8 @@ def test_update_book_invalid_json(client): "foo": "Dune", "boo": "Ciencia Ficción", }, - content_type="application/json" + content_type="application/json", ) # Then - assert resp.status_code == 400 \ No newline at end of file + assert resp.status_code == 400 diff --git a/tests/test_ejemplo.py b/tests/test_ejemplo.py index db7f75f..e351af8 100644 --- a/tests/test_ejemplo.py +++ b/tests/test_ejemplo.py @@ -1,3 +1,3 @@ # Las funciones deben empezar por "test_" def test_titulo(): - assert "canción de hielo y fuego" != "juego de tronos" \ No newline at end of file + assert "canción de hielo y fuego" != "juego de tronos" diff --git a/tests/test_ping.py b/tests/test_ping.py index 91fb861..2e48a15 100644 --- a/tests/test_ping.py +++ b/tests/test_ping.py @@ -1,9 +1,10 @@ import json from django.urls import reverse + def test_ping(client): url = reverse("ping") response = client.get(url) content = json.loads(response.content) assert response.status_code == 200 - assert content["ping"] == "pong!" \ No newline at end of file + assert content["ping"] == "pong!"