summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSenko Rasic <senko.rasic@dobarkod.hr>2011-07-27 09:38:33 (GMT)
committerSenko Rasic <senko.rasic@dobarkod.hr>2011-07-27 14:05:55 (GMT)
commitf58721f8ec6810eee3abb22642a1ceb48536dd7e (patch)
tree2f18241cd236289825be62f0a7584559cdd802ca
parentdf1aa272038a32ed519ae06ce0df6a7f553eb8ef (diff)
downloadgst-qa-system-f58721f8ec6810eee3abb22642a1ceb48536dd7e.tar.gz
gst-qa-system-f58721f8ec6810eee3abb22642a1ceb48536dd7e.tar.xz
web: add current test progress / setup page
-rw-r--r--web/insanityweb/urls.py3
-rw-r--r--web/insanityweb/views.py69
-rw-r--r--web/settings.py5
-rw-r--r--web/templates/insanityweb/current.html58
-rw-r--r--web/templates/insanityweb/index.html71
-rw-r--r--web/templates/insanityweb/test_summary.html2
6 files changed, 173 insertions, 35 deletions
diff --git a/web/insanityweb/urls.py b/web/insanityweb/urls.py
index 143a964..feae2e6 100644
--- a/web/insanityweb/urls.py
+++ b/web/insanityweb/urls.py
@@ -2,6 +2,9 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('web.insanityweb.views',
(r'^$', 'index'),
+ (r'^current/progress.json$', 'current_progress'),
+ (r'^current/stop/$', 'stop_current'),
+ (r'^current/$', 'current'),
(r'^testrun/(?P<testrun_id>\d+)/$', 'testrun_summary'),
(r'^test/(?P<test_id>\d+)/$', 'test_summary'),
(r'^matrix/(?P<testrun_id>\d+)/$', 'matrix_view'),
diff --git a/web/insanityweb/views.py b/web/insanityweb/views.py
index 6caa4b0..8582c66 100644
--- a/web/insanityweb/views.py
+++ b/web/insanityweb/views.py
@@ -1,9 +1,16 @@
-from web.insanity.models import TestRun, Test, TestClassInfo, TestCheckListList, TestArgumentsDict, TestExtraInfoDict
-from django.shortcuts import render_to_response, get_object_or_404
+from web.insanityweb.models import TestRun, Test, TestClassInfo, TestCheckListList, TestArgumentsDict, TestExtraInfoDict
+from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.http import HttpResponse
+from django.conf import settings
import time
from datetime import date
+from insanityweb.runner import runner
+
+from functools import wraps
+from django.http import HttpResponse
+from django.utils import simplejson as json
+
def index(request):
nbruns = request.GET.get("nbruns", 20)
latest_runs = TestRun.objects.withcounts().order_by("-starttime")[:int(nbruns)]
@@ -123,3 +130,61 @@ def matrix_view(request, testrun_id):
def handler404(request):
return "Something went wrong !"
+
+def render_to_json(**jsonargs):
+ """
+ Renders a JSON response with a given returned instance. Assumes json.dumps() can
+ handle the result. The default output uses an indent of 4.
+
+ @render_to_json()
+ def a_view(request, arg1, argN):
+ ...
+ return {'x': range(4)}
+
+ @render_to_json(indent=2)
+ def a_view2(request):
+ ...
+ return [1, 2, 3]
+
+ """
+ def outer(f):
+ @wraps(f)
+ def inner_json(request, *args, **kwargs):
+ result = f(request, *args, **kwargs)
+ r = HttpResponse(mimetype='application/json')
+ if result:
+ indent = jsonargs.pop('indent', 4)
+ r.write(json.dumps(result, indent=indent, **jsonargs))
+ else:
+ r.write("{}")
+ return r
+ return inner_json
+ return outer
+
+@render_to_json()
+def current_progress(request):
+ return {
+ 'progress': runner.get_progress()
+ }
+
+def current(request):
+ test_names = runner.get_test_names()
+ test_folders = settings.INSANITY_TEST_FOLDERS.items()
+
+ if 'submit' in request.POST:
+ test = request.POST.get('test', '')
+ folder = request.POST.get('folder', '')
+ if test in test_names and folder in settings.INSANITY_TEST_FOLDERS:
+ runner.start_test(test, folder)
+ return redirect('web.insanityweb.views.current')
+
+ progress = runner.get_progress()
+ tests_running = (progress is not None)
+ test = runner.get_test_name()
+ folder = settings.INSANITY_TEST_FOLDERS.get(runner.get_test_folder(), '(unknown folder)')
+ return render_to_response("insanityweb/current.html", locals())
+
+def stop_current(request):
+ if 'submit' in request.POST:
+ runner.stop_test()
+ return redirect('web.insanityweb.views.current')
diff --git a/web/settings.py b/web/settings.py
index cadcac1..457042f 100644
--- a/web/settings.py
+++ b/web/settings.py
@@ -87,3 +87,8 @@ INSTALLED_APPS = (
'django.contrib.admin',
'web.insanityweb'
)
+
+# A map of folders that the tests can be run in
+INSANITY_TEST_FOLDERS = {
+ os.path.join(PROJECT_PATH, 'test_media'): 'Test Media Folder'
+}
diff --git a/web/templates/insanityweb/current.html b/web/templates/insanityweb/current.html
new file mode 100644
index 0000000..6f7fa02
--- /dev/null
+++ b/web/templates/insanityweb/current.html
@@ -0,0 +1,58 @@
+{% extends "insanityweb/base.html" %}
+
+{% block title %}
+Insanity QA system - Start / Stop Test
+{% endblock %}
+
+{% block content %}
+
+<h1>Run / View Current Test Run</h1>
+
+<p>
+{% if tests_running %}
+ Running <b>{{ test }}</b> in <b>{{ folder }}</b>: <span id="progress_pct">{{ progress }}</span>% done. <br />
+ <form method="post" action="{% url web.insanityweb.views.stop_current %}">
+ <input type="submit" class="button" name="submit" value="Stop Tests" />
+ </form>
+{% else %}
+ No tests are running.
+
+<form method="post" action="">
+ <h2>Create new test</h2>
+ <select name="test">
+ {% for name in test_names %}
+ <option value="{{ name }}">{{ name }}</option>
+ {% endfor %}
+ </select>
+ in
+ <select name="folder">
+ {% for path, desc in test_folders %}
+ <option value="{{ path }}">{{ desc }}</option>
+ {% endfor %}
+ </select>
+ <input type="submit" class="button" name="submit" value="Start Test Run" />
+</form>
+
+{% endif %}
+</p>
+
+{% if tests_running %}
+<script type="text/javascript">
+$(function() {
+ setInterval(function() {
+ $.getJSON('{% url web.insanityweb.views.current_progress %}', function(data, status, xhr) {
+ if (status == 'success') {
+ var p = data.progress;
+ if ((p != undefined) && (p != null)) {
+ $('#progress_pct').text(data.progress);
+ return;
+ }
+ }
+ window.location.reload();
+ });
+ }, 500);
+});
+</script>
+{% endif %}
+
+{% endblock %}
diff --git a/web/templates/insanityweb/index.html b/web/templates/insanityweb/index.html
index 61743f0..d896812 100644
--- a/web/templates/insanityweb/index.html
+++ b/web/templates/insanityweb/index.html
@@ -6,37 +6,44 @@ Insanity QA system (latest {{nbruns}} runs)
{% block content %}
- {% if latest_runs %}
- <table class="testruns">
- <tr>
- <th class="side"></th>
- <th>Time</th>
- <th>Test(s)</th>
- <th>Client</th>
- <th colspan="6">Views</th>
- </tr>
- {% for run in latest_runs %}
- <tr class="{% cycle row1,row2 %}">
- <th class="side">TestRun #{{ run.id }}</th>
- <td>{{ run.starttime|date:"Y-m-d H:i:s" }}</td>
- <td class="numeric">{{ run.nbtests }}</td>
- <td>
- {{run.clientid.name}}
- {% if run.clientid.user %}
- / {{run.clientid.user}}
- {% endif %}
- </td>
- <td><a href="{{run.get_matrix_view_url}}?showscenario=0">Tests only</a></td>
- <td><a href="{{run.get_matrix_view_url}}?onlyfailed=1&showscenario=0">Failed Tests</a></td>
- <td><a href="{{run.get_matrix_view_url}}">Tests+Scenarios</a></td>
- <td><a href="{{run.get_matrix_view_url}}?onlyfailed=1">Failed Tests+Scenarios</a></td>
- <td><a href="{{run.get_matrix_view_url}}?crashonly=1">Crashed Tests</a></td>
- <td><a href="{{run.get_matrix_view_url}}?timedoutonly=1">Timed-out Tests</a></td>
- </tr>
- {% endfor %}
- </table>
- {% else %}
- <p>No Test Runs are currently available.</p>
- {% endif %}
+<p>
+ <a href="{% url web.insanityweb.views.current %}">Run new test or view test progress</a>
+</p>
+
+{% if latest_runs %}
+ <h2>
+ Overview of the latest {{ nbruns }} runs
+ </h2>
+
+ <table class="testruns">
+ <tr>
+ <th class="side"></th>
+ <th>Time</th>
+ <th>Test(s)</th>
+ <th>Client</th>
+ <th colspan="6">Views</th>
+ </tr>
+ {% for run in latest_runs %}
+ <tr class="{% cycle row1,row2 %}">
+ <th class="side">TestRun #{{ run.id }}</th>
+ <td>{{ run.starttime|date:"Y-m-d H:i:s" }}</td>
+ <td class="numeric">{{ run.nbtests }}</td>
+ <td>
+ {{run.clientid.name}} {% if run.clientid.user %}/ {{run.clientid.user}}{% endif %}
+ </td>
+ <td><a href="{{run.get_matrix_view_url}}?showscenario=0">Tests only</a></td>
+ <td><a href="{{run.get_matrix_view_url}}?onlyfailed=1&amp;showscenario=0">Failed Tests</a></td>
+ <td><a href="{{run.get_matrix_view_url}}">Tests+Scenarios</a></td>
+ <td><a href="{{run.get_matrix_view_url}}?onlyfailed=1">Failed Tests+Scenarios</a></td>
+ <td><a href="{{run.get_matrix_view_url}}?crashonly=1">Crashed Tests</a></td>
+ <td><a href="{{run.get_matrix_view_url}}?timedoutonly=1">Timed-out Tests</a></td>
+ </tr>
+ {% endfor %}
+ </table>
+{% else %}
+ <p>
+ No Test Runs are currently available.
+ </p>
+{% endif %}
{% endblock %}
diff --git a/web/templates/insanityweb/test_summary.html b/web/templates/insanityweb/test_summary.html
index a016263..88938d4 100644
--- a/web/templates/insanityweb/test_summary.html
+++ b/web/templates/insanityweb/test_summary.html
@@ -111,7 +111,7 @@ Test #{{test.id}}
{% endif %}
</tr>
{% endfor %}
- </table>
+ </table>
</td>
</tr>
{% endif %}