Commit fd99569d4f69024ee2d7ea1d8ce4431a18a57a05
1 parent
5a1d9029
Exists in
master
and in
1 other branch
Date: 22/06/2016
By: Paul Carensac Version: 0.7.7 Tests for Alert, User and Routine Managers Issues (closed): https://projects.irap.omp.eu/issues/3833 Major current version (0.7): https://projects.irap.omp.eu/versions/117
Showing
15 changed files
with
963 additions
and
28 deletions
Show diff stats
README.md
... | ... | @@ -60,11 +60,11 @@ PROJECT STRUCTURE: |
60 | 60 | -------------------------------------------------------------------------------------------- |
61 | 61 | CURRENT VERSION |
62 | 62 | |
63 | -Date: 20/06/2016 | |
63 | +Date: 22/06/2016 | |
64 | 64 | By: Paul Carensac |
65 | -Version: 0.7.6 | |
66 | -Colors + buttons submit on request list, and fixed a redirection bug in request building | |
67 | -Issues (closed): https://projects.irap.omp.eu/issues/3838 | |
65 | +Version: 0.7.7 | |
66 | +Tests for Alert, User and Routine Managers | |
67 | +Issues (closed): https://projects.irap.omp.eu/issues/3833 | |
68 | 68 | Major current version (0.7): https://projects.irap.omp.eu/versions/117 |
69 | 69 | |
70 | 70 | ROADMAP: https://projects.irap.omp.eu/projects/pyros/roadmap | ... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +<?xml version = '1.0' encoding = 'UTF-8'?> | |
2 | +<request> | |
3 | + | |
4 | + <sequence> | |
5 | + | |
6 | + <album detector='Cagire'> | |
7 | + | |
8 | + <plan filter='First infrared filter' duration='30' nb_images='5'/> | |
9 | + | |
10 | + <plan filter='Second infrared filter' duration='60' nb_images='6'/> | |
11 | + | |
12 | + </album> | |
13 | + | |
14 | + <album detector='Visible camera'> | |
15 | + | |
16 | + <plan filter='First visible filter' duration='20' nb_images='1'/> | |
17 | + | |
18 | + </album> | |
19 | + | |
20 | + </sequence> | |
21 | + | |
22 | + <sequence> | |
23 | + | |
24 | + <album detector='Cagire'> | |
25 | + | |
26 | + <plan filter='First infrared filter' duration='120' nb_images='10'/> | |
27 | + | |
28 | + <plan filter='Second infrared filter' duration='30' nb_images='5'/> | |
29 | + | |
30 | + <plan filter='First infrared filter' duration='150' nb_images='10'/> | |
31 | + | |
32 | + </album> | |
33 | + | |
34 | + </sequence> | |
35 | + | |
36 | +</request> | ... | ... |
src/alert_manager/tasks.py
... | ... | @@ -155,7 +155,7 @@ class alert_listener(Task): |
155 | 155 | |
156 | 156 | sequences = [sequence.strip('\n') for sequence in sequences] |
157 | 157 | request_builder = RequestBuilder() |
158 | - request_builder.start_new_request(PyrosUser.objects.get(), ScientificProgram.objects.get(), True, name="Simulation_request") | |
158 | + request_builder.start_new_request(PyrosUser.objects.all()[0], ScientificProgram.objects.all()[0], True, name="Simulation_request") | |
159 | 159 | for sequence in sequences: |
160 | 160 | sequence_array = sequence.split(" ") |
161 | 161 | id_seq = sequence_array[0] | ... | ... |
src/alert_manager/tests.py
... | ... | @@ -15,7 +15,50 @@ TEST_FILE_PATH = os.path.join(alert_manager.tasks.VOEVENTS_PATH, TEST_FILE) |
15 | 15 | VOEVENTS_TO_SEND_PATH = "alert_manager/events_to_send" |
16 | 16 | |
17 | 17 | |
18 | -class AlertListenerTests(TestCase): | |
18 | +class TestStrategyChange(TestCase): | |
19 | + | |
20 | + fixtures = ['alert_mgr_test.json'] | |
21 | + | |
22 | + def setUp(self): | |
23 | + ''' | |
24 | + Creates the base for the tests | |
25 | + ''' | |
26 | + | |
27 | + self.alert = Alert.objects.get() | |
28 | + self.strat1 = Alert.objects.get().strategyobs | |
29 | + self.strat2 = StrategyObs.objects.exclude(id=self.strat1.id)[0] | |
30 | + self.alert.strategyobs = self.strat1 | |
31 | + self.alert.save() | |
32 | + | |
33 | + def test_change_inexistant_strat(self): | |
34 | + self.client.login(username="test@test.test", password="test") | |
35 | + path = "/alert_manager/change_obs_strategy_validate/" + str(self.alert.id) | |
36 | + response = self.client.post(path, {"strategy_choice": 42}) | |
37 | + self.assertTrue("error" in response.context.keys(), "There should be an error of non existant strategy") | |
38 | + | |
39 | + def test_change_inexistant_alert(self): | |
40 | + self.client.login(username="test@test.test", password="test") | |
41 | + path = "/alert_manager/change_obs_strategy_validate/" + str(self.alert.id + 1) | |
42 | + response = self.client.post(path, {"strategy_choice": self.strat2.id}) | |
43 | + self.assertTrue("error" in response.context.keys(), "There should be an error of non existant alert") | |
44 | + | |
45 | + def test_change_same_strat(self): | |
46 | + self.client.login(username="test@test.test", password="test") | |
47 | + path = "/alert_manager/change_obs_strategy_validate/" + str(self.alert.id) | |
48 | + response = self.client.post(path, {"strategy_choice": self.strat1.id}) | |
49 | + self.assertTrue("error" in response.context.keys(), "There should be an error of changing to same strategy") | |
50 | + | |
51 | + def test_change_all_working(self): | |
52 | + self.client.login(username="test@test.test", password="test") | |
53 | + path = "/alert_manager/change_obs_strategy_validate/" + str(self.alert.id) | |
54 | + response = self.client.post(path, {"strategy_choice": self.strat2.id}) | |
55 | + self.assertFalse("error" in response.context.keys(), "There shouldn't be an error") | |
56 | + self.assertEqual(Alert.objects.count(), 2, "There should be 2 alerts after the strategy change") | |
57 | + new_alert = Alert.objects.exclude(id=self.alert.id)[0] | |
58 | + self.assertEqual(new_alert.strategyobs.id, self.strat2.id, "The new alert should have the 'strat2' strategy") | |
59 | + | |
60 | + | |
61 | +class AlertListenerTestsCelery(TestCase): | |
19 | 62 | |
20 | 63 | def setup(self): |
21 | 64 | pass | ... | ... |
src/alert_manager/views.py
... | ... | @@ -58,9 +58,18 @@ def change_obs_strategy_validate(request, alert_id): |
58 | 58 | ''' |
59 | 59 | Creates a new request with the strategy given for the selected alert |
60 | 60 | ''' |
61 | - alert = Alert.objects.get(id=alert_id) | |
61 | + | |
62 | + try: | |
63 | + alert = Alert.objects.get(id=alert_id) | |
64 | + except Exception: | |
65 | + alerts = Alert.objects.all() | |
66 | + error = True | |
67 | + message = "This alert doesn't exist" | |
68 | + return render(request, "alert_manager/alerts.html", locals()) | |
69 | + | |
62 | 70 | strategies = StrategyObs.objects.exclude(id=alert.strategyobs.id) |
63 | 71 | if request.method == "POST": |
72 | + | |
64 | 73 | strategy_id = request.POST["strategy_choice"] |
65 | 74 | try: |
66 | 75 | strategy = StrategyObs.objects.get(id=strategy_id) |
... | ... | @@ -69,16 +78,7 @@ def change_obs_strategy_validate(request, alert_id): |
69 | 78 | message = "This strategy doesn't exist" |
70 | 79 | return render(request, "alert_manager/strategy_change.html", locals()) |
71 | 80 | |
72 | - try: | |
73 | - alert = Alert.objects.get(id=alert_id) | |
74 | - except Exception: | |
75 | - error = True | |
76 | - message = "This alert doesn't exist" | |
77 | - return render(request, "alert_manager/strategy_change.html", locals()) | |
78 | - | |
79 | - print(alert.strategyobs.id, strategy_id) | |
80 | - | |
81 | - if alert.strategyobs.id == strategy_id: | |
81 | + if str(alert.strategyobs.id) == strategy_id: | |
82 | 82 | error = True |
83 | 83 | message = "This is already the current strategy for this alert" |
84 | 84 | return render(request, "alert_manager/strategy_change.html", locals()) |
... | ... | @@ -97,4 +97,5 @@ def change_obs_strategy_validate(request, alert_id): |
97 | 97 | |
98 | 98 | success = True |
99 | 99 | message = "Strategy successfully changed. A new request was created." |
100 | + | |
100 | 101 | return render(request, "alert_manager/strategy_change.html", locals()) | ... | ... |
src/common/RequestBuilder.py
... | ... | @@ -41,12 +41,8 @@ class RequestBuilder(): |
41 | 41 | This function MUST be called to build a request. |
42 | 42 | It erases the previous one, and creates the sequences', albums' and plans' dictionaries. |
43 | 43 | ''' |
44 | - if settings.SIMULATION == False: | |
45 | - self.request = Request(name=name, | |
46 | - scientific_program=scientific_program, pyros_user=pyros_user, is_alert=is_alert, complete=True, submitted=True) | |
47 | - else: | |
48 | - self.request = Request(name=name, scientific_program=ScientificProgram.objects.get( | |
49 | - ), pyros_user=PyrosUser.objects.get(), is_alert=True, complete=True, submitted=True) | |
44 | + self.request = Request(name=name, | |
45 | + scientific_program=scientific_program, pyros_user=pyros_user, is_alert=is_alert, complete=True, submitted=True) | |
50 | 46 | self.sequence_id = 1 |
51 | 47 | self.album_id = 1 |
52 | 48 | self.plan_id = 1 | ... | ... |
... | ... | @@ -0,0 +1,342 @@ |
1 | +[ | |
2 | +{ | |
3 | + "model": "pyrosapp.country", | |
4 | + "pk": 1, | |
5 | + "fields": { | |
6 | + "name": "France", | |
7 | + "desc": "", | |
8 | + "quota": null | |
9 | + } | |
10 | +}, | |
11 | +{ | |
12 | + "model": "pyrosapp.detector", | |
13 | + "pk": 1, | |
14 | + "fields": { | |
15 | + "device": 1, | |
16 | + "telescope": 1, | |
17 | + "status": "", | |
18 | + "nb_photo_x": null, | |
19 | + "nb_photo_y": null, | |
20 | + "photo_size_x": null, | |
21 | + "photo_size_y": null, | |
22 | + "has_shutter": false, | |
23 | + "equivalent_foc_len": "", | |
24 | + "acq_start": null, | |
25 | + "acq_stop": null, | |
26 | + "check_temp": null, | |
27 | + "gain": null, | |
28 | + "readout_noise": null, | |
29 | + "readout_time": null, | |
30 | + "idcam_readout_mode": null | |
31 | + } | |
32 | +}, | |
33 | +{ | |
34 | + "model": "pyrosapp.detector", | |
35 | + "pk": 2, | |
36 | + "fields": { | |
37 | + "device": 7, | |
38 | + "telescope": 1, | |
39 | + "status": "", | |
40 | + "nb_photo_x": null, | |
41 | + "nb_photo_y": null, | |
42 | + "photo_size_x": null, | |
43 | + "photo_size_y": null, | |
44 | + "has_shutter": false, | |
45 | + "equivalent_foc_len": "", | |
46 | + "acq_start": null, | |
47 | + "acq_stop": null, | |
48 | + "check_temp": null, | |
49 | + "gain": null, | |
50 | + "readout_noise": null, | |
51 | + "readout_time": null, | |
52 | + "idcam_readout_mode": null | |
53 | + } | |
54 | +}, | |
55 | +{ | |
56 | + "model": "pyrosapp.device", | |
57 | + "pk": 1, | |
58 | + "fields": { | |
59 | + "name": "Cagire", | |
60 | + "desc": "", | |
61 | + "created": "2016-05-13T11:49:49.663Z", | |
62 | + "updated": "2016-05-13T11:49:49.664Z", | |
63 | + "is_online": false, | |
64 | + "status": "", | |
65 | + "maintenance_date": null | |
66 | + } | |
67 | +}, | |
68 | +{ | |
69 | + "model": "pyrosapp.device", | |
70 | + "pk": 2, | |
71 | + "fields": { | |
72 | + "name": "First infrared filter", | |
73 | + "desc": "", | |
74 | + "created": "2016-05-13T11:49:56.579Z", | |
75 | + "updated": "2016-05-13T11:49:56.579Z", | |
76 | + "is_online": false, | |
77 | + "status": "", | |
78 | + "maintenance_date": null | |
79 | + } | |
80 | +}, | |
81 | +{ | |
82 | + "model": "pyrosapp.device", | |
83 | + "pk": 3, | |
84 | + "fields": { | |
85 | + "name": "First visible filter", | |
86 | + "desc": "", | |
87 | + "created": "2016-05-13T11:50:02.012Z", | |
88 | + "updated": "2016-05-13T11:50:02.013Z", | |
89 | + "is_online": false, | |
90 | + "status": "", | |
91 | + "maintenance_date": null | |
92 | + } | |
93 | +}, | |
94 | +{ | |
95 | + "model": "pyrosapp.device", | |
96 | + "pk": 4, | |
97 | + "fields": { | |
98 | + "name": "Second infrared filter", | |
99 | + "desc": "", | |
100 | + "created": "2016-05-13T11:50:07.592Z", | |
101 | + "updated": "2016-05-13T11:50:07.592Z", | |
102 | + "is_online": false, | |
103 | + "status": "", | |
104 | + "maintenance_date": null | |
105 | + } | |
106 | +}, | |
107 | +{ | |
108 | + "model": "pyrosapp.device", | |
109 | + "pk": 5, | |
110 | + "fields": { | |
111 | + "name": "Second visible filter", | |
112 | + "desc": "", | |
113 | + "created": "2016-05-13T11:50:11.226Z", | |
114 | + "updated": "2016-05-13T11:50:11.226Z", | |
115 | + "is_online": false, | |
116 | + "status": "", | |
117 | + "maintenance_date": null | |
118 | + } | |
119 | +}, | |
120 | +{ | |
121 | + "model": "pyrosapp.device", | |
122 | + "pk": 6, | |
123 | + "fields": { | |
124 | + "name": "Telescope", | |
125 | + "desc": "", | |
126 | + "created": "2016-05-13T11:50:14.326Z", | |
127 | + "updated": "2016-05-13T11:50:14.326Z", | |
128 | + "is_online": false, | |
129 | + "status": "", | |
130 | + "maintenance_date": null | |
131 | + } | |
132 | +}, | |
133 | +{ | |
134 | + "model": "pyrosapp.device", | |
135 | + "pk": 7, | |
136 | + "fields": { | |
137 | + "name": "Visible camera", | |
138 | + "desc": "", | |
139 | + "created": "2016-05-13T11:50:17.644Z", | |
140 | + "updated": "2016-05-13T11:50:17.644Z", | |
141 | + "is_online": false, | |
142 | + "status": "", | |
143 | + "maintenance_date": null | |
144 | + } | |
145 | +}, | |
146 | +{ | |
147 | + "model": "pyrosapp.filter", | |
148 | + "pk": 1, | |
149 | + "fields": { | |
150 | + "device": 2, | |
151 | + "detector": 1, | |
152 | + "category": "", | |
153 | + "transmission_curve_doc": "" | |
154 | + } | |
155 | +}, | |
156 | +{ | |
157 | + "model": "pyrosapp.filter", | |
158 | + "pk": 2, | |
159 | + "fields": { | |
160 | + "device": 4, | |
161 | + "detector": 1, | |
162 | + "category": "", | |
163 | + "transmission_curve_doc": "" | |
164 | + } | |
165 | +}, | |
166 | +{ | |
167 | + "model": "pyrosapp.filter", | |
168 | + "pk": 3, | |
169 | + "fields": { | |
170 | + "device": 3, | |
171 | + "detector": 2, | |
172 | + "category": "", | |
173 | + "transmission_curve_doc": "" | |
174 | + } | |
175 | +}, | |
176 | +{ | |
177 | + "model": "pyrosapp.filter", | |
178 | + "pk": 4, | |
179 | + "fields": { | |
180 | + "device": 5, | |
181 | + "detector": 2, | |
182 | + "category": "", | |
183 | + "transmission_curve_doc": "" | |
184 | + } | |
185 | +}, | |
186 | +{ | |
187 | + "model": "pyrosapp.scientificprogram", | |
188 | + "pk": 1, | |
189 | + "fields": { | |
190 | + "name": "GRB", | |
191 | + "desc": "", | |
192 | + "quota": 9999.0, | |
193 | + "priority": 0, | |
194 | + "pyros_users": [ | |
195 | + 1 | |
196 | + ] | |
197 | + } | |
198 | +}, | |
199 | +{ | |
200 | + "model": "pyrosapp.strategyobs", | |
201 | + "pk": 1, | |
202 | + "fields": { | |
203 | + "name": "strat1", | |
204 | + "desc": "", | |
205 | + "xml_file": "strat1.xml" | |
206 | + } | |
207 | +}, | |
208 | +{ | |
209 | + "model": "pyrosapp.strategyobs", | |
210 | + "pk": 2, | |
211 | + "fields": { | |
212 | + "name": "strat2", | |
213 | + "desc": "", | |
214 | + "xml_file": "strat2.xml" | |
215 | + } | |
216 | +}, | |
217 | +{ | |
218 | + "model": "pyrosapp.telescope", | |
219 | + "pk": 1, | |
220 | + "fields": { | |
221 | + "device": 6, | |
222 | + "mount_type": "", | |
223 | + "diameter": null, | |
224 | + "status": "", | |
225 | + "latitude": null, | |
226 | + "longitude": null, | |
227 | + "sens": "", | |
228 | + "altitude": null, | |
229 | + "readout_time": null, | |
230 | + "slew_time": null, | |
231 | + "slew_dead": null, | |
232 | + "slew_rate_max": null, | |
233 | + "horizon_type": "", | |
234 | + "horizon_def": null, | |
235 | + "lim_dec_max": null, | |
236 | + "lim_dec_min": null, | |
237 | + "lim_ha_rise": null, | |
238 | + "lim_ha_set": null, | |
239 | + "address": "", | |
240 | + "night_elev_sun": null, | |
241 | + "mpc_code": "" | |
242 | + } | |
243 | +}, | |
244 | +{ | |
245 | + "model": "pyrosapp.userlevel", | |
246 | + "pk": 1, | |
247 | + "fields": { | |
248 | + "name": "Developer", | |
249 | + "desc": "", | |
250 | + "priority": 0, | |
251 | + "quota": 9999.0 | |
252 | + } | |
253 | +}, | |
254 | +{ | |
255 | + "model": "auth.user", | |
256 | + "pk": 8, | |
257 | + "fields": { | |
258 | + "password": "pbkdf2_sha256$24000$bKJO902RCk0w$zxUz9uiSYG85ymuvl5rNLLqT/LZwrLwpVj5WfwwSyKE=", | |
259 | + "last_login": "2016-06-21T13:07:34.383Z", | |
260 | + "is_superuser": false, | |
261 | + "username": "test@test.test", | |
262 | + "first_name": "test", | |
263 | + "last_name": "test", | |
264 | + "email": "test@test.test", | |
265 | + "is_staff": false, | |
266 | + "is_active": true, | |
267 | + "date_joined": "2016-06-21T13:07:19.609Z", | |
268 | + "groups": [], | |
269 | + "user_permissions": [] | |
270 | + } | |
271 | +}, | |
272 | +{ | |
273 | + "model": "pyrosapp.pyrosuser", | |
274 | + "pk": 3, | |
275 | + "fields": { | |
276 | + "user": 8, | |
277 | + "country": 1, | |
278 | + "user_level": 1, | |
279 | + "desc": null, | |
280 | + "created": "2016-06-21T13:07:19.911Z", | |
281 | + "updated": "2016-06-21T13:07:19.911Z", | |
282 | + "tel": "test", | |
283 | + "address": "test", | |
284 | + "laboratory": "test", | |
285 | + "last_connect": null, | |
286 | + "cur_connect": null, | |
287 | + "putvalid_beg": null, | |
288 | + "putvalid_end": null, | |
289 | + "acqvalid_beg": null, | |
290 | + "acqvalid_end": null, | |
291 | + "quota": null, | |
292 | + "quota_rea": null, | |
293 | + "u_priority": null, | |
294 | + "p_priority": null, | |
295 | + "dir_level": null, | |
296 | + "can_del_void_req": false | |
297 | + } | |
298 | +},{ | |
299 | + "model": "pyrosapp.alert", | |
300 | + "pk": 8, | |
301 | + "fields": { | |
302 | + "request": 65, | |
303 | + "strategyobs": 1, | |
304 | + "voevent_xml": null, | |
305 | + "type": null, | |
306 | + "client": null, | |
307 | + "burst_jd": null, | |
308 | + "burst_ra": null, | |
309 | + "burst_dec": null, | |
310 | + "equinox": null, | |
311 | + "jd_pkt": null, | |
312 | + "jd_send": null, | |
313 | + "jd_received": null, | |
314 | + "trigger_instrum": null, | |
315 | + "trigger_num": null, | |
316 | + "grb_error": null, | |
317 | + "def_not_grb": false, | |
318 | + "editor": null, | |
319 | + "flag": null, | |
320 | + "idgcn_notice": null | |
321 | + } | |
322 | +},{ | |
323 | + "model": "pyrosapp.request", | |
324 | + "pk": 65, | |
325 | + "fields": { | |
326 | + "pyros_user": 3, | |
327 | + "scientific_program": 1, | |
328 | + "name": "Simulation_request", | |
329 | + "desc": null, | |
330 | + "created": "2016-06-21T12:51:24.293Z", | |
331 | + "updated": "2016-06-21T12:51:24.293Z", | |
332 | + "is_alert": true, | |
333 | + "target_type": null, | |
334 | + "status": null, | |
335 | + "autodeposit": false, | |
336 | + "checkpoint": null, | |
337 | + "flag": null, | |
338 | + "complete": true, | |
339 | + "submitted": true | |
340 | + } | |
341 | +} | |
342 | +] | ... | ... |
... | ... | @@ -0,0 +1,380 @@ |
1 | +[ | |
2 | +{ | |
3 | + "model": "pyrosapp.country", | |
4 | + "pk": 1, | |
5 | + "fields": { | |
6 | + "name": "France", | |
7 | + "desc": "", | |
8 | + "quota": null | |
9 | + } | |
10 | +}, | |
11 | +{ | |
12 | + "model": "pyrosapp.detector", | |
13 | + "pk": 1, | |
14 | + "fields": { | |
15 | + "device": 1, | |
16 | + "telescope": 1, | |
17 | + "status": "", | |
18 | + "nb_photo_x": null, | |
19 | + "nb_photo_y": null, | |
20 | + "photo_size_x": null, | |
21 | + "photo_size_y": null, | |
22 | + "has_shutter": false, | |
23 | + "equivalent_foc_len": "", | |
24 | + "acq_start": null, | |
25 | + "acq_stop": null, | |
26 | + "check_temp": null, | |
27 | + "gain": null, | |
28 | + "readout_noise": null, | |
29 | + "readout_time": null, | |
30 | + "idcam_readout_mode": null | |
31 | + } | |
32 | +}, | |
33 | +{ | |
34 | + "model": "pyrosapp.detector", | |
35 | + "pk": 2, | |
36 | + "fields": { | |
37 | + "device": 7, | |
38 | + "telescope": 1, | |
39 | + "status": "", | |
40 | + "nb_photo_x": null, | |
41 | + "nb_photo_y": null, | |
42 | + "photo_size_x": null, | |
43 | + "photo_size_y": null, | |
44 | + "has_shutter": false, | |
45 | + "equivalent_foc_len": "", | |
46 | + "acq_start": null, | |
47 | + "acq_stop": null, | |
48 | + "check_temp": null, | |
49 | + "gain": null, | |
50 | + "readout_noise": null, | |
51 | + "readout_time": null, | |
52 | + "idcam_readout_mode": null | |
53 | + } | |
54 | +}, | |
55 | +{ | |
56 | + "model": "pyrosapp.device", | |
57 | + "pk": 1, | |
58 | + "fields": { | |
59 | + "name": "Cagire", | |
60 | + "desc": "", | |
61 | + "created": "2016-05-13T11:49:49.663Z", | |
62 | + "updated": "2016-05-13T11:49:49.664Z", | |
63 | + "is_online": false, | |
64 | + "status": "", | |
65 | + "maintenance_date": null | |
66 | + } | |
67 | +}, | |
68 | +{ | |
69 | + "model": "pyrosapp.device", | |
70 | + "pk": 2, | |
71 | + "fields": { | |
72 | + "name": "First infrared filter", | |
73 | + "desc": "", | |
74 | + "created": "2016-05-13T11:49:56.579Z", | |
75 | + "updated": "2016-05-13T11:49:56.579Z", | |
76 | + "is_online": false, | |
77 | + "status": "", | |
78 | + "maintenance_date": null | |
79 | + } | |
80 | +}, | |
81 | +{ | |
82 | + "model": "pyrosapp.device", | |
83 | + "pk": 3, | |
84 | + "fields": { | |
85 | + "name": "First visible filter", | |
86 | + "desc": "", | |
87 | + "created": "2016-05-13T11:50:02.012Z", | |
88 | + "updated": "2016-05-13T11:50:02.013Z", | |
89 | + "is_online": false, | |
90 | + "status": "", | |
91 | + "maintenance_date": null | |
92 | + } | |
93 | +}, | |
94 | +{ | |
95 | + "model": "pyrosapp.device", | |
96 | + "pk": 4, | |
97 | + "fields": { | |
98 | + "name": "Second infrared filter", | |
99 | + "desc": "", | |
100 | + "created": "2016-05-13T11:50:07.592Z", | |
101 | + "updated": "2016-05-13T11:50:07.592Z", | |
102 | + "is_online": false, | |
103 | + "status": "", | |
104 | + "maintenance_date": null | |
105 | + } | |
106 | +}, | |
107 | +{ | |
108 | + "model": "pyrosapp.device", | |
109 | + "pk": 5, | |
110 | + "fields": { | |
111 | + "name": "Second visible filter", | |
112 | + "desc": "", | |
113 | + "created": "2016-05-13T11:50:11.226Z", | |
114 | + "updated": "2016-05-13T11:50:11.226Z", | |
115 | + "is_online": false, | |
116 | + "status": "", | |
117 | + "maintenance_date": null | |
118 | + } | |
119 | +}, | |
120 | +{ | |
121 | + "model": "pyrosapp.device", | |
122 | + "pk": 6, | |
123 | + "fields": { | |
124 | + "name": "Telescope", | |
125 | + "desc": "", | |
126 | + "created": "2016-05-13T11:50:14.326Z", | |
127 | + "updated": "2016-05-13T11:50:14.326Z", | |
128 | + "is_online": false, | |
129 | + "status": "", | |
130 | + "maintenance_date": null | |
131 | + } | |
132 | +}, | |
133 | +{ | |
134 | + "model": "pyrosapp.device", | |
135 | + "pk": 7, | |
136 | + "fields": { | |
137 | + "name": "Visible camera", | |
138 | + "desc": "", | |
139 | + "created": "2016-05-13T11:50:17.644Z", | |
140 | + "updated": "2016-05-13T11:50:17.644Z", | |
141 | + "is_online": false, | |
142 | + "status": "", | |
143 | + "maintenance_date": null | |
144 | + } | |
145 | +}, | |
146 | +{ | |
147 | + "model": "pyrosapp.filter", | |
148 | + "pk": 1, | |
149 | + "fields": { | |
150 | + "device": 2, | |
151 | + "detector": 1, | |
152 | + "category": "", | |
153 | + "transmission_curve_doc": "" | |
154 | + } | |
155 | +}, | |
156 | +{ | |
157 | + "model": "pyrosapp.filter", | |
158 | + "pk": 2, | |
159 | + "fields": { | |
160 | + "device": 4, | |
161 | + "detector": 1, | |
162 | + "category": "", | |
163 | + "transmission_curve_doc": "" | |
164 | + } | |
165 | +}, | |
166 | +{ | |
167 | + "model": "pyrosapp.filter", | |
168 | + "pk": 3, | |
169 | + "fields": { | |
170 | + "device": 3, | |
171 | + "detector": 2, | |
172 | + "category": "", | |
173 | + "transmission_curve_doc": "" | |
174 | + } | |
175 | +}, | |
176 | +{ | |
177 | + "model": "pyrosapp.filter", | |
178 | + "pk": 4, | |
179 | + "fields": { | |
180 | + "device": 5, | |
181 | + "detector": 2, | |
182 | + "category": "", | |
183 | + "transmission_curve_doc": "" | |
184 | + } | |
185 | +}, | |
186 | +{ | |
187 | + "model": "pyrosapp.scientificprogram", | |
188 | + "pk": 1, | |
189 | + "fields": { | |
190 | + "name": "GRB", | |
191 | + "desc": "", | |
192 | + "quota": 9999.0, | |
193 | + "priority": 0, | |
194 | + "pyros_users": [ | |
195 | + 1 | |
196 | + ] | |
197 | + } | |
198 | +}, | |
199 | +{ | |
200 | + "model": "pyrosapp.strategyobs", | |
201 | + "pk": 1, | |
202 | + "fields": { | |
203 | + "name": "strat1", | |
204 | + "desc": "", | |
205 | + "xml_file": "strat1.xml" | |
206 | + } | |
207 | +}, | |
208 | +{ | |
209 | + "model": "pyrosapp.strategyobs", | |
210 | + "pk": 2, | |
211 | + "fields": { | |
212 | + "name": "strat2", | |
213 | + "desc": "", | |
214 | + "xml_file": "strat2.xml" | |
215 | + } | |
216 | +}, | |
217 | +{ | |
218 | + "model": "pyrosapp.telescope", | |
219 | + "pk": 1, | |
220 | + "fields": { | |
221 | + "device": 6, | |
222 | + "mount_type": "", | |
223 | + "diameter": null, | |
224 | + "status": "", | |
225 | + "latitude": null, | |
226 | + "longitude": null, | |
227 | + "sens": "", | |
228 | + "altitude": null, | |
229 | + "readout_time": null, | |
230 | + "slew_time": null, | |
231 | + "slew_dead": null, | |
232 | + "slew_rate_max": null, | |
233 | + "horizon_type": "", | |
234 | + "horizon_def": null, | |
235 | + "lim_dec_max": null, | |
236 | + "lim_dec_min": null, | |
237 | + "lim_ha_rise": null, | |
238 | + "lim_ha_set": null, | |
239 | + "address": "", | |
240 | + "night_elev_sun": null, | |
241 | + "mpc_code": "" | |
242 | + } | |
243 | +}, | |
244 | +{ | |
245 | + "model": "pyrosapp.userlevel", | |
246 | + "pk": 1, | |
247 | + "fields": { | |
248 | + "name": "Developer", | |
249 | + "desc": "", | |
250 | + "priority": 0, | |
251 | + "quota": 9999.0 | |
252 | + } | |
253 | +}, | |
254 | +{ | |
255 | + "model": "auth.user", | |
256 | + "pk": 8, | |
257 | + "fields": { | |
258 | + "password": "pbkdf2_sha256$24000$bKJO902RCk0w$zxUz9uiSYG85ymuvl5rNLLqT/LZwrLwpVj5WfwwSyKE=", | |
259 | + "last_login": "2016-06-21T13:07:34.383Z", | |
260 | + "is_superuser": false, | |
261 | + "username": "test@test.test", | |
262 | + "first_name": "test", | |
263 | + "last_name": "test", | |
264 | + "email": "test@test.test", | |
265 | + "is_staff": false, | |
266 | + "is_active": true, | |
267 | + "date_joined": "2016-06-21T13:07:19.609Z", | |
268 | + "groups": [], | |
269 | + "user_permissions": [] | |
270 | + } | |
271 | +}, | |
272 | +{ | |
273 | + "model": "pyrosapp.pyrosuser", | |
274 | + "pk": 3, | |
275 | + "fields": { | |
276 | + "user": 8, | |
277 | + "country": 1, | |
278 | + "user_level": 1, | |
279 | + "desc": null, | |
280 | + "created": "2016-06-21T13:07:19.911Z", | |
281 | + "updated": "2016-06-21T13:07:19.911Z", | |
282 | + "tel": "test", | |
283 | + "address": "test", | |
284 | + "laboratory": "test", | |
285 | + "last_connect": null, | |
286 | + "cur_connect": null, | |
287 | + "putvalid_beg": null, | |
288 | + "putvalid_end": null, | |
289 | + "acqvalid_beg": null, | |
290 | + "acqvalid_end": null, | |
291 | + "quota": null, | |
292 | + "quota_rea": null, | |
293 | + "u_priority": null, | |
294 | + "p_priority": null, | |
295 | + "dir_level": null, | |
296 | + "can_del_void_req": false | |
297 | + } | |
298 | +},{ | |
299 | + "model": "pyrosapp.request", | |
300 | + "pk": 66, | |
301 | + "fields": { | |
302 | + "pyros_user": 3, | |
303 | + "scientific_program": 1, | |
304 | + "name": "Simulation_request_strat2", | |
305 | + "desc": null, | |
306 | + "created": "2016-06-21T13:42:04.493Z", | |
307 | + "updated": "2016-06-22T12:34:09.401Z", | |
308 | + "is_alert": true, | |
309 | + "target_type": "dqsd", | |
310 | + "status": null, | |
311 | + "autodeposit": false, | |
312 | + "checkpoint": null, | |
313 | + "flag": null, | |
314 | + "complete": true, | |
315 | + "submitted": false | |
316 | + } | |
317 | +}, | |
318 | +{ | |
319 | + "model": "pyrosapp.sequence", | |
320 | + "pk": 53, | |
321 | + "fields": { | |
322 | + "request": 66, | |
323 | + "name": "Simulation_request_strat2_0", | |
324 | + "desc": null, | |
325 | + "created": "2016-06-21T13:42:04.587Z", | |
326 | + "updated": "2016-06-22T12:32:16.892Z", | |
327 | + "is_alert": false, | |
328 | + "status": "CPL", | |
329 | + "target_coords": "sdfghj", | |
330 | + "with_drift": false, | |
331 | + "priority": 0, | |
332 | + "analysis_method": null, | |
333 | + "moon_min": null, | |
334 | + "alt_min": null, | |
335 | + "type": null, | |
336 | + "img_current": null, | |
337 | + "img_total": null, | |
338 | + "not_obs": false, | |
339 | + "obsolete": false, | |
340 | + "processing": false, | |
341 | + "flag": null, | |
342 | + "jd1": "0E-8", | |
343 | + "jd2": "9000000.00000000", | |
344 | + "t_prefered": "-1.00000000", | |
345 | + "duration": "0.00023148", | |
346 | + "overhead": "0E-8" | |
347 | + } | |
348 | +}, | |
349 | +{ | |
350 | + "model": "pyrosapp.album", | |
351 | + "pk": 55, | |
352 | + "fields": { | |
353 | + "sequence": 53, | |
354 | + "detector": 2, | |
355 | + "name": "Simulation_request_strat2_01", | |
356 | + "desc": null, | |
357 | + "created": "2016-06-21T13:42:04.874Z", | |
358 | + "updated": "2016-06-22T12:32:16.787Z", | |
359 | + "complete": true | |
360 | + } | |
361 | +}, | |
362 | +{ | |
363 | + "model": "pyrosapp.plan", | |
364 | + "pk": 58, | |
365 | + "fields": { | |
366 | + "album": 55, | |
367 | + "filter": 3, | |
368 | + "name": "Simulation_request_strat2_010", | |
369 | + "desc": null, | |
370 | + "created": "2016-06-21T13:42:05.309Z", | |
371 | + "updated": "2016-06-22T12:32:16.690Z", | |
372 | + "duration": 0.0002314814814814815, | |
373 | + "position": null, | |
374 | + "exposure_time": null, | |
375 | + "nb_images": 1, | |
376 | + "dithering": false, | |
377 | + "complete": true | |
378 | + } | |
379 | +} | |
380 | +] | ... | ... |
src/routine_manager/templates/routine_manager/requests_list.html
src/routine_manager/tests.py
1 | 1 | from django.test import TestCase |
2 | +from pyrosapp.models import * | |
3 | +import os | |
2 | 4 | |
3 | -# Create your tests here. | |
5 | +class TestRoutineManager(TestCase): | |
6 | + | |
7 | + fixtures = ["routine_mgr_test.json"] | |
8 | + | |
9 | + def setUp(self): | |
10 | + pass | |
11 | + | |
12 | + def test_import_fake_file(self): | |
13 | + self.client.login(username="test@test.test", password="test") | |
14 | + path = "/routine_manager/import_request" | |
15 | + response = self.client.post(path, {"request_file": "toto.xml"}, follow=True) | |
16 | + self.assertTrue("error" in response.context.keys(), "There should be an error of non existant file") | |
17 | + self.assertEqual(Request.objects.count(), 1, "There should still be only one request") | |
18 | + | |
19 | + def test_import_invalid_file(self): | |
20 | + self.client.login(username="test@test.test", password="test") | |
21 | + path = "/routine_manager/import_request" | |
22 | + with open("manage.py") as file: | |
23 | + response = self.client.post(path, {"request_file": file}, follow=True) | |
24 | + self.assertTrue("error" in response.context.keys(), "There should be an error of invalid file") | |
25 | + self.assertEqual(Request.objects.count(), 1, "There should still be only one request") | |
26 | + | |
27 | + def test_import(self): | |
28 | + self.client.login(username="test@test.test", password="test") | |
29 | + path = "/routine_manager/import_request" | |
30 | + with open("saved_requests/request_unittest.xml") as file: | |
31 | + response = self.client.post(path, {"request_file": file}, follow=True) | |
32 | + self.assertTrue("success" in response.context.keys(), "There should be a success message") | |
33 | + self.assertEqual(Request.objects.count(), 2, "There should still be two request") | |
34 | + | |
35 | + def test_export_incomplete(self): | |
36 | + req = Request.objects.get() | |
37 | + req.complete = False | |
38 | + req.save() | |
39 | + self.client.login(username="test@test.test", password="test") | |
40 | + path = "/routine_manager/export_request/" + str(req.id) | |
41 | + response = self.client.get(path, follow=True) | |
42 | + self.assertTrue("error" in response.context.keys(), "There should be an error of incomplete request") | |
43 | + | |
44 | + | |
45 | + def test_export(self): | |
46 | + req = Request.objects.get() | |
47 | + self.client.login(username="test@test.test", password="test") | |
48 | + path = "/routine_manager/export_request/" + str(req.id) | |
49 | + response = self.client.get(path, follow=True) | |
50 | + file_path = "saved_requests/request" + str(req.id) + ".xml" | |
51 | + self.assertTrue(os.path.isfile(file_path), "There should be a new file %s" % (file_path,)) | |
52 | + os.remove(file_path) | ... | ... |
src/routine_manager/views.py
... | ... | @@ -451,7 +451,10 @@ def import_request(request): |
451 | 451 | |
452 | 452 | if request.method == "POST": |
453 | 453 | file = request.FILES.get("request_file") |
454 | - if file.size > 1000000: | |
454 | + if file is None: | |
455 | + status = -1 | |
456 | + message = "File does not exist" | |
457 | + elif file.size > 1000000: | |
455 | 458 | status = -1 |
456 | 459 | message = "File is too big (more than 1 000 000 bytes)" |
457 | 460 | else: | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +<?xml version="1.0" ?> | |
2 | +<request name="532871" scientific_program="GRB" target_type="aze"> | |
3 | + <sequence duration="4.99996800" jd1="0E-8" jd2="10.00000000" name="532871_1" target_coords="azer"> | |
4 | + <album detector="Cagire" name="532871_11"> | |
5 | + <plan duration="5.0" filter="First infrared filter" name="532871_111" nb_images="5"/> | |
6 | + </album> | |
7 | + <album detector="Visible camera" name="532871_12"> | |
8 | + <plan duration="1.0" filter="First visible filter" name="532871_1219" nb_images="1"/> | |
9 | + </album> | |
10 | + </sequence> | |
11 | + <sequence duration="86400.00000000" jd1="0E-8" jd2="10.00000000" name="532871_2" target_coords="azerty"> | |
12 | + <album detector="Cagire" name="532871_21"> | |
13 | + <plan duration="86400.0" filter="Second infrared filter" name="532871_211" nb_images="3"/> | |
14 | + </album> | |
15 | + </sequence> | |
16 | +</request> | ... | ... |
... | ... | @@ -0,0 +1,8 @@ |
1 | +<?xml version="1.0" ?> | |
2 | +<request name="Simulation_request_strat2" scientific_program="GRB" target_type="dqsd"> | |
3 | + <sequence duration="19.99987200" jd1="0E-8" jd2="9000000.00000000" name="Simulation_request_strat2_0" target_coords="sdfghj"> | |
4 | + <album detector="Visible camera" name="Simulation_request_strat2_01"> | |
5 | + <plan duration="20.0" filter="First visible filter" name="Simulation_request_strat2_010" nb_images="1"/> | |
6 | + </album> | |
7 | + </sequence> | |
8 | +</request> | ... | ... |
src/user_manager/templates/user_manager/home_user_creation.html
src/user_manager/tests.py
1 | 1 | from django.test import TestCase |
2 | +from pyrosapp.models import * | |
3 | +from django.contrib.auth.models import User | |
2 | 4 | |
3 | -# Create your tests here. | |
5 | +from pprint import pprint | |
6 | + | |
7 | +class UserManagerTests(TestCase): | |
8 | + | |
9 | + def setUp(self): | |
10 | + UserLevel.objects.create() | |
11 | + Country.objects.create() | |
12 | + | |
13 | + def test_creation(self): | |
14 | + path = "/user_manager/creation_validate" | |
15 | + response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
16 | + "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
17 | + "laboratory": "IRAP", "address": "ici"}) | |
18 | + self.assertTrue("success" in response.context.keys(), "There should be a success") | |
19 | + self.assertEqual(User.objects.count(), 1, "There should be one User") | |
20 | + self.assertEqual(PyrosUser.objects.count(), 1, "There should be one PyrosUser") | |
21 | + | |
22 | + def test_login(self): | |
23 | + path = "/user_manager/creation_validate" | |
24 | + response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
25 | + "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
26 | + "laboratory": "IRAP", "address": "ici"}) | |
27 | + | |
28 | + path = "/user_manager/login" | |
29 | + response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze"}) | |
30 | + | |
31 | + """ Note that we use .has_key() because the login phase change the httpresponse context """ | |
32 | + self.assertTrue(response.context.has_key("success"), "There should be a success") | |
33 | + self.assertIn('_auth_user_id', self.client.session, "The user should be logged in") | |
34 | + | |
35 | + def test_wrong_email(self): | |
36 | + path = "/user_manager/creation_validate" | |
37 | + response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
38 | + "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
39 | + "laboratory": "IRAP", "address": "ici"}) | |
40 | + | |
41 | + path = "/user_manager/login" | |
42 | + response = self.client.post(path, {"email": "toto@tti.fr", "password": "aze"}) | |
43 | + self.assertIn("error", response.context.keys(), "There should be an error") | |
44 | + self.assertNotIn('_auth_user_id', self.client.session, "There shouldn't be an authentified user") | |
45 | + | |
46 | + def test_wrong_password(self): | |
47 | + path = "/user_manager/creation_validate" | |
48 | + response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
49 | + "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
50 | + "laboratory": "IRAP", "address": "ici"}) | |
51 | + path = "/user_manager/login" | |
52 | + response = self.client.post(path, {"email": "toto@titi.fr", "password": "azee"}) | |
53 | + self.assertIn("error", response.context.keys(), "There should be an error") | |
54 | + self.assertNotIn('_auth_user_id', self.client.session, "There shouldn't be an authentified user") | |
55 | + | |
56 | + def test_logout(self): | |
57 | + path = "/user_manager/creation_validate" | |
58 | + response = self.client.post(path, {"email": "toto@titi.fr", "password": "aze", "password_confirm": "aze", | |
59 | + "first_name": "toto", "last_name": "titi", "tel": "0123456789", | |
60 | + "laboratory": "IRAP", "address": "ici"}) | |
61 | + self.client.login(username="toto@titi.fr", password="aze") | |
62 | + path = "/user_manager/logout" | |
63 | + self.client.get(path) | |
64 | + self.assertNotIn('_auth_user_id', self.client.session, "There shouldn't be an authentified user") | ... | ... |