From 97e6372b344f02c541e443afde5ba468506bccd8 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 6 Apr 2018 15:07:26 +0530 Subject: Fix a bug that allows answer to be true if there are no test cases to a code question --- yaksh/tests/test_code_server.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'yaksh/tests/test_code_server.py') diff --git a/yaksh/tests/test_code_server.py b/yaksh/tests/test_code_server.py index 1309624..a647481 100644 --- a/yaksh/tests/test_code_server.py +++ b/yaksh/tests/test_code_server.py @@ -106,6 +106,25 @@ class TestCodeServer(unittest.TestCase): self.assertFalse(data['success']) self.assertTrue('AssertionError' in data['error'][0]['exception']) + def test_question_with_no_testcases(self): + # Given + testdata = { + 'metadata': { + 'user_answer': 'def f(): return 1', + 'language': 'python', + 'partial_grading': False + }, + 'test_case_data': [] + } + + # When + submit(self.url, '0', json.dumps(testdata), '') + result = get_result(self.url, '0', block=True) + + # Then + data = json.loads(result.get('result')) + self.assertFalse(data['success']) + def test_multiple_simultaneous_hits(self): # Given results = Queue() -- cgit From 7f04851ccbb4d8b541a3ed38aa13cff36b6e898c Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 6 Apr 2018 16:52:45 +0530 Subject: Add test cases to check if code passes without testcases --- yaksh/tests/test_code_server.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'yaksh/tests/test_code_server.py') diff --git a/yaksh/tests/test_code_server.py b/yaksh/tests/test_code_server.py index a647481..e2781df 100644 --- a/yaksh/tests/test_code_server.py +++ b/yaksh/tests/test_code_server.py @@ -125,6 +125,21 @@ class TestCodeServer(unittest.TestCase): data = json.loads(result.get('result')) self.assertFalse(data['success']) + # With correct answer and test case + testdata["metadata"]["user_answer"] = 'def f(): return 2' + testdata["test_case_data"] = [{'test_case': 'assert f() == 2', + 'test_case_type': 'standardtestcase', + 'weight': 0.0 + } + ] + # When + submit(self.url, '0', json.dumps(testdata), '') + result = get_result(self.url, '0', block=True) + + # Then + data = json.loads(result.get('result')) + self.assertTrue(data['success']) + def test_multiple_simultaneous_hits(self): # Given results = Queue() -- cgit