mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-12-24 18:22:24 +00:00
More testing
This commit is contained in:
parent
62faa241d2
commit
c2ab1e4bc5
@ -9,7 +9,12 @@ source =
|
||||
theme
|
||||
users
|
||||
omit =
|
||||
logs/tests/*.py
|
||||
logs/migrations/*.py
|
||||
media/tests/*.py
|
||||
media/migrations/*.py
|
||||
sporz/tests/*.py
|
||||
sporz/migrations/*.py
|
||||
theme/tests/*.py
|
||||
users/tests/*.py
|
||||
users/migrations/*.py
|
||||
|
@ -1,14 +0,0 @@
|
||||
{% extends "logs/sidebar.html" %}
|
||||
{% comment %}
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endcomment %}
|
||||
|
||||
{% block title %}Supression d'action{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
<h4>Attention, voulez-vous vraiment annuler cette action {{ objet_name }} ( {{ objet }} ) ?</h4>
|
||||
<input type="submit" value="Confirmer"/>
|
||||
</form>
|
||||
{% endblock %}
|
0
logs/tests/__init__.py
Normal file
0
logs/tests/__init__.py
Normal file
29
logs/tests/test_templates.py
Normal file
29
logs/tests/test_templates.py
Normal file
@ -0,0 +1,29 @@
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
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)
|
||||
|
||||
def test_logs_index(self):
|
||||
response = self.client.get(reverse("logs:index"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_logs_stats_actions(self):
|
||||
response = self.client.get(reverse("logs:stats-actions"))
|
||||
self.assertEqual(response.status_code, 200)
|
@ -23,7 +23,7 @@ class ISBNField(CharField):
|
||||
kwargs['verbose_name'] = kwargs[
|
||||
'verbose_name'] if 'verbose_name' in kwargs else u'ISBN'
|
||||
kwargs['validators'] = [isbn_validator]
|
||||
super(ISBNField, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {
|
||||
@ -31,10 +31,10 @@ class ISBNField(CharField):
|
||||
'validators': [isbn_validator],
|
||||
}
|
||||
defaults.update(kwargs)
|
||||
return super(ISBNField, self).formfield(**defaults)
|
||||
return super().formfield(**defaults)
|
||||
|
||||
def deconstruct(self):
|
||||
name, path, args, kwargs = super(ISBNField, self).deconstruct()
|
||||
name, path, args, kwargs = super().deconstruct()
|
||||
# Only include clean_isbn in kwarg if it's not the default value
|
||||
if not self.clean_isbn:
|
||||
kwargs['clean_isbn'] = self.clean_isbn
|
||||
@ -49,7 +49,7 @@ class ISBNField(CharField):
|
||||
if self.clean_isbn and value not in EMPTY_VALUES:
|
||||
cleaned_isbn = value.replace(' ', '').replace('-', '').upper()
|
||||
setattr(model_instance, self.attname, cleaned_isbn)
|
||||
return super(ISBNField, self).pre_save(model_instance, add)
|
||||
return super().pre_save(model_instance, add)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.value
|
||||
|
@ -7,14 +7,6 @@ import urllib.request
|
||||
|
||||
from django.forms import ModelForm
|
||||
|
||||
from .models import Emprunt
|
||||
|
||||
|
||||
class EmpruntForm(ModelForm):
|
||||
class Meta:
|
||||
model = Emprunt
|
||||
fields = ['media']
|
||||
|
||||
|
||||
class MediaAdminForm(ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
0
media/tests/__init__.py
Normal file
0
media/tests/__init__.py
Normal file
65
media/tests/test_templates.py
Normal file
65
media/tests/test_templates.py
Normal file
@ -0,0 +1,65 @@
|
||||
# -*- 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, Media
|
||||
from users.models import User
|
||||
from django.forms.models import model_to_dict
|
||||
"""
|
||||
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_media1 = Media.objects.create(
|
||||
title="Test media",
|
||||
side_identifier="T M",
|
||||
)
|
||||
self.dummy_media1.authors.add(self.dummy_author)
|
||||
self.dummy_media2 = Media.objects.create(
|
||||
title="Test media bis",
|
||||
side_identifier="T M 2",
|
||||
external_url="https://example.com/",
|
||||
)
|
||||
self.dummy_media2.authors.add(self.dummy_author)
|
||||
|
||||
def test_media_media_changelist(self):
|
||||
response = self.client.get(reverse('admin:media_media_changelist'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_media_media_add(self):
|
||||
response = self.client.get(reverse('admin:media_media_add'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_media_isbn_download(self):
|
||||
data = {
|
||||
'_continue': True,
|
||||
'isbn': "0316358525",
|
||||
}
|
||||
response = self.client.post(reverse(
|
||||
'admin:media_media_change',
|
||||
args=[self.dummy_media1.id],
|
||||
), data=data)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_media_emprunt_changelist(self):
|
||||
response = self.client.get(reverse('admin:media_emprunt_changelist'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_media_emprunt_add(self):
|
||||
response = self.client.get(reverse('admin:media_emprunt_add'))
|
||||
self.assertEqual(response.status_code, 200)
|
@ -8,7 +8,6 @@ Based on https://github.com/secnot/django-isbn-field
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from six import string_types
|
||||
from stdnum import isbn
|
||||
|
||||
|
||||
@ -16,16 +15,16 @@ def isbn_validator(raw_isbn):
|
||||
"""Check string is a valid ISBN number"""
|
||||
isbn_to_check = raw_isbn.replace('-', '').replace(' ', '')
|
||||
|
||||
if not isinstance(isbn_to_check, string_types):
|
||||
raise ValidationError(_(u'Invalid ISBN: Not a string'))
|
||||
if not isinstance(isbn_to_check, str):
|
||||
raise ValidationError(_('Invalid ISBN: Not a string'))
|
||||
|
||||
if len(isbn_to_check) != 10 and len(isbn_to_check) != 13:
|
||||
raise ValidationError(_(u'Invalid ISBN: Wrong length'))
|
||||
raise ValidationError(_('Invalid ISBN: Wrong length'))
|
||||
|
||||
if not isbn.is_valid(isbn_to_check):
|
||||
raise ValidationError(_(u'Invalid ISBN: Failed checksum'))
|
||||
raise ValidationError(_('Invalid ISBN: Failed checksum'))
|
||||
|
||||
if isbn_to_check != isbn_to_check.upper():
|
||||
raise ValidationError(_(u'Invalid ISBN: Only upper case allowed'))
|
||||
raise ValidationError(_('Invalid ISBN: Only upper case allowed'))
|
||||
|
||||
return True
|
||||
|
@ -108,7 +108,7 @@ class Player(models.Model):
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.user)
|
||||
return str(self.name)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("player")
|
||||
|
0
users/tests/__init__.py
Normal file
0
users/tests/__init__.py
Normal file
50
users/tests/test_templates.py
Normal file
50
users/tests/test_templates.py
Normal file
@ -0,0 +1,50 @@
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.core import mail
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
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)
|
||||
|
||||
def test_users_edit_info(self):
|
||||
response = self.client.get(reverse('users:edit-info'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_users_user_changelist(self):
|
||||
response = self.client.get(reverse('admin:users_user_changelist'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_users_user_creation_form(self):
|
||||
response = self.client.get(reverse('admin:users_user_add'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_users_user_add_init_mail(self):
|
||||
"""
|
||||
Test that an initialization mail is send when a new user is added
|
||||
"""
|
||||
data = {
|
||||
'username': "test_user",
|
||||
'email': "test@example.com",
|
||||
'first_name': "Test",
|
||||
'last_name': "User",
|
||||
}
|
||||
response = self.client.post(reverse(
|
||||
'admin:users_user_add',
|
||||
), data=data)
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
self.assertEqual(response.status_code, 302)
|
Loading…
Reference in New Issue
Block a user