Blame view

src/common/tests.py 2.3 KB
fafae58f   haribo   Cleaned directory
1
from django.test import TestCase
7c87794b   haribo   Date: 20/05/2016
2
3
4
from common.RequestBuilder import RequestBuilder
from pyrosapp.models import *
from django.contrib.auth.models import User
fafae58f   haribo   Cleaned directory
5

7c87794b   haribo   Date: 20/05/2016
6
7
class RequestBuilderTests(TestCase):

94082e77   haribo   Date: 03/06/2016
8
    fixtures = ['basic_fixture.json']
7c87794b   haribo   Date: 20/05/2016
9
10
11
12
13
14
15
16
17

    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")
94082e77   haribo   Date: 03/06/2016
18
        self.pyusr = PyrosUser.objects.create(country=country, user=usr, user_level=usr_lvl, quota=1111)
7c87794b   haribo   Date: 20/05/2016
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
        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")