Commits

Anonymous committed 6155bd7

basic views done, checkpointing

Comments (0)

Files changed (6)

web/results/management/commands/parse_results.py

 from zipfile import ZipFile, ZIP_DEFLATED
 from contextlib import closing
 
-from bender import results
-
 from web.results import models
 
 # XXX - fixme
                 xml = os.path.join(sdir, 'artifacts', 'noseresults.xml')
                 sres = models.Result(jobid=job, slave=slave, result=result, xmlfile=xml)
                 sres.save()
-                print results.parse_nose_results(open(xml, 'r').read())
                 results.append(sres)
             for i in slaves:
                 job.slaves.add(i)
             job.save()
             print '-' * 10
 
+
 def _import_hub(sdir):
     hubf = os.path.join(sdir, 'hub.json')
     if not os.path.isfile(hubf):

web/results/models.py

     result = models.IntegerField(max_length=10)
     xmlfile = models.CharField(max_length=1000)
 
-
 class Hub(models.Model):
     ipaddr = models.IPAddressField(unique=True)
     port = models.IntegerField(max_length=9999)

web/results/templatetags/__init__.py

Empty file added.

web/results/templatetags/get.py

+from django.utils.http import urlquote_plus
+from django.template.defaultfilters import stringfilter
+
+from django import template
+register = template.Library()
+
+@register.filter
+def get(thedict, thekey):
+    return thedict.get(thekey, '')

web/results/views.py

 # Create your views here.
 
+import os
+from xml.etree import ElementTree
+from StringIO import StringIO
+
 from django.shortcuts import redirect
 from django.template import RequestContext
 from django.shortcuts import render_to_response, get_object_or_404
 
-from bender import results
-
 from . import models
 
 def main(request):
     return render_to_response('main.html', {'jobs': jobs},
                                context_instance=RequestContext(request))
 
+
 def tag_view(request, tagname):
     tag = get_object_or_404(models.Tag, tag=tagname)
     jobs = tag.job_set.all()
     return render_to_response('tag.html', {'jobs': jobs, 'tag': tagname},
                                context_instance=RequestContext(request))
 
+
 def tags(request):
     tags = models.Tag.objects.all()
     return render_to_response('tags.html', {'tags': tags},
                                context_instance=RequestContext(request))
 
+
 def run_details(request, guid):
+    data = {}
     job = get_object_or_404(models.Job, jobid=guid)
-    for result in job.results.all():
-        pass
-    return render_to_response('job.html', {'job': job, 'jobid': guid},
+    presults = _get_detailed_results(job.results)
+    return render_to_response('job.html', {'job': job,
+                                           'presults': presults,
+                                           'jobid': guid},
                                context_instance=RequestContext(request))
 
+
+def _get_detailed_results(queryset):
+    presults = {}
+    for result in queryset.all():
+        presults[result.slave.slaveid] = None
+        if os.path.isfile(result.xmlfile):
+            presults[result.slave.slaveid] = parse_nose_results(open(result.xmlfile, 'r').read())
+    return presults
+
+
+def parse_nose_results(nose_data):
+    """Parse nose_data into dict with keys:
+    suite: tests, errors, skips, fails, time
+    cases:
+        test_name_1: time, ...
+        test_name_2: time, ...
+    """
+    if not nose_data:
+        return 
+    result = {'suite':{}, 'cases':{}}
+    tree = ElementTree.parse(StringIO(nose_data))
+    for element in tree.getiterator():
+        if element.tag == 'testsuite':
+            result['suite'] = dict(element.items())
+        else:
+            items = dict(element.items())
+            if 'name' in items:
+                name = items['name']
+                del items['name']
+                result['cases'][name] = items
+            else:
+                result['cases'][name]['errors'] = items
+                result['cases'][name]['text'] = element.text
+    return result
+
 """
 class Result(models.Model):
     jobid = models.ForeignKey('Job', related_name='ham')

web/templates/job.html

 {% extends "display.html" %}
+{% load get %}
 
 {% block header %}
     <h3>Bender :: detailed results for job: {{ jobid }}</h3>
             <div class="slave-result slaveError">
         {% endif %}
             <b>Slave Name</b>: {{ result.slave.name }} <span>&#149;</span> <b>Platform</b>: {{ result.slave.platform }} <span>&#149;</span> <b>Result</b>: {% if result.result == 0 %}Pass{% else %}Fail{% endif %}
+            <br/>
+            {% with result.slave.slaveid as slaveid %}
+                {% with presults|get:slaveid as myresult %}
+                    {% if myresult %}
+                        <span>
+                        <b>Tests Run</b>: {{ myresult.suite.tests }} <span>&#149;</span>
+                        <b>Failures</b>: {{ myresult.suite.failures }} <span>&#149;</span>
+                        <b>Errors</b>: {{ myresult.suite.errors }} <span>&#149;</span>
+                        <b>Skipped</b>: {{ myresult.suite.skip }}
+                        </span>
+                    {% endif %}
+                {% endwith %}
+            {% endwith %}
         </div>
     {% endfor %}
 {% endblock %}