Blame view

src/core/pyros_django/scheduler/tests.py 29.1 KB
7a1effdd   haribo   scheduler app cre...
1
from django.test import TestCase
ddf59dd4   haribo   Remaniement :
2
3
from scheduler.Scheduler import Scheduler
from common.models import *
a2283bf3   haribo   Date: 20/05/2016
4
from scheduler.simulator import Simulator
7a1effdd   haribo   scheduler app cre...
5

f49b7078   Etienne Pallier   Bugfix tests and ...
6
7
import os

a2283bf3   haribo   Date: 20/05/2016
8
SIMULATION_FILE = 'file:./scheduler/sequences_cador.html'
b87b6d9b   haribo   Finished tests fo...
9

bca9a283   Jeremy   Reworked the sche...
10

b87b6d9b   haribo   Finished tests fo...
11
class SchedulerTest(TestCase):
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
12
    fixtures = ['tests/common_test_TZ.json']
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
13
    # (EP) Create a fixture in memory with 1 scheduler, 3 requests belonging to 3 different users
b87b6d9b   haribo   Finished tests fo...
14
15
16
17
18
19
    def setUp(self):
        '''
            Creates the scheduler
            Creates 3 users (and associated needs)
            Creates 3 requests

94082e77   haribo   Date: 03/06/2016
20
            Creates associated needs : scientific program, country, user_level
b87b6d9b   haribo   Finished tests fo...
21
        '''
94336356   haribo   Added starting fi...
22

b87b6d9b   haribo   Finished tests fo...
23
        self.scheduler = Scheduler()
94336356   haribo   Added starting fi...
24

7a79e25b   haribo   Date: 19/05/2016
25
        self.scheduler.max_overhead = 1
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
26
27
        institute = Institute.objects.get(id=1)
        scipro = ScientificProgram.objects.get(id=1)
b87b6d9b   haribo   Finished tests fo...
28
        country = Country.objects.create()
94082e77   haribo   Date: 03/06/2016
29
        user_level = UserLevel.objects.create()
94336356   haribo   Added starting fi...
30

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
31
32
33
        self.usr1 = PyrosUser.objects.create(username="toto", country=country, institute=institute)
        self.usr2 = PyrosUser.objects.create(username="titi", country=country, institute=institute)
        self.usr3 = PyrosUser.objects.create(username="tata", country=country, institute=institute)
05f66454   ALEXIS-PC\alexis   adding and updati...
34
35
36
        for user in PyrosUser.objects.all():
            # associate each user to the same userlevel
            UserLevel.objects.all()[0].pyros_users.add(user)
ee2c4543   Etienne Pallier   Bugfix Monitoring...
37
38
39
        self.req1 = Request.objects.create(pyros_user=self.usr1, scientific_program=scipro)
        self.req2 = Request.objects.create(pyros_user=self.usr2, scientific_program=scipro)
        self.req3 = Request.objects.create(pyros_user=self.usr3, scientific_program=scipro)
94336356   haribo   Added starting fi...
40

b87b6d9b   haribo   Finished tests fo...
41
42
43
44
45
    def test_basic_3_seq(self):
        '''
            goal : test if 3 distinct sequences are put into the planning
            conditions : the sequence have the same priority, and have no jd overlap
        '''
94336356   haribo   Added starting fi...
46

b87b6d9b   haribo   Finished tests fo...
47
        print("\n===== TEST_BASIC_3_SEQ =====\n")
94336356   haribo   Added starting fi...
48

b87b6d9b   haribo   Finished tests fo...
49
50
51
52
        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 10

        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
53
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
54
                                       name="seq1", jd1=0, jd2=2, priority=1, t_prefered=-1, duration=1)
4b503f5c   jeremy   Update installer ...
55
        seq2 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
56
                                       name="seq2", jd1=4, jd2=6, priority=1, t_prefered=-1, duration=1)
4b503f5c   jeremy   Update installer ...
57
        seq3 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
58
59
                                       name="seq3", jd1=7, jd2=9, priority=1, t_prefered=-1, duration=1)

b87b6d9b   haribo   Finished tests fo...
60
        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
61
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
62

7a79e25b   haribo   Date: 19/05/2016
63
64
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
65
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
94336356   haribo   Added starting fi...
66

bca9a283   Jeremy   Reworked the sche...
67
68
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
69
70
71
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
72
73

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
74

7a79e25b   haribo   Date: 19/05/2016
75
76
77
78
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 2)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
79

7a79e25b   haribo   Date: 19/05/2016
80
81
82
83
        self.assertEqual(shs2.tsp, 4)
        self.assertEqual(shs2.tep, 5)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 1)
b87b6d9b   haribo   Finished tests fo...
84

7a79e25b   haribo   Date: 19/05/2016
85
86
87
88
        self.assertEqual(shs3.tsp, 7)
        self.assertEqual(shs3.tep, 8)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 1)
b87b6d9b   haribo   Finished tests fo...
89

b87b6d9b   haribo   Finished tests fo...
90
91
92
93
94
    def test_3_seq_with_quotas(self):
        '''
            goal : test if the quotas are decreased
            conditions : the sequences have the same priority, and various durations
        '''
94336356   haribo   Added starting fi...
95

b87b6d9b   haribo   Finished tests fo...
96
97
98
99
100
        print("\n===== TEST_3_SEQ_WITH_QUOTAS =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 100

b87b6d9b   haribo   Finished tests fo...
101
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
102
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
7a79e25b   haribo   Date: 19/05/2016
103
                                       name="seq1", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=3)
4b503f5c   jeremy   Update installer ...
104
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
7a79e25b   haribo   Date: 19/05/2016
105
                                       name="seq2", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
106
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
7a79e25b   haribo   Date: 19/05/2016
107
                                       name="seq3", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=5)
94336356   haribo   Added starting fi...
108

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
109
110
        # TODO : change quota gestion with rework of PyrosUser table
        """ seq1.request.pyros_user.quota = 100
b87b6d9b   haribo   Finished tests fo...
111
112
113
114
        seq1.request.pyros_user.save()
        seq2.request.pyros_user.quota = 100
        seq2.request.pyros_user.save()
        seq3.request.pyros_user.quota = 100
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
115
        seq3.request.pyros_user.save() """
b87b6d9b   haribo   Finished tests fo...
116
117

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
118
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
119

7a79e25b   haribo   Date: 19/05/2016
120
121
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
122
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
123
124
125
126
127
128

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks sequence owners' quotas '''
94336356   haribo   Added starting fi...
129

b87b6d9b   haribo   Finished tests fo...
130
131
        self.assertEqual(nbPlanned, 3)

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
132
        """
b87b6d9b   haribo   Finished tests fo...
133
134
        self.assertEqual(seq1.request.pyros_user.quota, 100 - 3)
        self.assertEqual(seq2.request.pyros_user.quota, 100 - 10)
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
135
136
        self.assertEqual(seq3.request.pyros_user.quota, 100 - 5) 
        """
b87b6d9b   haribo   Finished tests fo...
137
138
139
140
141
142

    def test_4_seq_insufficient_quotas(self):
        '''
            goal : test if an insufficient quota blocks sequence programmation
            conditions : the sequences have the same priority, a user has 2 sequence, the others have 1 Sequence
        '''
94336356   haribo   Added starting fi...
143

b87b6d9b   haribo   Finished tests fo...
144
145
146
147
148
        print("\n===== TEST_4_SEQ_INSUFFICIENT_QUOTAS =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 100

b87b6d9b   haribo   Finished tests fo...
149
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
150
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
151
                                       name="seq1", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=3)
4b503f5c   jeremy   Update installer ...
152
        seq2 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
153
                                       name="seq2", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
154
        seq3 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
155
                                       name="seq3", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
156
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
157
158
                                       name="seq4", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=15)

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
159
        """
b87b6d9b   haribo   Finished tests fo...
160
161
162
163
164
165
        seq1.request.pyros_user.quota = 11
        seq1.request.pyros_user.save()
        seq3.request.pyros_user.quota = 10
        seq3.request.pyros_user.save()
        seq4.request.pyros_user.quota = 14
        seq4.request.pyros_user.save()
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
166
        """
b87b6d9b   haribo   Finished tests fo...
167
168

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
169
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
170

7a79e25b   haribo   Date: 19/05/2016
171
172
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
173
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
174
175
176
177
178
179
180

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")
        seq4 = Sequence.objects.get(name="seq4")

        ''' checks sequence owners' quotas '''
94336356   haribo   Added starting fi...
181

2fdcd8bb   Alexis Koralewski   adapt tests to ne...
182
183
        # TODO : adapt test to new quotas
        """
b87b6d9b   haribo   Finished tests fo...
184
185
186
187
188
        self.assertEqual(nbPlanned, 2)

        self.assertEqual(seq1.request.pyros_user.quota, 11 - 3 - 0)
        self.assertEqual(seq3.request.pyros_user.quota, 10 - 10)
        self.assertEqual(seq4.request.pyros_user.quota, 14 - 0)
2fdcd8bb   Alexis Koralewski   adapt tests to ne...
189
        """
b87b6d9b   haribo   Finished tests fo...
190
191
192
193
194
    def test_3_seq_priority(self):
        '''
            goal : test if the priority is taken into account when there isn't enough room
            conditions : sequences have different priorities, are visible the whole night and can't be all put
        '''
94336356   haribo   Added starting fi...
195

b87b6d9b   haribo   Finished tests fo...
196
197
198
199
200
        print("\n===== TEST_3_SEQ_PRIORITY =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 20

b87b6d9b   haribo   Finished tests fo...
201
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
202
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
203
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
204
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
205
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
4b503f5c   jeremy   Update installer ...
206
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
207
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=10)
b87b6d9b   haribo   Finished tests fo...
208
209

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
210
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
211

7a79e25b   haribo   Date: 19/05/2016
212
213
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
214
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
215

7a79e25b   haribo   Date: 19/05/2016
216
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
b87b6d9b   haribo   Finished tests fo...
217
218

        ''' checks which sequence is planned '''
94336356   haribo   Added starting fi...
219

b87b6d9b   haribo   Finished tests fo...
220
221
        self.assertEqual(nbPlanned, 1)

4b503f5c   jeremy   Update installer ...
222
        self.assertEqual(shs2.status, Sequence.PLANNED)
b87b6d9b   haribo   Finished tests fo...
223

b87b6d9b   haribo   Finished tests fo...
224
225
226
227
228
    def test_3_seq_priority_overlap(self):
        '''
            goal : test if the sequences are arranged according to the priorities
            conditions : sequences have different priorities, are visible the whole night and can be all put (enough room)
        '''
94336356   haribo   Added starting fi...
229

b87b6d9b   haribo   Finished tests fo...
230
231
232
233
234
        print("\n===== TEST_3_SEQ_PRIORITY_OVERLAP =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
235
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
236
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
237
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
238
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
239
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
4b503f5c   jeremy   Update installer ...
240
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
241
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=12)
b87b6d9b   haribo   Finished tests fo...
242
243

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
244
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
245

7a79e25b   haribo   Date: 19/05/2016
246
247
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
248
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
249

7a79e25b   haribo   Date: 19/05/2016
250
251
252
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
253
254

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
255

b87b6d9b   haribo   Finished tests fo...
256
257
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
258
259
260
261
        self.assertEqual(shs2.tsp, 1)
        self.assertEqual(shs2.tep, 12)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 0)
94336356   haribo   Added starting fi...
262

7a79e25b   haribo   Date: 19/05/2016
263
264
265
266
        self.assertEqual(shs1.tsp, 13)
        self.assertEqual(shs1.tep, 23)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
267

7a79e25b   haribo   Date: 19/05/2016
268
269
270
271
        self.assertEqual(shs3.tsp, 24)
        self.assertEqual(shs3.tep, 36)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 200 - shs3.tep)
b87b6d9b   haribo   Finished tests fo...
272
273
274
275
276
277

    def test_3_seq_t_prefered(self):
        '''
            goal: test if the sequences are wall_arranged with t_prefered
            conditions : various t_prefered that should put the sequences at the beginning, the middle and the end of the night
        '''
94336356   haribo   Added starting fi...
278

b87b6d9b   haribo   Finished tests fo...
279
280
281
282
283
        print("\n===== TEST_3_SEQ_T_PREFERED =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
284
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
285
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
286
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=11, duration=20)
4b503f5c   jeremy   Update installer ...
287
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
288
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
4b503f5c   jeremy   Update installer ...
289
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
290
                                       name="seq3", jd1=0, jd2=200, priority=1, t_prefered=191, duration=20)
b87b6d9b   haribo   Finished tests fo...
291
292

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
293
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
294

7a79e25b   haribo   Date: 19/05/2016
295
296
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
297
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
298

bca9a283   Jeremy   Reworked the sche...
299
300
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
301
302
303
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
304
305

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
306

bca9a283   Jeremy   Reworked the sche...
307
        self.scheduler.logSchedule()
b87b6d9b   haribo   Finished tests fo...
308

7a79e25b   haribo   Date: 19/05/2016
309
310
311
312
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 21)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, shs2.tsp - 1 - shs1.tep)
94336356   haribo   Added starting fi...
313

7a79e25b   haribo   Date: 19/05/2016
314
315
316
317
        self.assertEqual(shs2.tsp, 90)
        self.assertEqual(shs2.tep, 110)
        self.assertEqual(shs2.deltaTL, shs1.deltaTR)
        self.assertEqual(shs2.deltaTR, shs3.tsp - 1 - shs2.tep)
b87b6d9b   haribo   Finished tests fo...
318

7a79e25b   haribo   Date: 19/05/2016
319
320
321
322
        self.assertEqual(shs3.tsp, 180)
        self.assertEqual(shs3.tep, 200)
        self.assertEqual(shs3.deltaTL, shs2.deltaTR)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
323
324
325
326
327
328

    def test_3_seq_t_prefered_priority(self):
        '''
            goal: test if the sequences are wall_arranged with t_prefered and priority
            conditions : various t_prefered that should put the sequences the middle of the night, according to priority
        '''
94336356   haribo   Added starting fi...
329

b87b6d9b   haribo   Finished tests fo...
330
331
332
333
334
        print("\n===== TEST_3_SEQ_T_PREFERED_PRIORITY =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
335
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
336
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
337
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
4b503f5c   jeremy   Update installer ...
338
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
339
                                       name="seq2", jd1=0, jd2=200, priority=0, t_prefered=100, duration=20)
4b503f5c   jeremy   Update installer ...
340
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
341
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=100, duration=20)
b87b6d9b   haribo   Finished tests fo...
342
343

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
344
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
345

7a79e25b   haribo   Date: 19/05/2016
346
347
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
348
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
349

bca9a283   Jeremy   Reworked the sche...
350
351
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
352
353
354
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
355
356

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
357

b87b6d9b   haribo   Finished tests fo...
358

7a79e25b   haribo   Date: 19/05/2016
359
360
        self.assertEqual(shs1.tsp, 69)
        self.assertEqual(shs1.tep, 89)
92039557   haribo   Minor fix : t_pre...
361
        self.assertEqual(shs1.deltaTL, 68)
7a79e25b   haribo   Date: 19/05/2016
362
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
363

7a79e25b   haribo   Date: 19/05/2016
364
365
366
        self.assertEqual(shs2.tsp, 90)
        self.assertEqual(shs2.tep, 110)
        self.assertEqual(shs2.deltaTL, 0)
92039557   haribo   Minor fix : t_pre...
367
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
368

92039557   haribo   Minor fix : t_pre...
369
370
371
372
        self.assertEqual(shs3.tsp, 111)
        self.assertEqual(shs3.tep, 131)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 200 - shs3.tep)
b87b6d9b   haribo   Finished tests fo...
373
374
375
376
377

    def test_3_seq_move_left(self):
        '''
            goal: test if a sequence can move to the left to let another one
            conditions : use priorities to place 2 sequences with an interval between, then try to put a bigger sequence in it
94336356   haribo   Added starting fi...
378
379
        '''

b87b6d9b   haribo   Finished tests fo...
380
381
382
        print("\n===== TEST_3_SEQ_MOVE_LEFT =====\n")

        self.scheduler.schedule.plan_start = 0
7a79e25b   haribo   Date: 19/05/2016
383
        self.scheduler.schedule.plan_end = 58
b87b6d9b   haribo   Finished tests fo...
384

b87b6d9b   haribo   Finished tests fo...
385
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
386
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
387
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
4b503f5c   jeremy   Update installer ...
388
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
389
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
4b503f5c   jeremy   Update installer ...
390
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
391
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=15)
b87b6d9b   haribo   Finished tests fo...
392
393

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
394
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
395

7a79e25b   haribo   Date: 19/05/2016
396
397
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
398
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
399

bca9a283   Jeremy   Reworked the sche...
400
401
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
402
403
404
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
405
406

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
407

7a79e25b   haribo   Date: 19/05/2016
408
409
410
411
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 21)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
412

7a79e25b   haribo   Date: 19/05/2016
413
414
415
416
        self.assertEqual(shs2.tsp, 38)
        self.assertEqual(shs2.tep, 58)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
417

7a79e25b   haribo   Date: 19/05/2016
418
419
420
421
        self.assertEqual(shs3.tsp, 22)
        self.assertEqual(shs3.tep, 37)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
422
423
424
425
426

    def test_3_seq_move_right(self):
        '''
            goal: test if a sequence can move to the right to let another one
            conditions : use priorities to place 2 sequences with an interval between, then try to put a bigger sequence in it
94336356   haribo   Added starting fi...
427
428
        '''

b87b6d9b   haribo   Finished tests fo...
429
430
431
        print("\n===== TEST_3_SEQ_MOVE_RIGHT =====\n")

        self.scheduler.schedule.plan_start = 0
7a79e25b   haribo   Date: 19/05/2016
432
        self.scheduler.schedule.plan_end = 67
b87b6d9b   haribo   Finished tests fo...
433

b87b6d9b   haribo   Finished tests fo...
434
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
435
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
436
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
4b503f5c   jeremy   Update installer ...
437
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
7a79e25b   haribo   Date: 19/05/2016
438
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=47, duration=20)
4b503f5c   jeremy   Update installer ...
439
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
440
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=20)
b87b6d9b   haribo   Finished tests fo...
441
442

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
443
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
444

7a79e25b   haribo   Date: 19/05/2016
445
446
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
447
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
448

bca9a283   Jeremy   Reworked the sche...
449
450
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
451
452
453
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
454
455

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
456

b87b6d9b   haribo   Finished tests fo...
457

7a79e25b   haribo   Date: 19/05/2016
458
459
460
461
        self.assertEqual(shs1.tsp, 5)
        self.assertEqual(shs1.tep, 25)
        self.assertEqual(shs1.deltaTL, 4)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
462

7a79e25b   haribo   Date: 19/05/2016
463
464
465
466
        self.assertEqual(shs2.tsp, 47)
        self.assertEqual(shs2.tep, 67)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
467

7a79e25b   haribo   Date: 19/05/2016
468
469
470
471
        self.assertEqual(shs3.tsp, 26)
        self.assertEqual(shs3.tep, 46)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
472

b87b6d9b   haribo   Finished tests fo...
473
474
475
476
    def test_3_seq_move_both(self):
        '''
            goal: test if a sequence can move to the let AND the right to let another one
            conditions : use priorities to place 2 sequences with an interval between, then try to put a bigger sequence in it
94336356   haribo   Added starting fi...
477
478
        '''

b87b6d9b   haribo   Finished tests fo...
479
480
481
        print("\n===== TEST_3_SEQ_MOVE_BOTH =====\n")

        self.scheduler.schedule.plan_start = 0
7a79e25b   haribo   Date: 19/05/2016
482
        self.scheduler.schedule.plan_end = 68
b87b6d9b   haribo   Finished tests fo...
483

b87b6d9b   haribo   Finished tests fo...
484
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
485
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
486
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
4b503f5c   jeremy   Update installer ...
487
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
488
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
4b503f5c   jeremy   Update installer ...
489
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
490
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=25)
b87b6d9b   haribo   Finished tests fo...
491
492

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
493
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
494

7a79e25b   haribo   Date: 19/05/2016
495
496
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
497
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
498

bca9a283   Jeremy   Reworked the sche...
499
500
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
501
502
503
        shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
        shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
b87b6d9b   haribo   Finished tests fo...
504
505

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
506

7a79e25b   haribo   Date: 19/05/2016
507
508
509
510
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 21)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
511

7a79e25b   haribo   Date: 19/05/2016
512
513
514
515
        self.assertEqual(shs2.tsp, 48)
        self.assertEqual(shs2.tep, 68)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
516

7a79e25b   haribo   Date: 19/05/2016
517
518
519
520
        self.assertEqual(shs3.tsp, 22)
        self.assertEqual(shs3.tep, 47)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
521

b87b6d9b   haribo   Finished tests fo...
522
523
524
525
526
    def test_5_seq_status(self):
        '''
            goal: test the evolution of sequences status
            conditions: 5 identical sequences with different status at the beginning
        '''
94336356   haribo   Added starting fi...
527

b87b6d9b   haribo   Finished tests fo...
528
529
530
531
532
        print("\n===== TEST_5_SEQ_STATUS =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
533
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
534
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
535
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
4b503f5c   jeremy   Update installer ...
536
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
537
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
538
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.EXECUTED,
94336356   haribo   Added starting fi...
539
                                       name="seq3", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
540
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.REJECTED,
94336356   haribo   Added starting fi...
541
                                       name="seq4", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
542
        seq5 = Sequence.objects.create(request=self.req3, status=Sequence.UNPLANNABLE,
94336356   haribo   Added starting fi...
543
                                       name="seq5", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
b87b6d9b   haribo   Finished tests fo...
544
545

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
546
        self.scheduler.makeSchedule()
7a79e25b   haribo   Date: 19/05/2016
547
548
549

        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
550
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
94336356   haribo   Added starting fi...
551

7a79e25b   haribo   Date: 19/05/2016
552
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
b87b6d9b   haribo   Finished tests fo...
553
554
555
556
557
558
559
560

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")
        seq4 = Sequence.objects.get(name="seq4")
        seq5 = Sequence.objects.get(name="seq5")

        ''' checks sequences status '''
94336356   haribo   Added starting fi...
561

4b503f5c   jeremy   Update installer ...
562
        self.assertEqual(nbPlanned, 2)
94336356   haribo   Added starting fi...
563

4b503f5c   jeremy   Update installer ...
564
565
        self.assertEqual(seq1.status, Sequence.PLANNED)
        self.assertEqual(shs2.status, Sequence.PLANNED)
b87b6d9b   haribo   Finished tests fo...
566
567
568
569
        self.assertEqual(seq3.status, Sequence.EXECUTED)
        self.assertEqual(seq4.status, Sequence.REJECTED)
        self.assertEqual(seq5.status, Sequence.UNPLANNABLE)

b87b6d9b   haribo   Finished tests fo...
570
571
    def test_4_seq_eligibility(self):
        '''
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
572
            goal: test if ineligible sequences are programmed
715fabb7   haribo   #3430 (100%)
573
            conditions: only ineligible sequences
b87b6d9b   haribo   Finished tests fo...
574
        '''
94336356   haribo   Added starting fi...
575

b87b6d9b   haribo   Finished tests fo...
576
577
        print("\n===== TEST_4_SEQ_ELIGIBILITY =====\n")

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
578
579
580
581
582
583
        # Check that only 1 EMPTY schedule is available in DB (because of Scheduler() instance created in setup())
        self.assertEqual(len(Schedule.objects.all()) , 1)
        sched = Schedule.objects.order_by('-created')[0]
        print("schedule is", sched)
        self.assertEqual(len(sched.shs.all()), 0)

b87b6d9b   haribo   Finished tests fo...
584
585
586
        self.scheduler.schedule.plan_start = 100
        self.scheduler.schedule.plan_end = 200

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
587
        ''' create 4 sequences (to be planned) with default status TOBEPLANNED '''
4b503f5c   jeremy   Update installer ...
588
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
589
                                       name="seq1", jd1=0, jd2=110, priority=1, t_prefered=-1, duration=20)
4b503f5c   jeremy   Update installer ...
590
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
591
                                       name="seq2", jd1=181, jd2=300, priority=1, t_prefered=-1, duration=20)
4b503f5c   jeremy   Update installer ...
592
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
593
                                       name="seq3", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=20)
4b503f5c   jeremy   Update installer ...
594
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
595
                                       name="seq4", jd1=300, jd2=400, priority=1, t_prefered=-1, duration=20)
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
596
597
598
599
        #for s in (seq1,seq2,seq3,seq4): print(s.status)

        # Check that we now have exactly 4 sequences in DB
        self.assertEqual(len(Sequence.objects.all()) , 4)
b87b6d9b   haribo   Finished tests fo...
600
601

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
602
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
603

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
604
605
606
        # Check that still only 1 schedule available in DB, and 0 sequence in it
        self.assertEqual(len(Schedule.objects.all()) , 1)
        # Get the last (more recent) schedule saved by makeSchedule()
7a79e25b   haribo   Date: 19/05/2016
607
        sched = Schedule.objects.order_by('-created')[0]
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
608
        print("updated schedule is", sched, "with night start", sched.plan_night_start)
7a79e25b   haribo   Date: 19/05/2016
609
        shs_list = sched.shs.all()
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
610
611
        # EP added
        self.assertEqual(len(shs_list), 0)
4b503f5c   jeremy   Update installer ...
612
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
613
        self.assertEqual(nbPlanned, 0)
b87b6d9b   haribo   Finished tests fo...
614

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
615
        ''' checks sequences status '''
b87b6d9b   haribo   Finished tests fo...
616
617
618
619
620
        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")
        seq4 = Sequence.objects.get(name="seq4")

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
621
        for s in (seq1,seq2,seq3,seq4): print(s.status)
b87b6d9b   haribo   Finished tests fo...
622
        self.assertEqual(seq1.status, Sequence.UNPLANNABLE)
4b503f5c   jeremy   Update installer ...
623
        self.assertEqual(seq2.status, Sequence.TOBEPLANNED)
b87b6d9b   haribo   Finished tests fo...
624
        self.assertEqual(seq3.status, Sequence.UNPLANNABLE)
4b503f5c   jeremy   Update installer ...
625
        self.assertEqual(seq4.status, Sequence.TOBEPLANNED)
b87b6d9b   haribo   Finished tests fo...
626

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
627

b87b6d9b   haribo   Finished tests fo...
628
629
630
631
    def test_invalid_sequences(self):
        '''
            goal: test if the scheduler is able to plan invalid sequences (it shouldn't)
        '''
94336356   haribo   Added starting fi...
632

b87b6d9b   haribo   Finished tests fo...
633
634
635
636
637
        print("\n===== TEST_INVALID_SEQUENCES =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
638
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
639
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
640
                                       name="seq1", jd1=190, jd2=110, priority=1, t_prefered=-1, duration=20)
4b503f5c   jeremy   Update installer ...
641
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
642
                                       name="seq2", jd1=20, jd2=30, priority=1, t_prefered=-1, duration=20)
4b503f5c   jeremy   Update installer ...
643
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
644
                                       name="seq3", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=0)
4b503f5c   jeremy   Update installer ...
645
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
646
                                       name="seq4", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=-10)
b87b6d9b   haribo   Finished tests fo...
647
648

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
649
        self.scheduler.makeSchedule()
94336356   haribo   Added starting fi...
650

7a79e25b   haribo   Date: 19/05/2016
651
652
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
653
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
654
655
656
657
658
659
660

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")
        seq4 = Sequence.objects.get(name="seq4")

        ''' checks sequences status '''
94336356   haribo   Added starting fi...
661

b87b6d9b   haribo   Finished tests fo...
662
663
664
665
        self.assertEqual(seq1.status, Sequence.INVALID)
        self.assertEqual(seq2.status, Sequence.INVALID)
        self.assertEqual(seq3.status, Sequence.INVALID)
        self.assertEqual(seq4.status, Sequence.INVALID)
bca9a283   Jeremy   Reworked the sche...
666
        self.assertEqual(nbPlanned, 0)
a2283bf3   haribo   Date: 20/05/2016
667
668
669
670
671
672
673
674
675

    def test_simulation(self):
        '''
            goal : Uses the simulation module to make a schedule and test the validity of created sequences
        '''

        print("\n===== TEST_SIMULATION =====\n")

        simulator = Simulator()
f49b7078   Etienne Pallier   Bugfix tests and ...
676
        print("current dir is", os.getcwd())
a2283bf3   haribo   Date: 20/05/2016
677
        simulator.simulate(SIMULATION_FILE)