@@ 329-364 (lines=36) @@ | ||
326 | self.assertEqual(404, response.code) |
|
327 | ||
328 | ||
329 | class TestEvaluationPlainHandlerEnabled(AsyncHTTPTestCase): |
|
330 | @classmethod |
|
331 | def setUpClass(cls): |
|
332 | prefix = "__TestEvaluationPlainHandlerEnabled_" |
|
333 | ||
334 | # create config file |
|
335 | cls.config_file = tempfile.NamedTemporaryFile( |
|
336 | mode="w+t", prefix=prefix, suffix=".conf", delete=False |
|
337 | ) |
|
338 | cls.config_file.write( |
|
339 | "[TabPy]\n" |
|
340 | f"TABPY_EVALUATE_ENABLE = true" |
|
341 | ) |
|
342 | cls.config_file.close() |
|
343 | ||
344 | cls.script = ( |
|
345 | '{"data":{"_arg1":[2,3],"_arg2":[3,-1]},' |
|
346 | '"script":"res=[]\\nfor i in range(len(_arg1)):\\n ' |
|
347 | 'res.append(_arg1[i] * _arg2[i])\\nreturn res"}' |
|
348 | ) |
|
349 | ||
350 | @classmethod |
|
351 | def tearDownClass(cls): |
|
352 | os.remove(cls.config_file.name) |
|
353 | ||
354 | def get_app(self): |
|
355 | self.app = TabPyApp(self.config_file.name) |
|
356 | return self.app._create_tornado_web_app() |
|
357 | ||
358 | def test_evaluation_enabled(self): |
|
359 | response = self.fetch( |
|
360 | "/evaluate", |
|
361 | method="POST", |
|
362 | body=self.script |
|
363 | ) |
|
364 | self.assertEqual(200, response.code) |
|
365 | ||
366 | ||
367 | class TestEvaluationPlainHandlerDefault(AsyncHTTPTestCase): |
|
@@ 291-326 (lines=36) @@ | ||
288 | self.assertEqual(400, response.code) |
|
289 | ||
290 | ||
291 | class TestEvaluationPlainHandlerDisabled(AsyncHTTPTestCase): |
|
292 | @classmethod |
|
293 | def setUpClass(cls): |
|
294 | prefix = "__TestEvaluationPlainHandlerDisabled_" |
|
295 | ||
296 | # create config file |
|
297 | cls.config_file = tempfile.NamedTemporaryFile( |
|
298 | mode="w+t", prefix=prefix, suffix=".conf", delete=False |
|
299 | ) |
|
300 | cls.config_file.write( |
|
301 | "[TabPy]\n" |
|
302 | f"TABPY_EVALUATE_ENABLE = false" |
|
303 | ) |
|
304 | cls.config_file.close() |
|
305 | ||
306 | cls.script = ( |
|
307 | '{"data":{"_arg1":[2,3],"_arg2":[3,-1]},' |
|
308 | '"script":"res=[]\\nfor i in range(len(_arg1)):\\n ' |
|
309 | 'res.append(_arg1[i] * _arg2[i])\\nreturn res"}' |
|
310 | ) |
|
311 | ||
312 | @classmethod |
|
313 | def tearDownClass(cls): |
|
314 | os.remove(cls.config_file.name) |
|
315 | ||
316 | def get_app(self): |
|
317 | self.app = TabPyApp(self.config_file.name) |
|
318 | return self.app._create_tornado_web_app() |
|
319 | ||
320 | def test_evaluation_disabled_fails(self): |
|
321 | response = self.fetch( |
|
322 | "/evaluate", |
|
323 | method="POST", |
|
324 | body=self.script |
|
325 | ) |
|
326 | self.assertEqual(404, response.code) |
|
327 | ||
328 | ||
329 | class TestEvaluationPlainHandlerEnabled(AsyncHTTPTestCase): |
|
@@ 367-401 (lines=35) @@ | ||
364 | self.assertEqual(200, response.code) |
|
365 | ||
366 | ||
367 | class TestEvaluationPlainHandlerDefault(AsyncHTTPTestCase): |
|
368 | @classmethod |
|
369 | def setUpClass(cls): |
|
370 | prefix = "__TestEvaluationPlainHandlerDefault_" |
|
371 | ||
372 | # create config file |
|
373 | cls.config_file = tempfile.NamedTemporaryFile( |
|
374 | mode="w+t", prefix=prefix, suffix=".conf", delete=False |
|
375 | ) |
|
376 | cls.config_file.write( |
|
377 | "[TabPy]" |
|
378 | ) |
|
379 | cls.config_file.close() |
|
380 | ||
381 | cls.script = ( |
|
382 | '{"data":{"_arg1":[2,3],"_arg2":[3,-1]},' |
|
383 | '"script":"res=[]\\nfor i in range(len(_arg1)):\\n ' |
|
384 | 'res.append(_arg1[i] * _arg2[i])\\nreturn res"}' |
|
385 | ) |
|
386 | ||
387 | @classmethod |
|
388 | def tearDownClass(cls): |
|
389 | os.remove(cls.config_file.name) |
|
390 | ||
391 | def get_app(self): |
|
392 | self.app = TabPyApp(self.config_file.name) |
|
393 | return self.app._create_tornado_web_app() |
|
394 | ||
395 | def test_evaluation_default(self): |
|
396 | response = self.fetch( |
|
397 | "/evaluate", |
|
398 | method="POST", |
|
399 | body=self.script |
|
400 | ) |
|
401 | self.assertEqual(200, response.code) |
|
402 |