From 5088450ed347e41f0815826d44a4a138f4f44dd2 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Tue, 2 Jul 2013 22:09:51 -0400 Subject: [PATCH] add another unit test to explicitly exercise the can_execute_unsafe_code() method --- .../djangoapps/util/tests/test_sandboxing.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 common/djangoapps/util/tests/test_sandboxing.py diff --git a/common/djangoapps/util/tests/test_sandboxing.py b/common/djangoapps/util/tests/test_sandboxing.py new file mode 100644 index 0000000000..96547cc1eb --- /dev/null +++ b/common/djangoapps/util/tests/test_sandboxing.py @@ -0,0 +1,28 @@ +""" +Tests for sandboxing.py in util app +""" + +from django.test import TestCase +from util.sandboxing import can_execute_unsafe_code +from django.test.utils import override_settings + + +class SandboxingTest(TestCase): + """ + Test sandbox whitelisting + """ + @override_settings(COURSES_WITH_UNSAFE_CODE=['edX/full/.*']) + def test_sandbox_exclusion(self): + """ + Test to make sure that a non-match returns false + """ + self.assertFalse(can_execute_unsafe_code('edX/notful/empty')) + + @override_settings(COURSES_WITH_UNSAFE_CODE=['edX/full/.*']) + def test_sandbox_inclusion(self): + """ + Test to make sure that a match works across course runs + """ + self.assertTrue(can_execute_unsafe_code('edX/full/2012_Fall')) + self.assertTrue(can_execute_unsafe_code('edX/full/2013_Spring')) +