Blame view

src/core/pyros_django/scheduler/tests.py 28.8 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):
94336356   haribo   Added starting fi...
12

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
26
        self.scheduler.max_overhead = 1

b87b6d9b   haribo   Finished tests fo...
27
28
        scipro = ScientificProgram.objects.create()
        country = Country.objects.create()
94082e77   haribo   Date: 03/06/2016
29
        user_level = UserLevel.objects.create()
94336356   haribo   Added starting fi...
30

05f66454   ALEXIS-PC\alexis   adding and updati...
31
32
33
34
35
36
        self.usr1 = PyrosUser.objects.create(username="toto", country=country, quota=100)
        self.usr2 = PyrosUser.objects.create(username="titi", country=country, quota=100)
        self.usr3 = PyrosUser.objects.create(username="tata", country=country, quota=100)
        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

b87b6d9b   haribo   Finished tests fo...
109
110
111
112
113
114
115
116
        seq1.request.pyros_user.quota = 100
        seq1.request.pyros_user.save()
        seq2.request.pyros_user.quota = 100
        seq2.request.pyros_user.save()
        seq3.request.pyros_user.quota = 100
        seq3.request.pyros_user.save()

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

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

        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...
128

b87b6d9b   haribo   Finished tests fo...
129
130
131
132
133
134
135
136
137
138
139
        self.assertEqual(nbPlanned, 3)

        self.assertEqual(seq1.request.pyros_user.quota, 100 - 3)
        self.assertEqual(seq2.request.pyros_user.quota, 100 - 10)
        self.assertEqual(seq3.request.pyros_user.quota, 100 - 5)

    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...
140

b87b6d9b   haribo   Finished tests fo...
141
142
143
144
145
        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...
146
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
147
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
148
                                       name="seq1", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=3)
4b503f5c   jeremy   Update installer ...
149
        seq2 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
150
                                       name="seq2", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
151
        seq3 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
152
                                       name="seq3", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
153
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
154
155
                                       name="seq4", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=15)

b87b6d9b   haribo   Finished tests fo...
156
157
158
159
160
161
162
163
        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()

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

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

        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...
176

b87b6d9b   haribo   Finished tests fo...
177
178
179
180
181
182
183
184
185
186
187
        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)

    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...
188

b87b6d9b   haribo   Finished tests fo...
189
190
191
192
193
        print("\n===== TEST_3_SEQ_PRIORITY =====\n")

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

b87b6d9b   haribo   Finished tests fo...
194
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
195
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
196
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
197
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
198
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
4b503f5c   jeremy   Update installer ...
199
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
200
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=10)
b87b6d9b   haribo   Finished tests fo...
201
202

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

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

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

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

b87b6d9b   haribo   Finished tests fo...
213
214
        self.assertEqual(nbPlanned, 1)

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

b87b6d9b   haribo   Finished tests fo...
217
218
219
220
221
    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...
222

b87b6d9b   haribo   Finished tests fo...
223
224
225
226
227
        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...
228
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
229
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
230
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
4b503f5c   jeremy   Update installer ...
231
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
232
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
4b503f5c   jeremy   Update installer ...
233
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
234
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=12)
b87b6d9b   haribo   Finished tests fo...
235
236

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

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

7a79e25b   haribo   Date: 19/05/2016
243
244
245
        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...
246
247

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

b87b6d9b   haribo   Finished tests fo...
249
250
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
251
252
253
254
        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...
255

7a79e25b   haribo   Date: 19/05/2016
256
257
258
259
        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...
260

7a79e25b   haribo   Date: 19/05/2016
261
262
263
264
        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...
265
266
267
268
269
270

    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...
271

b87b6d9b   haribo   Finished tests fo...
272
273
274
275
276
        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...
277
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
278
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
279
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=11, duration=20)
4b503f5c   jeremy   Update installer ...
280
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
281
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
4b503f5c   jeremy   Update installer ...
282
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
283
                                       name="seq3", jd1=0, jd2=200, priority=1, t_prefered=191, duration=20)
b87b6d9b   haribo   Finished tests fo...
284
285

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

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

bca9a283   Jeremy   Reworked the sche...
292
293
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
294
295
296
        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...
297
298

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

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

7a79e25b   haribo   Date: 19/05/2016
302
303
304
305
        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...
306

7a79e25b   haribo   Date: 19/05/2016
307
308
309
310
        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...
311

7a79e25b   haribo   Date: 19/05/2016
312
313
314
315
        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...
316
317
318
319
320
321

    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...
322

b87b6d9b   haribo   Finished tests fo...
323
324
325
326
327
        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...
328
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
329
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
330
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
4b503f5c   jeremy   Update installer ...
331
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
332
                                       name="seq2", jd1=0, jd2=200, priority=0, t_prefered=100, duration=20)
4b503f5c   jeremy   Update installer ...
333
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
334
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=100, duration=20)
b87b6d9b   haribo   Finished tests fo...
335
336

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

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

bca9a283   Jeremy   Reworked the sche...
343
344
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
345
346
347
        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...
348
349

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

b87b6d9b   haribo   Finished tests fo...
351

7a79e25b   haribo   Date: 19/05/2016
352
353
        self.assertEqual(shs1.tsp, 69)
        self.assertEqual(shs1.tep, 89)
92039557   haribo   Minor fix : t_pre...
354
        self.assertEqual(shs1.deltaTL, 68)
7a79e25b   haribo   Date: 19/05/2016
355
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
356

7a79e25b   haribo   Date: 19/05/2016
357
358
359
        self.assertEqual(shs2.tsp, 90)
        self.assertEqual(shs2.tep, 110)
        self.assertEqual(shs2.deltaTL, 0)
92039557   haribo   Minor fix : t_pre...
360
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
361

92039557   haribo   Minor fix : t_pre...
362
363
364
365
        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...
366
367
368
369
370

    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...
371
372
        '''

b87b6d9b   haribo   Finished tests fo...
373
374
375
        print("\n===== TEST_3_SEQ_MOVE_LEFT =====\n")

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

b87b6d9b   haribo   Finished tests fo...
378
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
379
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
380
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
4b503f5c   jeremy   Update installer ...
381
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
382
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
4b503f5c   jeremy   Update installer ...
383
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
384
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=15)
b87b6d9b   haribo   Finished tests fo...
385
386

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

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

bca9a283   Jeremy   Reworked the sche...
393
394
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
395
396
397
        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...
398
399

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

7a79e25b   haribo   Date: 19/05/2016
401
402
403
404
        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...
405

7a79e25b   haribo   Date: 19/05/2016
406
407
408
409
        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...
410

7a79e25b   haribo   Date: 19/05/2016
411
412
413
414
        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...
415
416
417
418
419

    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...
420
421
        '''

b87b6d9b   haribo   Finished tests fo...
422
423
424
        print("\n===== TEST_3_SEQ_MOVE_RIGHT =====\n")

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

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

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

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

bca9a283   Jeremy   Reworked the sche...
442
443
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
444
445
446
        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...
447
448

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

b87b6d9b   haribo   Finished tests fo...
450

7a79e25b   haribo   Date: 19/05/2016
451
452
453
454
        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...
455

7a79e25b   haribo   Date: 19/05/2016
456
457
458
459
        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...
460

7a79e25b   haribo   Date: 19/05/2016
461
462
463
464
        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...
465

b87b6d9b   haribo   Finished tests fo...
466
467
468
469
    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...
470
471
        '''

b87b6d9b   haribo   Finished tests fo...
472
473
474
        print("\n===== TEST_3_SEQ_MOVE_BOTH =====\n")

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

b87b6d9b   haribo   Finished tests fo...
477
        ''' create the sequences '''
4b503f5c   jeremy   Update installer ...
478
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
479
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
4b503f5c   jeremy   Update installer ...
480
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
481
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
4b503f5c   jeremy   Update installer ...
482
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
483
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=25)
b87b6d9b   haribo   Finished tests fo...
484
485

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

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

bca9a283   Jeremy   Reworked the sche...
492
493
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
494
495
496
        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...
497
498

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

7a79e25b   haribo   Date: 19/05/2016
500
501
502
503
        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...
504

7a79e25b   haribo   Date: 19/05/2016
505
506
507
508
        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...
509

7a79e25b   haribo   Date: 19/05/2016
510
511
512
513
        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...
514

b87b6d9b   haribo   Finished tests fo...
515
516
517
518
519
    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...
520

b87b6d9b   haribo   Finished tests fo...
521
522
523
524
525
        print("\n===== TEST_5_SEQ_STATUS =====\n")

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

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

        ''' compute and print the schedule '''
bca9a283   Jeremy   Reworked the sche...
539
        self.scheduler.makeSchedule()
7a79e25b   haribo   Date: 19/05/2016
540
541
542

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

7a79e25b   haribo   Date: 19/05/2016
545
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
b87b6d9b   haribo   Finished tests fo...
546
547
548
549
550
551
552
553

        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...
554

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

4b503f5c   jeremy   Update installer ...
557
558
        self.assertEqual(seq1.status, Sequence.PLANNED)
        self.assertEqual(shs2.status, Sequence.PLANNED)
b87b6d9b   haribo   Finished tests fo...
559
560
561
562
        self.assertEqual(seq3.status, Sequence.EXECUTED)
        self.assertEqual(seq4.status, Sequence.REJECTED)
        self.assertEqual(seq5.status, Sequence.UNPLANNABLE)

b87b6d9b   haribo   Finished tests fo...
563
564
    def test_4_seq_eligibility(self):
        '''
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
565
            goal: test if ineligible sequences are programmed
715fabb7   haribo   #3430 (100%)
566
            conditions: only ineligible sequences
b87b6d9b   haribo   Finished tests fo...
567
        '''
94336356   haribo   Added starting fi...
568

b87b6d9b   haribo   Finished tests fo...
569
570
        print("\n===== TEST_4_SEQ_ELIGIBILITY =====\n")

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
571
572
573
574
575
576
        # 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...
577
578
579
        self.scheduler.schedule.plan_start = 100
        self.scheduler.schedule.plan_end = 200

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
580
        ''' create 4 sequences (to be planned) with default status TOBEPLANNED '''
4b503f5c   jeremy   Update installer ...
581
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
582
                                       name="seq1", jd1=0, jd2=110, priority=1, t_prefered=-1, duration=20)
4b503f5c   jeremy   Update installer ...
583
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
584
                                       name="seq2", jd1=181, jd2=300, priority=1, t_prefered=-1, duration=20)
4b503f5c   jeremy   Update installer ...
585
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
586
                                       name="seq3", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=20)
4b503f5c   jeremy   Update installer ...
587
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
588
                                       name="seq4", jd1=300, jd2=400, priority=1, t_prefered=-1, duration=20)
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
589
590
591
592
        #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...
593
594

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

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
597
598
599
        # 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
600
        sched = Schedule.objects.order_by('-created')[0]
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
601
        print("updated schedule is", sched, "with night start", sched.plan_night_start)
7a79e25b   haribo   Date: 19/05/2016
602
        shs_list = sched.shs.all()
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
603
604
        # EP added
        self.assertEqual(len(shs_list), 0)
4b503f5c   jeremy   Update installer ...
605
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
606
        self.assertEqual(nbPlanned, 0)
b87b6d9b   haribo   Finished tests fo...
607

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
608
        ''' checks sequences status '''
b87b6d9b   haribo   Finished tests fo...
609
610
611
612
613
        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...
614
        for s in (seq1,seq2,seq3,seq4): print(s.status)
b87b6d9b   haribo   Finished tests fo...
615
        self.assertEqual(seq1.status, Sequence.UNPLANNABLE)
4b503f5c   jeremy   Update installer ...
616
        self.assertEqual(seq2.status, Sequence.TOBEPLANNED)
b87b6d9b   haribo   Finished tests fo...
617
        self.assertEqual(seq3.status, Sequence.UNPLANNABLE)
4b503f5c   jeremy   Update installer ...
618
        self.assertEqual(seq4.status, Sequence.TOBEPLANNED)
b87b6d9b   haribo   Finished tests fo...
619

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

b87b6d9b   haribo   Finished tests fo...
621
622
623
624
    def test_invalid_sequences(self):
        '''
            goal: test if the scheduler is able to plan invalid sequences (it shouldn't)
        '''
94336356   haribo   Added starting fi...
625

b87b6d9b   haribo   Finished tests fo...
626
627
628
629
630
        print("\n===== TEST_INVALID_SEQUENCES =====\n")

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

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

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

7a79e25b   haribo   Date: 19/05/2016
644
645
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
4b503f5c   jeremy   Update installer ...
646
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
b87b6d9b   haribo   Finished tests fo...
647
648
649
650
651
652
653

        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...
654

b87b6d9b   haribo   Finished tests fo...
655
656
657
658
        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...
659
        self.assertEqual(nbPlanned, 0)
a2283bf3   haribo   Date: 20/05/2016
660
661
662
663
664
665
666
667
668

    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 ...
669
        print("current dir is", os.getcwd())
a2283bf3   haribo   Date: 20/05/2016
670
        simulator.simulate(SIMULATION_FILE)