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):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app.libros'
default_auto_field = "django.db.models.BigAutoField"
name = "app.libros"

View File

@ -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:

View File

@ -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()

View File

@ -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()

View File

@ -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'
AUTH_USER_MODEL = "libros.CustomUser"

View File

@ -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()

View File

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

View File

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

View File

@ -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,7 +195,7 @@ def test_update_book_invalid_json(client):
"foo": "Dune",
"boo": "Ciencia Ficción",
},
content_type="application/json"
content_type="application/json",
)
# Then

View File

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