Beispiel #1
0
    def test_run_compilationError(self):
        solution = model_mocks.mock_solution()

        code = 'some code'
        tests = [{"input": "", "output": ""}]

        compilation_error = 'ce'

        views.api.run_code = mock.MagicMock(return_value=api.CompilationError(compilation_error))

        request = self.request_post('wolf:run', args=[solution.id], data={'code': code, 'tests': json.dumps(tests)})

        result = json.loads(views.run(request, solution.id).content.decode())

        self.assertDictEqual(result, {
            'compiled': False,
            'compilation_error': compilation_error,
        })
Beispiel #2
0
    def test_run_compilationError(self):
        solution = model_mocks.mock_solution()

        code = 'some code'
        tests = [{"input": "", "output": ""}]

        compilation_error = 'ce'

        views.api.run_code = mock.MagicMock(
            return_value=api.CompilationError(compilation_error))

        request = self.request_post('wolf:run',
                                    args=[solution.id],
                                    data={
                                        'code': code,
                                        'tests': json.dumps(tests)
                                    })

        result = json.loads(views.run(request, solution.id).content.decode())

        self.assertDictEqual(result, {
            'compiled': False,
            'compilation_error': compilation_error,
        })
Beispiel #3
0
    def test_run_updatesSolution(self):
        solution = model_mocks.mock_solution()

        new_code = 'new code'
        new_tests = [{"input": "2 1", "output": "4"}]

        views.api.run_code = mock.MagicMock(return_value=['3'])
        views.compare_result = mock.MagicMock(return_value=False)

        data = {'code': new_code, 'tests': json.dumps(new_tests)}
        request = self.request_post('wolf:run', args=[solution.id], data=data)
        result = json.loads(views.run(request, solution.id).content.decode())

        updated_solution = models.Solution.objects.get(pk=solution.id)
        self.assertEqual(updated_solution.code, new_code)
        self.assertEqual(json.loads(updated_solution.tests), new_tests)

        self.assertEqual(result, {
            'compiled': True,
            'result': [{
                'successful': False,
                'output': '3',
            }],
        })
Beispiel #4
0
    def test_run_updatesSolution(self):
        solution = model_mocks.mock_solution()

        new_code = 'new code'
        new_tests = [{"input": "2 1", "output": "4"}]

        views.api.run_code = mock.MagicMock(return_value=['3'])
        views.compare_result = mock.MagicMock(return_value=False)

        data = {'code': new_code, 'tests': json.dumps(new_tests)}
        request = self.request_post('wolf:run', args=[solution.id], data=data)
        result = json.loads(views.run(request, solution.id).content.decode())

        updated_solution = models.Solution.objects.get(pk=solution.id)
        self.assertEqual(updated_solution.code, new_code)
        self.assertEqual(json.loads(updated_solution.tests), new_tests)

        self.assertEqual(result, {
            'compiled': True,
            'result': [{
                'successful': False,
                'output': '3',
            }],
        })