Commit a1bdec36 authored by Cezar Burlacu's avatar Cezar Burlacu Committed by Damien Lespiau
Browse files

testresult: Factor out a TestState enum class



We'd like to add more users of those states, so factor them out in a
separate class.
Signed-off-by: default avatarCezar Burlacu <cezar.burlacu@intel.com>
Signed-off-by: default avatarDamien Lespiau <damien.lespiau@intel.com>
parent 84daebfb
......@@ -446,6 +446,20 @@ class BundlePatch(models.Model):
SERIES_DEFAULT_NAME = "Series without cover letter"
class TestState:
STATE_PENDING = 0
STATE_SUCCESS = 1
STATE_WARNING = 2
STATE_FAILURE = 3
STATE_CHOICES = (
(STATE_PENDING, 'pending'),
(STATE_SUCCESS, 'success'),
(STATE_WARNING, 'warning'),
(STATE_FAILURE, 'failure'),
)
# This Model represents the "top level" Series, an object that doesn't change
# with the various versions of patches sent to the mailing list.
class Series(models.Model):
......@@ -630,23 +644,13 @@ class Test(models.Model):
return self.name
class TestResult(models.Model):
STATE_PENDING = 0
STATE_SUCCESS = 1
STATE_WARNING = 2
STATE_FAILURE = 3
STATE_CHOICES = (
(STATE_PENDING, 'pending'),
(STATE_SUCCESS, 'success'),
(STATE_WARNING, 'warning'),
(STATE_FAILURE, 'failure'),
)
test = models.ForeignKey(Test)
revision = models.ForeignKey(SeriesRevision, blank=True, null=True)
patch = models.ForeignKey(Patch, blank=True, null=True)
user = models.ForeignKey(User)
date = models.DateTimeField(auto_now=True)
state = models.SmallIntegerField(choices=STATE_CHOICES)
state = models.SmallIntegerField(choices=TestState.STATE_CHOICES)
url = models.URLField(blank=True, null=True)
summary = models.TextField(blank=True, null=True)
......
......@@ -23,7 +23,7 @@ from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import models
from patchwork.models import Project, Series, SeriesRevision, Patch, Person, \
State, EventLog, Test, TestResult
State, EventLog, Test, TestResult, TestState
from rest_framework import serializers
from rest_framework import fields
from enum import Enum
......@@ -199,7 +199,7 @@ class ValueChoiceField(serializers.ChoiceField):
class TestResultSerializer(serializers.Serializer):
test_name = serializers.CharField(source='test.name')
state = ValueChoiceField(choices=TestResult.STATE_CHOICES)
state = ValueChoiceField(choices=TestState.STATE_CHOICES)
url = serializers.URLField(required=False, allow_none=True)
summary = serializers.CharField(required=False, allow_none=True)
......
......@@ -31,8 +31,9 @@ from django.core import mail
import patchwork.tests.test_series as test_series
from patchwork.tests.test_user import TestUser
from patchwork.tests.utils import TestSeries
from patchwork.models import Series, Patch, SeriesRevision, Test, TestResult
from patchwork.models import (
Series, Patch, SeriesRevision, Test, TestResult, TestState
)
entry_points = {
'/': {
......@@ -404,7 +405,7 @@ class TestResultTest(APITestBase):
self.assertEqual(result.revision, None)
self.assertEqual(result.patch, self.patch)
self.assertEqual(result.user, self.maintainer.user)
self.assertEqual(result.state, TestResult.STATE_PENDING)
self.assertEqual(result.state, TestState.STATE_PENDING)
self.assertEqual(result.url, None)
self.assertEqual(result.summary, None)
......@@ -442,7 +443,7 @@ class TestResultTest(APITestBase):
results = TestResult.objects.all()
self.assertEqual(len(results), 1)
result = results[0]
self.assertEqual(result.state, TestResult.STATE_PENDING)
self.assertEqual(result.state, TestState.STATE_PENDING)
self.assertEqual(result.url, None)
self.assertEqual(result.summary, None)
......@@ -458,7 +459,7 @@ class TestResultTest(APITestBase):
results = TestResult.objects.all()
self.assertEqual(len(results), 1)
result = results[0]
self.assertEqual(result.state, TestResult.STATE_SUCCESS)
self.assertEqual(result.state, TestState.STATE_SUCCESS)
self.assertEqual(result.url, self.result_url)
self.assertEqual(result.summary, self.result_summary)
......@@ -478,7 +479,7 @@ class TestResultTest(APITestBase):
results = TestResult.objects.all()
self.assertEqual(len(results), 1)
result = results[0]
self.assertEqual(result.state, TestResult.STATE_PENDING)
self.assertEqual(result.state, TestState.STATE_PENDING)
self.assertEqual(result.url, self.result_url)
self.assertEqual(result.summary, self.result_summary)
......@@ -491,7 +492,7 @@ class TestResultTest(APITestBase):
self.assertEqual(r.status_code, 201)
result = TestResult.objects.all()[0]
self.assertEqual(result.state, TestResult.STATE_PENDING)
self.assertEqual(result.state, TestState.STATE_PENDING)
self.assertEqual(result.url, None)
self.assertEqual(result.summary, None)
......
......@@ -29,7 +29,8 @@ from django.core import mail
from django.db.models import Q
from django.http import HttpResponse
from patchwork.models import Project, Series, SeriesRevision, Patch, EventLog, \
Test, TestResult, Person, SERIES_DEFAULT_NAME
Test, TestResult, TestState, Person, \
SERIES_DEFAULT_NAME
from rest_framework import views, viewsets, mixins, generics, filters, \
permissions, status
from rest_framework.authentication import BasicAuthentication
......@@ -258,7 +259,7 @@ class ResultMixin(object):
return obj.name
def _prepare_mail(self, result, obj):
if result.state == TestResult.STATE_SUCCESS:
if result.state == TestState.STATE_SUCCESS:
tick = u"✓"
else:
tick = u"✗"
......@@ -328,12 +329,12 @@ class ResultMixin(object):
if to:
# never send mail on pending
if instance.state == TestResult.STATE_PENDING:
if instance.state == TestState.STATE_PENDING:
to = []
if (instance.test.mail_condition == Test.CONDITION_ON_FAILURE and
instance.state not in (TestResult.STATE_WARNING,
TestResult.STATE_FAILURE)):
instance.state not in (TestState.STATE_WARNING,
TestState.STATE_FAILURE)):
to = []
if to:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment