Spaces:
Build error
Build error
Creado test post para api_words
Browse files
tecnicas/test/test_words.py
CHANGED
|
@@ -52,3 +52,50 @@ class TestsApiWords(TestCase):
|
|
| 52 |
data = res_json["data"]
|
| 53 |
self.assertEqual(data["id"], expected_data["id"])
|
| 54 |
self.assertEqual(data["name"], expected_data["nombre_palabra"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
data = res_json["data"]
|
| 53 |
self.assertEqual(data["id"], expected_data["id"])
|
| 54 |
self.assertEqual(data["name"], expected_data["nombre_palabra"])
|
| 55 |
+
|
| 56 |
+
def test_post_word_success(self):
|
| 57 |
+
word_name = "dulce"
|
| 58 |
+
expected_message = "palabra creada"
|
| 59 |
+
|
| 60 |
+
response = self.client.post(
|
| 61 |
+
reverse("cata_system:api_palabras"),
|
| 62 |
+
data={"nombre_palabra": word_name}
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
self.assertEqual(response.status_code, 200)
|
| 66 |
+
|
| 67 |
+
res_json = response.json()
|
| 68 |
+
|
| 69 |
+
self.assertIn("message", res_json)
|
| 70 |
+
self.assertEqual(res_json["message"], expected_message)
|
| 71 |
+
|
| 72 |
+
data = res_json["data"]
|
| 73 |
+
self.assertIn("id", data)
|
| 74 |
+
self.assertIn("nombre_palabra", data)
|
| 75 |
+
self.assertEqual(data["nombre_palabra"], word_name)
|
| 76 |
+
|
| 77 |
+
def test_post_word_fail(self):
|
| 78 |
+
word_name = "salado"
|
| 79 |
+
expected_error = "palabra repetida"
|
| 80 |
+
|
| 81 |
+
response = self.client.post(
|
| 82 |
+
reverse("cata_system:api_palabras"),
|
| 83 |
+
data={"nombre_palabra": word_name}
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
self.assertEqual(response.status_code, 200)
|
| 87 |
+
|
| 88 |
+
res_json = response.json()
|
| 89 |
+
self.assertIn("error", res_json)
|
| 90 |
+
self.assertEqual(res_json["error"], expected_error)
|
| 91 |
+
|
| 92 |
+
def test_post_word_no_parameter(self):
|
| 93 |
+
expected_error = "parametros no encontrados"
|
| 94 |
+
|
| 95 |
+
response = self.client.post(reverse("cata_system:api_palabras"))
|
| 96 |
+
|
| 97 |
+
self.assertEqual(response.status_code, 200)
|
| 98 |
+
|
| 99 |
+
res_json = response.json()
|
| 100 |
+
self.assertIn("error", res_json)
|
| 101 |
+
self.assertEqual(res_json["error"], expected_error)
|
tecnicas/utils/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
from .code_generate import generarCodigo
|
| 2 |
-
from .
|
|
|
|
| 1 |
from .code_generate import generarCodigo
|
| 2 |
+
from .general_error import general_error
|
tecnicas/utils/general_error.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import JsonResponse
|
| 2 |
+
|
| 3 |
+
def general_error(message="informacion incorrecta"):
|
| 4 |
+
respuesta = { "error" : message }
|
| 5 |
+
return JsonResponse(respuesta)
|
tecnicas/views/api_tag.py
CHANGED
|
@@ -2,11 +2,12 @@ from django.http import HttpRequest, JsonResponse
|
|
| 2 |
from django.db import IntegrityError
|
| 3 |
from ..models import Etiqueta
|
| 4 |
from ..forms import EtiquetaForm
|
| 5 |
-
import
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
if req.method == "GET":
|
| 9 |
-
return
|
| 10 |
elif req.method == "POST":
|
| 11 |
try:
|
| 12 |
form = EtiquetaForm(req.POST)
|
|
@@ -15,15 +16,16 @@ def newTag(req:HttpRequest):
|
|
| 15 |
value_etiqueta = value_etiqueta.strip()
|
| 16 |
value_etiqueta = value_etiqueta.lower()
|
| 17 |
else:
|
| 18 |
-
return
|
| 19 |
except KeyError:
|
| 20 |
-
return
|
| 21 |
|
| 22 |
try:
|
| 23 |
-
new_etiqueta = Etiqueta.objects.create(
|
|
|
|
| 24 |
except IntegrityError:
|
| 25 |
-
return
|
| 26 |
-
|
| 27 |
return JsonResponse({
|
| 28 |
"message": "etiqueta registrada",
|
| 29 |
"new_tag": {
|
|
@@ -31,7 +33,3 @@ def newTag(req:HttpRequest):
|
|
| 31 |
"valor": new_etiqueta.valor_etiqueta
|
| 32 |
}
|
| 33 |
})
|
| 34 |
-
|
| 35 |
-
def error(message="informacion incorrecta"):
|
| 36 |
-
respuesta = { "error" : message }
|
| 37 |
-
return JsonResponse(respuesta)
|
|
|
|
| 2 |
from django.db import IntegrityError
|
| 3 |
from ..models import Etiqueta
|
| 4 |
from ..forms import EtiquetaForm
|
| 5 |
+
from ..utils import general_error
|
| 6 |
|
| 7 |
+
|
| 8 |
+
def newTag(req: HttpRequest):
|
| 9 |
if req.method == "GET":
|
| 10 |
+
return general_error()
|
| 11 |
elif req.method == "POST":
|
| 12 |
try:
|
| 13 |
form = EtiquetaForm(req.POST)
|
|
|
|
| 16 |
value_etiqueta = value_etiqueta.strip()
|
| 17 |
value_etiqueta = value_etiqueta.lower()
|
| 18 |
else:
|
| 19 |
+
return general_error()
|
| 20 |
except KeyError:
|
| 21 |
+
return general_error()
|
| 22 |
|
| 23 |
try:
|
| 24 |
+
new_etiqueta = Etiqueta.objects.create(
|
| 25 |
+
valor_etiqueta=value_etiqueta)
|
| 26 |
except IntegrityError:
|
| 27 |
+
return general_error("etiqueta repetida")
|
| 28 |
+
|
| 29 |
return JsonResponse({
|
| 30 |
"message": "etiqueta registrada",
|
| 31 |
"new_tag": {
|
|
|
|
| 33 |
"valor": new_etiqueta.valor_etiqueta
|
| 34 |
}
|
| 35 |
})
|
|
|
|
|
|
|
|
|
|
|
|
tecnicas/views/api_words.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from django.http import HttpRequest, JsonResponse
|
| 2 |
from django.db import IntegrityError
|
| 3 |
from ..models import Palabra
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def words(req: HttpRequest):
|
|
@@ -9,9 +10,9 @@ def words(req: HttpRequest):
|
|
| 9 |
word_name = req.GET["palabra"]
|
| 10 |
fund_word = Palabra.objects.get(nombre_palabra=word_name)
|
| 11 |
except KeyError:
|
| 12 |
-
return
|
| 13 |
except Palabra.DoesNotExist:
|
| 14 |
-
return
|
| 15 |
|
| 16 |
response = {
|
| 17 |
"message": "dato localizado",
|
|
@@ -27,9 +28,9 @@ def words(req: HttpRequest):
|
|
| 27 |
word_name = req.POST["nombre_palabra"]
|
| 28 |
new_word = Palabra.objects.create(nombre_palabra=word_name)
|
| 29 |
except KeyError:
|
| 30 |
-
return
|
| 31 |
except IntegrityError:
|
| 32 |
-
return
|
| 33 |
|
| 34 |
response = {
|
| 35 |
"message": "palabra creada",
|
|
@@ -37,8 +38,3 @@ def words(req: HttpRequest):
|
|
| 37 |
}
|
| 38 |
|
| 39 |
return JsonResponse(response)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def error(message="parametros no encontrados"):
|
| 43 |
-
respuesta = {"error": message}
|
| 44 |
-
return JsonResponse(respuesta)
|
|
|
|
| 1 |
from django.http import HttpRequest, JsonResponse
|
| 2 |
from django.db import IntegrityError
|
| 3 |
from ..models import Palabra
|
| 4 |
+
from ..utils import general_error
|
| 5 |
|
| 6 |
|
| 7 |
def words(req: HttpRequest):
|
|
|
|
| 10 |
word_name = req.GET["palabra"]
|
| 11 |
fund_word = Palabra.objects.get(nombre_palabra=word_name)
|
| 12 |
except KeyError:
|
| 13 |
+
return general_error("parametros no encontrados")
|
| 14 |
except Palabra.DoesNotExist:
|
| 15 |
+
return general_error("palabra no encontrada")
|
| 16 |
|
| 17 |
response = {
|
| 18 |
"message": "dato localizado",
|
|
|
|
| 28 |
word_name = req.POST["nombre_palabra"]
|
| 29 |
new_word = Palabra.objects.create(nombre_palabra=word_name)
|
| 30 |
except KeyError:
|
| 31 |
+
return general_error("parametros no encontrados")
|
| 32 |
except IntegrityError:
|
| 33 |
+
return general_error("palabra repetida")
|
| 34 |
|
| 35 |
response = {
|
| 36 |
"message": "palabra creada",
|
|
|
|
| 38 |
}
|
| 39 |
|
| 40 |
return JsonResponse(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tecnicas/views/configurations_panel_words.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import HttpRequest
|
| 2 |
+
|
| 3 |
+
def configuracionPanelWords(req: HttpRequest):
|
| 4 |
+
if req.method == "GET":
|
| 5 |
+
return error("This endpoint is not implemented yet.")
|
| 6 |
+
else:
|
| 7 |
+
return error("Method not allowed.")
|