This commit is contained in:
Andros Fenollosa 2021-07-13 18:30:31 +02:00
parent 7fd71eca7f
commit 204556f495
13 changed files with 59 additions and 60 deletions

View File

@ -2,5 +2,5 @@ from django.apps import AppConfig
class LibrosConfig(AppConfig): class LibrosConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = "django.db.models.BigAutoField"
name = 'app.libros' name = "app.libros"

View File

@ -14,9 +14,8 @@ def ping(request):
class LibrosList(APIView): class LibrosList(APIView):
def get(self, request): 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) serializer = LibroSerializer(libros, many=True)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
@ -29,7 +28,6 @@ class LibrosList(APIView):
class LibrosDetails(APIView): class LibrosDetails(APIView):
def get(self, request, pk): def get(self, request, pk):
libro = Libros.objects.filter(pk=pk).first() libro = Libros.objects.filter(pk=pk).first()
if libro: if libro:
@ -37,7 +35,6 @@ class LibrosDetails(APIView):
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(status=status.HTTP_404_NOT_FOUND) return Response(status=status.HTTP_404_NOT_FOUND)
def put(self, request, pk): def put(self, request, pk):
libro = Libros.objects.filter(pk=pk).first() libro = Libros.objects.filter(pk=pk).first()
serializer = LibroSerializer(libro, data=request.data) 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.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def delete(self, request, pk): def delete(self, request, pk):
libro = Libros.objects.filter(pk=pk).first() libro = Libros.objects.filter(pk=pk).first()
if libro: if libro:

View File

@ -6,7 +6,7 @@ import sys
def main(): def main():
"""Run administrative tasks.""" """Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proyecto.settings') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proyecto.settings")
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError as exc: except ImportError as exc:
@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application 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() application = get_asgi_application()

View File

@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # 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! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
@ -31,54 +31,54 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.admin', "django.contrib.admin",
'django.contrib.auth', "django.contrib.auth",
'django.contrib.contenttypes', "django.contrib.contenttypes",
'django.contrib.sessions', "django.contrib.sessions",
'django.contrib.messages', "django.contrib.messages",
'django.contrib.staticfiles', "django.contrib.staticfiles",
'rest_framework', # nuevo "rest_framework", # nuevo
'app.libros', # nuevo "app.libros", # nuevo
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', "django.middleware.security.SecurityMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware', "django.contrib.sessions.middleware.SessionMiddleware",
'django.middleware.common.CommonMiddleware', "django.middleware.common.CommonMiddleware",
'django.middleware.csrf.CsrfViewMiddleware', "django.middleware.csrf.CsrfViewMiddleware",
'django.contrib.auth.middleware.AuthenticationMiddleware', "django.contrib.auth.middleware.AuthenticationMiddleware",
'django.contrib.messages.middleware.MessageMiddleware', "django.contrib.messages.middleware.MessageMiddleware",
'django.middleware.clickjacking.XFrameOptionsMiddleware', "django.middleware.clickjacking.XFrameOptionsMiddleware",
] ]
ROOT_URLCONF = 'proyecto.urls' ROOT_URLCONF = "proyecto.urls"
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', "BACKEND": "django.template.backends.django.DjangoTemplates",
'DIRS': [], "DIRS": [],
'APP_DIRS': True, "APP_DIRS": True,
'OPTIONS': { "OPTIONS": {
'context_processors': [ "context_processors": [
'django.template.context_processors.debug', "django.template.context_processors.debug",
'django.template.context_processors.request', "django.template.context_processors.request",
'django.contrib.auth.context_processors.auth', "django.contrib.auth.context_processors.auth",
'django.contrib.messages.context_processors.messages', "django.contrib.messages.context_processors.messages",
], ],
}, },
}, },
] ]
WSGI_APPLICATION = 'proyecto.wsgi.application' WSGI_APPLICATION = "proyecto.wsgi.application"
# Database # Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = { DATABASES = {
'default': { "default": {
'ENGINE': 'django.db.backends.sqlite3', "ENGINE": "django.db.backends.sqlite3",
'NAME': BASE_DIR / 'db.sqlite3', "NAME": BASE_DIR / "db.sqlite3",
} }
} }
@ -88,16 +88,16 @@ DATABASES = {
AUTH_PASSWORD_VALIDATORS = [ 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 # Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/ # 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 USE_I18N = True
@ -119,11 +119,11 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/ # https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = "/static/"
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field # 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' AUTH_USER_MODEL = "libros.CustomUser"

View File

@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application 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() application = get_wsgi_application()

View File

@ -4,6 +4,7 @@ import pytest
from app.libros.models import Libros from app.libros.models import Libros
@pytest.mark.django_db @pytest.mark.django_db
def test_libros_model(): def test_libros_model():

View File

@ -2,6 +2,7 @@
from app.libros.serializers import LibroSerializer from app.libros.serializers import LibroSerializer
def test_valid_libro_serializer(): def test_valid_libro_serializer():
valid_serializer_data = { valid_serializer_data = {
"title": "Raising Arizona", "title": "Raising Arizona",

View File

@ -20,7 +20,7 @@ def test_add_book(client):
"author": "Isaac Asimov", "author": "Isaac Asimov",
"year": "1955", "year": "1955",
}, },
content_type="application/json" content_type="application/json",
) )
# Then # Then
@ -154,7 +154,7 @@ def test_update_book(client):
"author": "Frank Herbert", "author": "Frank Herbert",
"year": "1965", "year": "1965",
}, },
content_type="application/json" content_type="application/json",
) )
# Then # Then
@ -195,7 +195,7 @@ def test_update_book_invalid_json(client):
"foo": "Dune", "foo": "Dune",
"boo": "Ciencia Ficción", "boo": "Ciencia Ficción",
}, },
content_type="application/json" content_type="application/json",
) )
# Then # Then

View File

@ -1,6 +1,7 @@
import json import json
from django.urls import reverse from django.urls import reverse
def test_ping(client): def test_ping(client):
url = reverse("ping") url = reverse("ping")
response = client.get(url) response = client.get(url)