eds/cms/tests.py

53 lines
1.6 KiB
Python
Raw Normal View History

2018-05-23 15:17:03 +02:00
import os
from django.db.models import Sum
2017-04-07 09:17:20 +02:00
2018-05-22 16:04:39 +02:00
from django.conf import settings
from django.contrib.auth.models import User
from django.core import mail
2018-05-23 15:17:03 +02:00
from django.test import TestCase, Client
2018-05-22 16:04:39 +02:00
from django.urls import reverse
2017-04-07 09:17:20 +02:00
# Create your tests here.
2018-05-23 15:17:03 +02:00
from cms.models import Domaine, Processus, Module
2018-05-22 16:04:39 +02:00
class PdfTestCase(TestCase):
2018-05-23 15:17:03 +02:00
fixtures = ['enseignant.json', 'domaine.json', 'processus.json', 'module.json']
2018-05-22 16:04:39 +02:00
@classmethod
def setUpTestData(cls):
User.objects.create_superuser('me', 'me@example.org', 'mepassword')
def setUp(self):
2018-05-23 15:17:03 +02:00
self.client = Client()
2018-05-22 16:04:39 +02:00
self.client.login(username='me', password='mepassword')
2018-05-23 15:17:03 +02:00
def test_index(self):
response = self.client.get('')
self.assertGreater(len(response.content), 200)
2018-05-22 16:04:39 +02:00
def test_plan_pdf(self):
response = self.client.get(reverse('plan-pdf'))
self.assertEqual(
2018-05-23 15:17:03 +02:00
response['content-disposition'],
'attachment; filename="EDS_plan_formation.pdf"'
2018-05-22 16:04:39 +02:00
)
2018-05-23 15:17:03 +02:00
self.assertEqual(response['content-type'], 'application/pdf')
2018-05-22 16:04:39 +02:00
self.assertGreater(len(response.content), 200)
2018-05-23 15:17:03 +02:00
def test_periode_presentiel(self):
tot = 0
for m in Module.objects.all():
tot += m.total_presentiel
tot = Module.objects.aggregate(Sum('total_presentiel'))
self.assertEqual(tot, 1200)
def test_periode_pratique(self):
tot = Module.objects.aggregate(Sum('pratique_prof'))
self.assertEqual(tot['pratique_prof__sum'], 1200)
def test_periode_travail_perso(self):
tot = Module.objects.aggregate(Sum('travail_perso'))
self.assertEqual(tot['travail_perso__sum'], 1200)