med/media/tests/test_templates.py

65 lines
2.0 KiB
Python
Raw Normal View History

2019-08-16 17:44:27 +00:00
# -*- mode: python; coding: utf-8 -*-
# SPDX-License-Identifier: GPL-3.0-or-later
from django.test import TestCase
from django.urls import reverse
2020-05-22 16:04:41 +00:00
from media.models import Auteur, BD
2019-08-16 17:44:27 +00:00
from users.models import User
2019-08-16 18:14:52 +00:00
2019-08-16 17:44:27 +00:00
"""
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
2020-05-22 19:08:44 +00:00
self.dummy_bd1 = BD.objects.create(
2019-08-16 17:44:27 +00:00
title="Test media",
side_identifier="T M",
)
2020-05-22 19:08:44 +00:00
self.dummy_bd1.authors.add(self.dummy_author)
self.dummy_bd2 = BD.objects.create(
2019-08-16 17:44:27 +00:00
title="Test media bis",
side_identifier="T M 2",
external_url="https://example.com/",
)
2020-05-22 19:08:44 +00:00
self.dummy_bd2.authors.add(self.dummy_author)
2019-08-16 17:44:27 +00:00
2020-05-22 19:08:44 +00:00
def test_bd_bd_changelist(self):
response = self.client.get(reverse('admin:media_bd_changelist'))
2019-08-16 17:44:27 +00:00
self.assertEqual(response.status_code, 200)
2020-05-22 19:08:44 +00:00
def test_bd_bd_add(self):
response = self.client.get(reverse('admin:media_bd_add'))
2019-08-16 17:44:27 +00:00
self.assertEqual(response.status_code, 200)
2020-05-22 19:08:44 +00:00
def test_bd_isbn_download(self):
2019-08-16 17:44:27 +00:00
data = {
2020-05-12 13:09:06 +00:00
'_isbn': True,
2019-08-16 17:44:27 +00:00
'isbn': "0316358525",
}
response = self.client.post(reverse(
2020-05-22 19:08:44 +00:00
'admin:media_bd_change',
args=[self.dummy_bd1.id],
2019-08-16 17:44:27 +00:00
), data=data)
2020-02-10 04:03:53 +00:00
self.assertEqual(response.status_code, 302)
2019-08-16 17:44:27 +00:00
2020-05-22 19:08:44 +00:00
def test_bd_emprunt_changelist(self):
2019-08-16 17:44:27 +00:00
response = self.client.get(reverse('admin:media_emprunt_changelist'))
self.assertEqual(response.status_code, 200)
2020-05-22 19:08:44 +00:00
def test_bd_emprunt_add(self):
2019-08-16 17:44:27 +00:00
response = self.client.get(reverse('admin:media_emprunt_add'))
self.assertEqual(response.status_code, 200)