diff --git a/codespeed/models.py b/codespeed/models.py index fdd936fe..77e0571e 100644 --- a/codespeed/models.py +++ b/codespeed/models.py @@ -6,12 +6,14 @@ from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse -from django.db import models from django.conf import settings +from django.db import models +from django.utils.encoding import python_2_unicode_compatible from .commits.github import GITHUB_URL_RE +@python_2_unicode_compatible class Project(models.Model): NO_LOGS = 'N' GIT = 'G' @@ -38,7 +40,7 @@ class Project(models.Model): blank=True, max_length=200) track = models.BooleanField("Track changes", default=True) - def __unicode__(self): + def __str__(self): return self.name @property @@ -71,11 +73,12 @@ def save(self, *args, **kwargs): super(Project, self).save(*args, **kwargs) +@python_2_unicode_compatible class Branch(models.Model): name = models.CharField(max_length=20) project = models.ForeignKey(Project, related_name="branches") - def __unicode__(self): + def __str__(self): return self.project.name + ":" + self.name class Meta: @@ -83,6 +86,7 @@ class Meta: verbose_name_plural = "branches" +@python_2_unicode_compatible class Revision(models.Model): # git and mercurial's SHA-1 length is 40 commitid = models.CharField(max_length=42) @@ -100,7 +104,7 @@ def get_short_commitid(self): def get_browsing_url(self): return self.branch.project.commit_browsing_url.format(**self.__dict__) - def __unicode__(self): + def __str__(self): if self.date is None: date = None else: @@ -123,6 +127,7 @@ def clean(self): raise ValidationError("Invalid SVN commit id %s" % self.commitid) +@python_2_unicode_compatible class Executable(models.Model): name = models.CharField(max_length=30) description = models.CharField(max_length=200, blank=True) @@ -131,10 +136,11 @@ class Executable(models.Model): class Meta: unique_together = ('name', 'project') - def __unicode__(self): + def __str__(self): return self.name +@python_2_unicode_compatible class Benchmark(models.Model): B_TYPES = ( ('C', 'Cross-project'), @@ -154,7 +160,7 @@ class Benchmark(models.Model): default_on_comparison = models.BooleanField( "Default on comparison page", default=True) - def __unicode__(self): + def __str__(self): return self.name def clean(self): @@ -164,6 +170,7 @@ def clean(self): "'default_on_comparison' first.") +@python_2_unicode_compatible class Environment(models.Model): name = models.CharField(unique=True, max_length=100) cpu = models.CharField(max_length=100, blank=True) @@ -171,10 +178,11 @@ class Environment(models.Model): os = models.CharField(max_length=100, blank=True) kernel = models.CharField(max_length=100, blank=True) - def __unicode__(self): + def __str__(self): return self.name +@python_2_unicode_compatible class Result(models.Model): value = models.FloatField() std_dev = models.FloatField(blank=True, null=True) @@ -186,13 +194,14 @@ class Result(models.Model): benchmark = models.ForeignKey(Benchmark, related_name="results") environment = models.ForeignKey(Environment, related_name="results") - def __unicode__(self): + def __str__(self): return u"%s: %s" % (self.benchmark.name, self.value) class Meta: unique_together = ("revision", "executable", "benchmark", "environment") +@python_2_unicode_compatible class Report(models.Model): revision = models.ForeignKey(Revision, related_name="reports") environment = models.ForeignKey(Environment, related_name="reports") @@ -201,7 +210,7 @@ class Report(models.Model): colorcode = models.CharField(max_length=10, default="none") _tablecache = models.TextField(blank=True) - def __unicode__(self): + def __str__(self): return u"Report for %s" % self.revision class Meta: @@ -534,3 +543,4 @@ def _get_tablecache(self): if self._tablecache == '': return {} return json.loads(self._tablecache) + diff --git a/codespeed/tests/test_models.py b/codespeed/tests/test_models.py index eb4d04ab..c6aec1fa 100644 --- a/codespeed/tests/test_models.py +++ b/codespeed/tests/test_models.py @@ -11,9 +11,17 @@ class TestProject(TestCase): def setUp(self): self.github_project = Project( - repo_type='H', repo_path='https://github.com/tobami/codespeed.git') - self.git_project = Project(repo_type='G', - repo_path='/home/foo/codespeed') + name='Some Project', + repo_type='H', + repo_path='https://github.com/tobami/codespeed.git' + ) + self.git_project = Project( + repo_type='G', + repo_path='/home/foo/codespeed' + ) + + def test_str(self): + self.assertEqual(str(self.github_project), 'Some Project') def test_repo_name(self): """Test that only projects with local repositories have a repo_name attribute diff --git a/codespeed/tests/test_domain.py b/codespeed/tests/test_views_data.py similarity index 100% rename from codespeed/tests/test_domain.py rename to codespeed/tests/test_views_data.py