med/media/tests/test_templates.py

66 lines
2.0 KiB
Python

# -*- mode: python; coding: utf-8 -*-
# SPDX-License-Identifier: GPL-3.0-or-later
from django.test import TestCase
from django.urls import reverse
from media.models import Auteur, BD
from users.models import User
"""
Test that every page render
"""
class TemplateTests(TestCase):
def setUp(self):
self.user = User.objects.create_superuser(
username="admin",
password="adminadmin",
email="admin@example.com",
)
self.client.force_login(self.user)
# Create an author
self.dummy_author = Auteur.objects.create(name="Test author")
# Create media
self.dummy_bd1 = BD.objects.create(
title="Test media",
side_identifier="T M",
)
self.dummy_bd1.authors.add(self.dummy_author)
self.dummy_bd2 = BD.objects.create(
title="Test media bis",
side_identifier="T M 2",
external_url="https://example.com/",
)
self.dummy_bd2.authors.add(self.dummy_author)
def test_bd_bd_changelist(self):
response = self.client.get(reverse('admin:media_bd_changelist'))
self.assertEqual(response.status_code, 200)
def test_bd_bd_add(self):
response = self.client.get(reverse('admin:media_bd_add'))
self.assertEqual(response.status_code, 200)
def test_bd_isbn_download(self):
data = {
'_isbn': True,
'isbn': "0316358525",
}
response = self.client.post(reverse(
'admin:media_bd_change',
args=[self.dummy_bd1.id],
), data=data)
self.assertEqual(response.status_code, 302)
def test_bd_emprunt_changelist(self):
response = self.client.get(reverse('admin:media_emprunt_changelist'))
self.assertEqual(response.status_code, 200)
def test_bd_emprunt_add(self):
response = self.client.get(reverse('admin:media_emprunt_add'))
self.assertEqual(response.status_code, 200)