Esempio n. 1
0
 def setUp(self):
     self.user = User.objects.get(pk=1)
     self.question1 = Question(summary='Demo question 1',
                               language='Python',
                               type='Code',
                               active=True,
                               description='Write a function',
                               points=1.0,
                               user=self.user,
                               snippet='def myfunc()')
     self.question2 = Question(summary='Demo question 2',
                               language='Python',
                               type='Code',
                               active=True,
                               description='Write to standard output',
                               points=1.0,
                               user=self.user,
                               snippet='def myfunc()')
     self.question1.save()
     self.question2.save()
     self.assertion_testcase = StandardTestCase(
         question=self.question1,
         test_case='assert myfunc(12, 13) == 15',
         type='standardtestcase')
     self.stdout_based_testcase = StdIOBasedTestCase(
         question=self.question2,
         expected_output='Hello World',
         type='standardtestcase')
     self.assertion_testcase.save()
     self.stdout_based_testcase.save()
     answer_data = {
         'metadata': {
             'user_answer': 'demo_answer',
             'language': 'python',
             'partial_grading': False
         },
         'test_case_data': [{
             'test_case': 'assert myfunc(12, 13) == 15',
             'test_case_type': 'standardtestcase',
             'test_case_args': "",
             'weight': 1.0
         }]
     }
     self.answer_data_json = json.dumps(answer_data)
Esempio n. 2
0
    def setUp(self):
        self.user = User.objects.get(pk=1)
        self.question1 = Question(summary='Demo question 1',
            language='Python',
            type='Code',
            active=True,
            description='Write a function',
            points=1.0,
            test_case_type="standardtestcase",
            user=self.user,
            snippet='def myfunc()'
        )
        self.question2 = Question(summary='Demo question 2',
             language='Python',
             type='Code',
             active=True,
             description='Write to standard output',
             points=1.0,
             test_case_type="stdiobasedtestcase",
             user=self.user,
             snippet='def myfunc()'
        )
        self.question1.save()
        self.question2.save()
        self.assertion_testcase = StandardTestCase(
            question=self.question1,
            test_case='assert myfunc(12, 13) == 15',
            type='standardtestcase'
        )
        self.stdout_based_testcase = StdIOBasedTestCase(
            question=self.question2,
            expected_output='Hello World',
            type='standardtestcase'

        )
        self.assertion_testcase.save()
        self.stdout_based_testcase.save()
        answer_data = {'metadata': { 'user_answer': 'demo_answer',
                        'language': 'python',
                        'partial_grading': False
                        },
                    'test_case_data': [{'test_case': 'assert myfunc(12, 13) == 15',
                        'test_case_type': 'standardtestcase',
                        'weight': 1.0
                        }]
                    }
        self.answer_data_json = json.dumps(answer_data)
Esempio n. 3
0
class TestCaseTestCases(unittest.TestCase):
    def setUp(self):
        self.user = User.objects.get(pk=1)
        self.question1 = Question(summary='Demo question 1',
            language='Python',
            type='Code',
            active=True,
            description='Write a function',
            points=1.0,
            test_case_type="standardtestcase",
            user=self.user,
            snippet='def myfunc()'
        )
        self.question2 = Question(summary='Demo question 2',
             language='Python',
             type='Code',
             active=True,
             description='Write to standard output',
             points=1.0,
             test_case_type="stdiobasedtestcase",
             user=self.user,
             snippet='def myfunc()'
        )
        self.question1.save()
        self.question2.save()
        self.assertion_testcase = StandardTestCase(
            question=self.question1,
            test_case='assert myfunc(12, 13) == 15',
            type='standardtestcase'
        )
        self.stdout_based_testcase = StdIOBasedTestCase(
            question=self.question2,
            expected_output='Hello World',
            type='standardtestcase'

        )
        self.assertion_testcase.save()
        self.stdout_based_testcase.save()
        answer_data = {'metadata': { 'user_answer': 'demo_answer',
                        'language': 'python',
                        'partial_grading': False
                        },
                    'test_case_data': [{'test_case': 'assert myfunc(12, 13) == 15',
                        'test_case_type': 'standardtestcase',
                        'weight': 1.0
                        }]
                    }
        self.answer_data_json = json.dumps(answer_data)

    def test_assertion_testcase(self):
        """ Test question """
        self.assertEqual(self.assertion_testcase.question, self.question1)
        self.assertEqual(self.assertion_testcase.test_case,
                             'assert myfunc(12, 13) == 15')

    def test_stdout_based_testcase(self):
        """ Test question """
        self.assertEqual(self.stdout_based_testcase.question, self.question2)
        self.assertEqual(self.stdout_based_testcase.expected_output,
            'Hello World'
        )

    def test_consolidate_answer_data(self):
        """ Test consolidate answer data model method """
        result = self.question1.consolidate_answer_data(
            user_answer="demo_answer"
        )
        actual_data = json.loads(result)
        exp_data = json.loads(self.answer_data_json)
        self.assertEqual(actual_data['metadata']['user_answer'], exp_data['metadata']['user_answer'])
        self.assertEqual(actual_data['test_case_data'], exp_data['test_case_data'])
Esempio n. 4
0
class TestCaseTestCases(unittest.TestCase):
    def setUp(self):
        self.user = User.objects.get(pk=1)
        self.question1 = Question(summary='Demo question 1',
                                  language='Python',
                                  type='Code',
                                  active=True,
                                  description='Write a function',
                                  points=1.0,
                                  user=self.user,
                                  snippet='def myfunc()')
        self.question2 = Question(summary='Demo question 2',
                                  language='Python',
                                  type='Code',
                                  active=True,
                                  description='Write to standard output',
                                  points=1.0,
                                  user=self.user,
                                  snippet='def myfunc()')
        self.question1.save()
        self.question2.save()
        self.assertion_testcase = StandardTestCase(
            question=self.question1,
            test_case='assert myfunc(12, 13) == 15',
            type='standardtestcase')
        self.stdout_based_testcase = StdIOBasedTestCase(
            question=self.question2,
            expected_output='Hello World',
            type='standardtestcase')
        self.assertion_testcase.save()
        self.stdout_based_testcase.save()
        answer_data = {
            'metadata': {
                'user_answer': 'demo_answer',
                'language': 'python',
                'partial_grading': False
            },
            'test_case_data': [{
                'test_case': 'assert myfunc(12, 13) == 15',
                'test_case_type': 'standardtestcase',
                'test_case_args': "",
                'weight': 1.0
            }]
        }
        self.answer_data_json = json.dumps(answer_data)

    def test_assertion_testcase(self):
        """ Test question """
        self.assertEqual(self.assertion_testcase.question, self.question1)
        self.assertEqual(self.assertion_testcase.test_case,
                         'assert myfunc(12, 13) == 15')

    def test_stdout_based_testcase(self):
        """ Test question """
        self.assertEqual(self.stdout_based_testcase.question, self.question2)
        self.assertEqual(self.stdout_based_testcase.expected_output,
                         'Hello World')

    def test_consolidate_answer_data(self):
        """ Test consolidate answer data model method """
        result = self.question1.consolidate_answer_data(
            user_answer="demo_answer")
        actual_data = json.loads(result)
        exp_data = json.loads(self.answer_data_json)
        self.assertEqual(actual_data['metadata']['user_answer'],
                         exp_data['metadata']['user_answer'])
        self.assertEqual(actual_data['test_case_data'],
                         exp_data['test_case_data'])