[PATCH v3 3/8] models: Add 'check' model

Stephen Finucane stephen.finucane at intel.com
Fri Nov 6 04:13:18 AEDT 2015


From: Stephen Finucane <stephenfinucane at hotmail.com>

This will represent the status of tests executed (or executing) against
a patch. This includes a suitable migration and admin view.

Signed-off-by: Stephen Finucane <stephenfinucane at hotmail.com>

--

v3: Remove manual SQL migrations - they're not necessary/possible for
  Django 1.7/1.8, respectively
---
 patchwork/admin.py                           | 11 ++++++-
 patchwork/migrations/0003_add_check_model.py | 33 ++++++++++++++++++++
 patchwork/models.py                          | 45 ++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 patchwork/migrations/0003_add_check_model.py

diff --git a/patchwork/admin.py b/patchwork/admin.py
index 04a8ff8..d32edba 100644
--- a/patchwork/admin.py
+++ b/patchwork/admin.py
@@ -20,7 +20,7 @@
 from django.contrib import admin
 
 from patchwork.models import (
-    Project, Person, UserProfile, State, Patch, Comment, Bundle, Tag)
+    Project, Person, UserProfile, State, Patch, Comment, Bundle, Tag, Check)
 
 
 class ProjectAdmin(admin.ModelAdmin):
@@ -74,6 +74,15 @@ class CommentAdmin(admin.ModelAdmin):
 admin.site.register(Comment, CommentAdmin)
 
 
+class CheckAdmin(admin.ModelAdmin):
+    list_display = ('patch', 'user', 'state', 'target_url',
+                    'description', 'context')
+    exclude = ('date', )
+    search_fields = ('patch__name', 'project__name')
+    date_hierarchy = 'date'
+admin.site.register(Check, CheckAdmin)
+
+
 class BundleAdmin(admin.ModelAdmin):
     list_display = ('name', 'owner', 'project', 'public')
     list_filter = ('public', 'project')
diff --git a/patchwork/migrations/0003_add_check_model.py b/patchwork/migrations/0003_add_check_model.py
new file mode 100644
index 0000000..50bd72b
--- /dev/null
+++ b/patchwork/migrations/0003_add_check_model.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import datetime
+from django.conf import settings
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+        ('patchwork', '0002_fix_patch_state_default_values'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Check',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('date', models.DateTimeField(default=datetime.datetime.now)),
+                ('state', models.SmallIntegerField(default=0, help_text=b'The state of the check.', choices=[(0, b'pending'), (1, b'success'), (2, b'warning'), (3, b'fail')])),
+                ('target_url', models.URLField(help_text=b'The target URL to associate with this check. This should be specific to the patch.', null=True, blank=True)),
+                ('description', models.TextField(help_text=b'A brief description of the check.', null=True, blank=True)),
+                ('context', models.CharField(default=b'default', max_length=255, null=True, help_text=b'A label to discern check from checks of other testing systems.', blank=True)),
+                ('patch', models.ForeignKey(to='patchwork.Patch')),
+                ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
+            ],
+            options={
+            },
+            bases=(models.Model,),
+        ),
+    ]
diff --git a/patchwork/models.py b/patchwork/models.py
index d0b3447..80f1eff 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -1,5 +1,6 @@
 # Patchwork - automated patch tracking system
 # Copyright (C) 2008 Jeremy Kerr <jk at ozlabs.org>
+# Copyright (C) 2015 Intel Corporation
 #
 # This file is part of the Patchwork package.
 #
@@ -430,6 +431,50 @@ class BundlePatch(models.Model):
         ordering = ['order']
 
 
+class Check(models.Model):
+    """Check for a patch.
+
+    Checks store the results of any tests executed (or executing) for a
+    given patch. This is useful, for example, when using a continuous
+    integration (CI) system to test patches.
+    """
+    STATE_PENDING = 0
+    STATE_SUCCESS = 1
+    STATE_WARNING = 2
+    STATE_FAIL = 3
+    STATE_CHOICES = (
+        (STATE_PENDING, 'pending'),
+        (STATE_SUCCESS, 'success'),
+        (STATE_WARNING, 'warning'),
+        (STATE_FAIL, 'fail'),
+    )
+
+    patch = models.ForeignKey(Patch)
+    user = models.ForeignKey(User)
+    date = models.DateTimeField(default=datetime.datetime.now)
+
+    state = models.SmallIntegerField(
+        choices=STATE_CHOICES, default=STATE_PENDING,
+        help_text='The state of the check.')
+    target_url = models.URLField(
+        blank=True, null=True,
+        help_text='The target URL to associate with this check. This should'
+        ' be specific to the patch.')
+    description = models.TextField(
+        blank=True, null=True, help_text='A brief description of the check.')
+    context = models.CharField(
+        max_length=255, default='default', blank=True, null=True,
+        help_text='A label to discern check from checks of other testing '
+        'systems.')
+
+    def __repr__(self):
+        return "<Check id='%d' context='%s' state='%s'" % (
+            self.id, self.context, self.get_state_display())
+
+    def __unicode__(self):
+        return ('%s (%s)' % (self.context, self.get_state_display()))
+
+
 class EmailConfirmation(models.Model):
     validity = datetime.timedelta(days=settings.CONFIRMATION_VALIDITY_DAYS)
     type = models.CharField(max_length=20, choices=[
-- 
2.0.0



More information about the Patchwork mailing list