def viewSub(request, taskID, subID): """ Allows you to view a partcular submission's code and the problems PyLint has found with the code. """ sameSubType = Upload.objects.filter(userID=request.user, task=taskID) # a list that defines submissions that share a tasKID and userID with the submission in question sameSubTypeMax = sameSubType.count() - 1 def locateLatestSub(request, sub): """ Navigation function that returns the most recent submission for a task based on the user and submission selected """ return sameSubType[sameSubTypeMax] def locateNextSub(request, sub): """ Navigation function that returns the next submission for a task based on the user and submission selected """ for counter in range (0, sameSubTypeMax + 1):# cannot use .len() or .index() on this object if sameSubType[counter].id == sub.id: if counter == sameSubTypeMax: return sameSubType[counter] else: return sameSubType[counter + 1] def locatePreviousSub(request, sub): """ Navigation function that returns the previous submission for a task based on the user and submission selected. The reverse version of locateNextSub, perhaps this can be refactored? """ for counter in range (sameSubTypeMax , -1, -1):# cannot use .len() or .index() on this object if sameSubType[counter].id == sub.id: if counter == 0: return sameSubType[counter] else: return sameSubType[counter - 1] def locateFirstSub(request, sub): """ Navigation function that returns the first submission for a task based on the user and submission selected """ return sameSubType[0] def viewingPermission(request, submission): """ This is a function to prevent users from viewing submissions they did not personally upload. It is to be replaced by a system of permissions based on group. """ if not request.user.is_staff and not request.user == s.userID: #and admin/group check response = HttpResponse() response.status_code = 403 return response s = Upload.objects.get(pk=subID) # Get the submission that was selected. viewingPermission(request,s) codePath = s.fileUpload.path with open(codePath, mode='r') as f: codeString = f.read() codePath = codePath.split('/') del codePath[-1] codePath = '/'.join(codePath) # these steps would be more sensible as path transformations, not string pylintCodePath = codePath + "/pylintOutput.txt" unitTestCodePath = codePath + "/log_file.txt" parsedUnitTest = unitTestParser.parseUnitTestResults(unitTestCodePath) parsedPylint = gameAndGradeParser.readable_output(pylintCodePath).replace('\n', '<br>') return render_to_response('submissions.html', {'currSub': codeString, 'subPylint': parsedPylint, 'subUnitTest': parsedUnitTest,'subs': s, 'nextSub': locateNextSub(request,s), 'previousSub': locatePreviousSub(request,s), 'firstSub': locateFirstSub(request,s), 'latestSub': locateLatestSub(request, s)}, context_instance=RequestContext(request))
def test_pylintSpacePrecedingOperator(self): """This test checks if the parser correctly determines that a docstring is absent""" self.assertRegexpMatches(gameAndGradeParser.readable_output(BADCODEOUT), r'%s Operator not preceded by a space' % (gameAndGradeParser.DIG), "parser should be able to identify the lack of a preceding space before an operator")
def test_pylintDocstring(self): """This test checks if the parser correctly determines that a docstring is absent""" self.assertRegexpMatches(gameAndGradeParser.readable_output(BADCODEOUT), r'%s Missing docstring' % (gameAndGradeParser.DIG), "parser should be able to locate a docstring")
def test_emptyOutput(self): """This test checks if the parsed output for empty code is an empty string""" self.assertNotEqual(gameAndGradeParser.readable_output(EMPTYCODEOUT), "", "parser should have some output")
def test_badOrGood(self): """This test checks if the parser module distinguishes between bad and good code""" self.assertNotEqual(gameAndGradeParser.readable_output(GOODCODEOUT), gameAndGradeParser.readable_output(BADCODEOUT), "parser should distinguish between bad and good code")
def test_emptyOrBad(self): """This test checks if the parser module distinguishes between empty and bad code""" self.assertNotEqual(gameAndGradeParser.readable_output(BADCODEOUT), gameAndGradeParser.readable_output(EMPTYCODEOUT), "parser should distinguish between empty and bad code")