Herramientas de usuario

Herramientas del sitio


wiki2:python:django:tests

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:python:django:tests [2018/10/12 14:15]
alfred [RequestFactory]
wiki2:python:django:tests [2020/08/29 15:11] (actual)
Línea 45: Línea 45:
 res = self.client.get('/​users/​signup'​) res = self.client.get('/​users/​signup'​)
 </​code>​ </​code>​
 +<​code>​ 
 +self.client.force_login(User.objects.get_or_create(username='​testuser'​)[0]) 
 +self.client.login(... 
 +</​code>​
 ====== Mail ====== ====== Mail ======
 <​code>​ <​code>​
Línea 63: Línea 66:
         self.assertEqual(mail.outbox[0].to[0],​ email)         self.assertEqual(mail.outbox[0].to[0],​ email)
 </​code>​ </​code>​
 +
 +
 +====== Articles ======
 +
 +===== N+1 Queries =====
 +
 +Lets imagine you are creating a view for returning all the courses with some of their authors data. If you run a code like this:
 +<code python>
 +queryset = Course.objects.all()
 +courses = []
 +for course in queryset:
 +  courses.append({"​title":​ course.title,​ "​author":​ course.author.name})
 +</​code>​
 +This is executing one query (for bringing all courses) and N queries more (one for each author). There is the library [[https://​github.com/​jmcarp/​nplusone|nplusone]] to detect this.
 +  * {{ :​wiki2:​python:​django:​automating_performance_testing_in_django.zip |}}
 +
wiki2/python/django/tests.1539353718.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)