17. Soluciones
Django
○ Borrón y cuenta nueva
manage flush && manage syncdb
○ Modificar manualmente las tablas
manage sql
18. Soluciones
Django
○ Borrón y cuenta nueva
manage flush && manage syncdb
○ Modificar manualmente las tablas
manage sql
South
19. south
South brings migrations to Django applications.
● Automatic migration creation
● Database independence
● App-savvy
● VCS-proof
20. Migraciones
RAE:
Acción y efecto de pasar de un país a otro para
establecerse en él.
south:
[...] a way of changing your database schema
from one version into another [...]
21. Migraciones
RAE:
Acción y efecto de pasar de un país a otro para
establecerse en él.
south:
[...] a way of changing your database schema
from one version into another [...]
En ambos sentidos.
22. south en dos patadas
Migraciones:
Primera:
manage.py schemamigration APP --initial
Siguientes:
manage.py schemamigration APP --auto
Aplicar:
manage.py migrate [APP]
23. Migraciones complicadas
? The field 'Votacion.autor' does not have a default specified, yet
is NOT NULL.
? Since you are making this field non-nullable, you MUST specify
a default
? value to use for existing rows. Would you like to:
? 1. Quit now, and add a default to the field in models.py
? 2. Specify a one-off value to use for existing columns now
? Please select a choice:
24. Durante el desarrollo
Reutilizar la migración:
manage.py schemamigration --update --auto
Conflictos
manage.py migrate --merge
Listar:
manage.py migrate --list
27. Pruebas :-?
● When you’re writing new code, you can use
tests to validate your code works as expected.
● When you’re refactoring or modifying old code,
you can use tests to ensure your changes haven’
t affected your application’s behavior
unexpectedly.
28. Pruebas :-?
● When you’re writing new code, you can use
tests to validate your code works as expected.
● When you’re refactoring or modifying old code,
you can use tests to ensure your changes haven’
t affected your application’s behavior
unexpectedly.
Sí o sí 0:-)
30. unittest
Forma parte de Python
Cumplir dos condiciones:
a. Heredar de unittest.TestCase
b. El método empieza por test
Django enriquece con django.utils.unittest
32. Pruebas en Django
Por defecto:
APP/tests.py
manage.py test [[[APP].TestCase].test_method]
33. Modelos
Bases de datos de prueba
By default the test databases get their names by
prepending test_ to the value of the NAME
settings for the databases defined in
DATABASES.
Ejercicio para el lector: fixtures
34. Vistas
Test Client simula un navegador
from django.test.client import Client
class SimpleTest(unittest.TestCase):
def setUp(self):
self.client = Client()
def test_details(self):
response = self.client.get('/customer/details/')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['customers']), 5)