18.10. Test Smoke Testing
18.10.1. Use Case - 1
import logging
from django.contrib.auth.models import User
from django.test import TestCase
from django.test.client import Client
class Test(TestCase):
assert_http_200 = []
def setUp(self):
self.logger = logging.getLogger(__name__)
self.user = User.objects.create_superuser('test', 'test@example.com', 'test')
self.client.login(username='test', password='test')
def tearDown(self):
self.client.logout()
self.user.delete()
def test_http_200(self):
for url in self.assert_http_200:
response = self.client.get(url)
if response.status_code != 200:
self.logger.error(f'{response.status_code} {url}')
raise AssertionError(f'HTTP {response.status_code} for "{url}"')
else:
self.logger.info(f'{response.status_code} {url}')
... from myproject.tests import Test
...
... class TestShop(Test):
... assert_http_200 = [
... '/admin/',
... '/admin/shop/',
... '/admin/shop/customer/',
... '/admin/shop/customer/add/',
... '/admin/shop/customer/edit/1/',
... '/admin/shop/address/',
... '/admin/shop/address/add/',
... '/admin/shop/address/edit/1/',
... '/admin/shop/product/',
... '/admin/shop/product/add/',
... '/admin/shop/product/edit/1/',
... '/admin/shop/order/',
... '/admin/shop/order/add/',
... '/admin/shop/order/edit/1/',
... ]