Skip to content

Instantly share code, notes, and snippets.

@aipi
Last active May 17, 2017 03:44
Show Gist options
  • Save aipi/99ed2c992be41be437bb9506de73cb44 to your computer and use it in GitHub Desktop.
Save aipi/99ed2c992be41be437bb9506de73cb44 to your computer and use it in GitHub Desktop.
Django subTest() example code and login test example code
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
class (TestCase):
def setUp(self):
self.superuser = User.objects.create_superuser(
email='[email protected]',
password='V&ryD@f3Pwd',
name='Super User')
self.login = self.client.login(email='[email protected]', password='V&ryD@f3Pwd')
self.resp = self.client.get('/mouses')
def test_login(self):
""" Check if is logged """
self.assertTrue(self.login)
def test_html(self):
""" HTML must contains input tags """
tags = (('<h1>Mouse populations'),
('<th>ID'),
('<th>Age'),
('<th>Skin color'),
('<th>Gender'),)
for text in tags:
with self.subTest():
self.assertContains(self.resp, text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment