tests.py
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from django.test import TestCase
from common.RequestBuilder import RequestBuilder
from pyrosapp.models import *
from django.contrib.auth.models import User
class RequestBuilderTests(TestCase):
fixtures = ['fixture_test.json']
def setUp(self):
'''
Creates the base for the tests : user, scientific program, etc
'''
country = Country.objects.create(name="France")
usr_lvl = UserLevel.objects.create(name="default")
usr = User.objects.create(username="toto")
self.pyusr = PyrosUser.objects.create(country=country, user=usr, userlevel=usr_lvl, quota=1111)
self.sp = ScientificProgram.objects.create(name="default")
def test_full_creation(self):
'''
Goal : Create a full request with sequences, albums & plans, and check if they are in the DB
'''
request_builder = RequestBuilder()
request_builder.start_new_request(self.pyusr, self.sp, False)
seq1 = request_builder.add_sequence(1, 0, 10, name="seq1")
alb11 = request_builder.add_album(seq1, Device.NIR, name="alb11")
request_builder.add_plan(
alb11, Device.NIR_FILTER_1, 120, 5, name="plan111")
alb12 = request_builder.add_album(seq1, Device.VIS, name="alb12")
request_builder.add_plan(
alb12, Device.VIS_FILTER_1, 180, 1, name="plan121")
seq2 = request_builder.add_sequence(1, 0, 10, name="seq2")
alb21 = request_builder.add_album(seq2, Device.NIR, name="alb21")
request_builder.add_plan(
alb21, Device.NIR_FILTER_2, 60, 3, name="plan211")
request_builder.validate_request()
req = Request.objects.get()
seq1 = Sequence.objects.get(name="seq1")
seq2 = Sequence.objects.get(name="seq2")
albums = Album.objects.all()
self.assertEqual(len(req.sequences.all()), 2, "There should be 2 sequences")
self.assertEqual(seq1.albums.count(), 2, "There should be 2 albums in seq1")
self.assertEqual(seq2.albums.count(), 1, "There should be 1 album in seq2")
self.assertEqual(Plan.objects.count(), 3, "There should be 3 plans")
self.assertEqual(len(albums), 3, "There should be 3 albums")
for album in albums:
self.assertEqual(album.plans.count(), 1, "There should be 1 plan in each album")