Consolidate the views for Test Management
This commit is contained in:
1 parent
bc5740febf
commit
21f4ae3e25
7 files changed
+57
-177
No files matched your search
+1
-1
@@ -127,4 +127,4 @@ class LogEvent(Model):
|
||||
creation = DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return "{0} {1} {2}".format(self.author, str(self.test), self.data)
|
||||
return "{0} {1} {2}".format(self.author, str(self.test), self.data)
|
||||
+4
-7
@@ -43,14 +43,11 @@ urlpatterns = [
|
||||
django.urls.path(r'eventLog/', OpenBench.views.eventLog),
|
||||
django.urls.path(r'eventLog/<int:page>/', OpenBench.views.eventLog),
|
||||
|
||||
# Links for viewing and managing tests
|
||||
# Links for viewing and managing tests (maintain Legacy)
|
||||
django.urls.path(r'test/<int:id>/', OpenBench.views.test),
|
||||
django.urls.path(r'viewTest/<int:id>/', OpenBench.views.test),
|
||||
django.urls.path(r'test/<int:id>/<str:action>', OpenBench.views.test),
|
||||
django.urls.path(r'newTest/', OpenBench.views.newTest),
|
||||
django.urls.path(r'viewTest/<int:id>/', OpenBench.views.viewTest),
|
||||
django.urls.path(r'editTest/<int:id>/', OpenBench.views.editTest),
|
||||
django.urls.path(r'approveTest/<int:id>/', OpenBench.views.approveTest),
|
||||
django.urls.path(r'restartTest/<int:id>/', OpenBench.views.restartTest),
|
||||
django.urls.path(r'stopTest/<int:id>/', OpenBench.views.stopTest),
|
||||
django.urls.path(r'deleteTest/<int:id>/', OpenBench.views.deleteTest),
|
||||
|
||||
# Links for the Client to update the Server
|
||||
django.urls.path(r'getFiles/', OpenBench.views.getFiles),
|
||||
|
||||
+40
-157
@@ -362,172 +362,55 @@ def newTest(request):
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
|
||||
def viewTest(request, id):
|
||||
def test(request, id, action=None):
|
||||
|
||||
try:
|
||||
# Build context dictionary for test template
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# GET : The User is either trying to view the status of the selected #
|
||||
# test, or adjust the running state of the test in some way. When #
|
||||
# viewing a test, collect the results and return an HTML template #
|
||||
# using that data. Otherwise, look to adjust the running state of #
|
||||
# the test. We throw out any invalid requests. Create a LogEvent #
|
||||
# if the we attempt to modify the test's state in any way #
|
||||
# #
|
||||
# POST : The only valid POST request is for the action MODIFY. Requests #
|
||||
# to modify contain an updated Priority and Throughput parameter #
|
||||
# for the selected test. Bound the updated values, and log the #
|
||||
# modification of the test with the creation of a new LogEvent #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
if not Test.objects.filter(id=id):
|
||||
return django.http.HttpResponseRedirect('/index/')
|
||||
|
||||
if action not in ['APPROVE', 'RESTART', 'STOP', 'DELETE', 'MODIFY']:
|
||||
test = Test.objects.get(id=id)
|
||||
results = Result.objects.all().filter(test=test)
|
||||
results = results.order_by('machine_id')
|
||||
data = {'test' : test, 'results' : results}
|
||||
return render(request, 'viewTest.html', data)
|
||||
results = Result.objects.filter(test=test).order_by('machine_id')
|
||||
return render(request, 'test.html', {'test' : test, 'results': results})
|
||||
|
||||
# Unable to find test
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
user = request.user
|
||||
test = Test.objects.get(id=id)
|
||||
profile = Profile.objects.get(user=user)
|
||||
|
||||
@login_required(login_url='/login/')
|
||||
def editTest(request, id):
|
||||
if not profile.approver and test.author != profile.user.username:
|
||||
return django.http.HttpResponseRedirect('/index/')
|
||||
|
||||
try:
|
||||
# Only let approvers or the test author edit a test
|
||||
test = Test.objects.get(id=id)
|
||||
profile = Profile.objects.get(user=request.user)
|
||||
if not profile.approver and test.author != profile.user.username:
|
||||
raise Exception('Only Admins Or Test Owners Can Edit A Test')
|
||||
if action == 'APPROVE' and test.author == user.username and not user.is_superuser:
|
||||
return django.http.HttpResponseRedirect('/index/')
|
||||
|
||||
# Edit the provided test
|
||||
test = Test.objects.get(id=id)
|
||||
if action == 'APPROVE': test.approved = True; test.save()
|
||||
if action == 'RESTART': test.finished = False; test.save()
|
||||
if action == 'STOP' : test.finished = True; test.save()
|
||||
if action == 'DELETE' : test.deleted = True; test.save()
|
||||
|
||||
if action == 'MODIFY':
|
||||
test.priority = int(request.POST['priority'])
|
||||
test.throughput = max(0, int(request.POST['throughput']))
|
||||
test.throughput = max(1, int(request.POST['throughput']))
|
||||
test.save()
|
||||
|
||||
# Log changes to the test settings
|
||||
LogEvent.objects.create(
|
||||
data='Edited Test P={0} TP={1}'.format(test.priority, test.throughput),
|
||||
author=request.user.username,
|
||||
test=test)
|
||||
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
# Bad test id, permissions, or other
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
|
||||
@login_required(login_url='/login/')
|
||||
def approveTest(request, id):
|
||||
|
||||
try:
|
||||
# Throw out users without approver status
|
||||
profile = Profile.objects.get(user=request.user)
|
||||
if not profile.approver:
|
||||
raise Exception('No Approver Permissions on Account')
|
||||
|
||||
# Ensure cross verification is used, except for the site admin
|
||||
test = Test.objects.get(id=id)
|
||||
if test.author == profile.user.username and not profile.user.is_superuser:
|
||||
raise Exception('Cross Approval is Required')
|
||||
|
||||
# Approve the provided test
|
||||
if test.approved:
|
||||
return HttpResponseRedirect('/index/')
|
||||
test.approved = True
|
||||
test.save()
|
||||
|
||||
# Log the test approval
|
||||
LogEvent.objects.create(
|
||||
data='Approved Test',
|
||||
author=request.user.username,
|
||||
test=test)
|
||||
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
# Bad test id, permissions, or other
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
|
||||
@login_required(login_url='/login/')
|
||||
def restartTest(request, id):
|
||||
|
||||
try:
|
||||
# Only let approvers or the author restart a test
|
||||
test = Test.objects.get(id=id)
|
||||
profile = Profile.objects.get(user=request.user)
|
||||
if not profile.approver and test.author != profile.user.username:
|
||||
raise Exception('Only Admins Or Test Owners Can Restart A Test')
|
||||
|
||||
# Restart the provided test
|
||||
test = Test.objects.get(id=id)
|
||||
if not test.finished:
|
||||
return HttpResponseRedirect('/index/')
|
||||
test.finished = False
|
||||
test.save()
|
||||
|
||||
# Log the test stopping
|
||||
LogEvent.objects.create(
|
||||
data='Restarted Test',
|
||||
author=request.user.username,
|
||||
test=test)
|
||||
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
# Bad test id, permissions, or other
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
|
||||
@login_required(login_url='/login/')
|
||||
def stopTest(request, id):
|
||||
|
||||
try:
|
||||
# Only let approvers or the author stop a test
|
||||
test = Test.objects.get(id=id)
|
||||
profile = Profile.objects.get(user=request.user)
|
||||
if not profile.approver and test.author != profile.user.username:
|
||||
raise Exception('Only Admins Or Test Owners Can Stop A Test')
|
||||
|
||||
# Stop the provided test
|
||||
test = Test.objects.get(id=id)
|
||||
if test.finished:
|
||||
return HttpResponseRedirect('/index/')
|
||||
test.finished = True
|
||||
test.save()
|
||||
|
||||
# Log the test stopping
|
||||
LogEvent.objects.create(
|
||||
data='Stopped Test',
|
||||
author=request.user.username,
|
||||
test=test)
|
||||
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
# Bad test id, permissions, or other
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
|
||||
@login_required(login_url='/login/')
|
||||
def deleteTest(request, id):
|
||||
|
||||
try:
|
||||
# Only let approvers or the author delete a test
|
||||
test = Test.objects.get(id=id)
|
||||
profile = Profile.objects.get(user=request.user)
|
||||
if not profile.approver and test.author != profile.user.username:
|
||||
raise Exception('Only Admins Or Test Owners Can Delete A Test')
|
||||
|
||||
# Delete the provided test
|
||||
test = Test.objects.get(id=id)
|
||||
if test.deleted:
|
||||
return HttpResponseRedirect('/index/')
|
||||
test.deleted = True
|
||||
test.save()
|
||||
|
||||
# Reduce the test count for the test author
|
||||
user = User.objects.get(username=test.author)
|
||||
profile = Profile.objects.get(user=user)
|
||||
profile.tests -= 1
|
||||
profile.save()
|
||||
|
||||
# Log the test deltion
|
||||
LogEvent.objects.create(
|
||||
data='Deleted Test',
|
||||
author=request.user.username,
|
||||
test=test)
|
||||
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
# Bad test id, permissions, or other
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
action += " P={0} TP={1}".format(test.priority, test.throughput)
|
||||
LogEvent.objects.create(data=action, author=user.username, test=test)
|
||||
return django.http.HttpResponseRedirect('/index/')
|
||||
|
||||
@csrf_exempt
|
||||
@not_minified_response
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<tr>
|
||||
<td><a href="/user/{{test.author}}">{{test.author|slice:":6"}}</a></td>
|
||||
<td>{{test.engine}}</td>
|
||||
<td><a href="/viewTest/{{test.id}}">{{test.dev.name}}</a></td>
|
||||
<td><a href="/test/{{test.id}}">{{test.dev.name}}</a></td>
|
||||
<td class="textcenter"><a href="{{test|gitDiffLink}}">diff</a></td>
|
||||
<td>{{test.timecontrol}}</td>
|
||||
<td class='statblock {{test|testResultColour}}'><strong>{{test|shortStatBlock|linebreaksbr}}</strong></td>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<tr>
|
||||
<td>{{event.creation|date:'Y-m-d H:i:s'}}</td>
|
||||
<td>{{event.author}}</td>
|
||||
<td><a href="/viewTest/{{event.test.id}}">{{event.test.dev.name}}</a></td>
|
||||
<td><a href="/test/{{event.test.id}}">{{event.test.dev.name}}</a></td>
|
||||
<td>{{event.test.timecontrol}}</td>
|
||||
<td>{{event.data}}</td>
|
||||
</tr>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<td>{{machine.owner}}</td>
|
||||
<td>{{machine.osname}}</td>
|
||||
<td>{{machine.updated|date:'Y-m-d H:i'}}</td>
|
||||
<td> <a href="/viewTest/{{machine.workload.id}}">{{machine.workload.dev.name}}</a></td>
|
||||
<td> <a href="/test/{{machine.workload.id}}">{{machine.workload.dev.name}}</a></td>
|
||||
<td class="numeric">{{machine.threads}}</td>
|
||||
<td class="numeric">{{machine.mnps|twoDigitPrecision}}</td>
|
||||
</tr>
|
||||
|
||||
@@ -35,34 +35,34 @@
|
||||
|
||||
<!-- Approve Button: For Admins, or Cross-approvers -->
|
||||
{% if not test.approved and profile.approver and profile.user.username != test.author %}
|
||||
<a class="anchorbutton" id="approvebutton" href="/approveTest/{{test.id}}/">Approve</a>
|
||||
<a class="anchorbutton" id="approvebutton" href="/test/{{test.id}}/APPROVE">Approve</a>
|
||||
{% elif not test.approved and request.user.is_superuser %}
|
||||
<a class="anchorbutton" id="approvebutton" href="/approveTest/{{test.id}}/">Approve</a>
|
||||
<a class="anchorbutton" id="approvebutton" href="/test/{{test.id}}/APPROVE">Approve</a>
|
||||
{% else %}
|
||||
<a class="anchorbutton deadbutton">Approve</a>
|
||||
{% endif %}
|
||||
|
||||
<!-- Restart Button: For Approvers or Test Authors of finished tests -->
|
||||
{% if test.finished and profile.approver %}
|
||||
<a class="anchorbutton" id="stopbutton" href="/restartTest/{{test.id}}/">Restart</a>
|
||||
<a class="anchorbutton" id="stopbutton" href="/test/{{test.id}}/RESTART">Restart</a>
|
||||
{% elif test.finished and profile.user.username == test.author %}
|
||||
<a class="anchorbutton" id="stopbutton" href="/restartTest/{{test.id}}/">Restart</a>
|
||||
<a class="anchorbutton" id="stopbutton" href="/test/{{test.id}}/RESTART">Restart</a>
|
||||
{% elif test.finished %}
|
||||
<a class="anchorbutton deadbutton">Restart</a>
|
||||
{% endif %}
|
||||
|
||||
<!-- Stop Button: For Approvers or Test Authors of active tests -->
|
||||
{% if not test.finished and profile.approver %}
|
||||
<a class="anchorbutton" id="restartbutton" href="/stopTest/{{test.id}}/">Stop</a>
|
||||
<a class="anchorbutton" id="restartbutton" href="/test/{{test.id}}/STOP">Stop</a>
|
||||
{% elif not test.finished and profile.user.username == test.author %}
|
||||
<a class="anchorbutton" id="restartbutton" href="/stopTest/{{test.id}}/">Stop</a>
|
||||
<a class="anchorbutton" id="restartbutton" href="/test/{{test.id}}/STOP">Stop</a>
|
||||
{% elif not test.finished %}
|
||||
<a class="anchorbutton deadbutton">Stop</a>
|
||||
{% endif %}
|
||||
|
||||
<!-- Delete Button: For Approvers or Test Authors -->
|
||||
{% if profile.approver or profile.user.username == test.author %}
|
||||
<a class="anchorbutton" id="deletebutton" href="/deleteTest/{{test.id}}/">Delete</a>
|
||||
<a class="anchorbutton" id="deletebutton" href="/test/{{test.id}}/DELETE">Delete</a>
|
||||
{% else %}
|
||||
<a class="anchorbutton deadbutton">Delete</a>
|
||||
{% endif %}
|
||||
@@ -77,7 +77,7 @@
|
||||
|
||||
|
||||
<!-- Forum to modify the Priority or Throughput -->
|
||||
<form method="POST" action="/editTest/{{test.id}}/">
|
||||
<form method="POST" action="/test/{{test.id}}/MODIFY">
|
||||
|
||||
{% csrf_token %}
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
<th>ID</th>
|
||||
<th>USER</th>
|
||||
<th>OS</th>
|
||||
<th>Last Updated</th>
|
||||
<th>UPDATED</th>
|
||||
<th style="width: 60px">GAMES</th>
|
||||
<th style="width: 60px">WON</th>
|
||||
<th style="width: 60px">LOST</th>
|
||||
Reference in new issue
Block a user