Example #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,
         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="stdoutbasedtestcase", 
          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'
     )
     self.stdout_based_testcase = StdoutBasedTestCase(
         question=self.question2,
         expected_output='Hello World'
     )
     self.assertion_testcase.save()
     self.stdout_based_testcase.save()
     answer_data = {"user_answer": "demo_answer",
         "test_case_data": [
             {"test_case": "assert myfunc(12, 13) == 15"}
         ]
     }
     self.answer_data_json = json.dumps(answer_data)
Example #2
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="stdoutbasedtestcase", 
             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'
        )
        self.stdout_based_testcase = StdoutBasedTestCase(
            question=self.question2,
            expected_output='Hello World'
        )
        self.assertion_testcase.save()
        self.stdout_based_testcase.save()
        answer_data = {"user_answer": "demo_answer",
            "test_case_data": [
                {"test_case": "assert myfunc(12, 13) == 15"}
            ]
        }
        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"
        )
        self.assertEqual(result, self.answer_data_json)