Commit 5053ed6f authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

tests: Don't cache 'defaults' globally

Project and Person instances were stored globally, keeping their PK(s)
even when db cleaning removed them, causing some saves() to overwrite
them when used with sqlite3.
Signed-off-by: default avatarArkadiusz Hiler <>
parent 9d1e22a5
......@@ -30,14 +30,17 @@ from patchwork.models import (Project, Person, Patch, Comment, State, EventLog,
Event, SeriesRevision,
from patchwork.tests.utils import (read_patch, read_mail, create_email,
defaults, create_user)
defaults, create_user, classproperty)
class PatchTest(TestCase):
fixtures = ['default_states', 'default_events']
default_sender = defaults.sender
default_subject = defaults.subject
project = defaults.project
def project(cls):
return defaults.project
class InlinePatchTest(PatchTest):
......@@ -27,7 +27,7 @@ from patchwork.models import (Patch, Series, SeriesRevision, Project,
SERIES_DEFAULT_NAME, EventLog, User, Person,
State, RevisionState)
from patchwork.tests.utils import read_mail
from patchwork.tests.utils import defaults, TestSeries
from patchwork.tests.utils import defaults, TestSeries, classproperty
from patchwork.bin.parsemail import parse_mail, build_references_list, \
......@@ -95,7 +95,9 @@ class SeriesTest(TestCase):
class GeneratedSeriesTest(SeriesTest):
project = defaults.project
def project(cls):
return defaults.project
def _create_series(self, n_patches, has_cover_letter=True):
self.n_patches = n_patches
......@@ -35,13 +35,42 @@ _test_mail_dir = os.path.join(os.path.dirname(__file__), 'mail')
_test_patch_dir = os.path.join(os.path.dirname(__file__), 'patches')
class classproperty(object):
def __init__(self, fget):
self.fget = classmethod(fget)
def __get__(self, obj, klass=None):
if klass is None:
klass = type(obj)
return self.fget.__get__(obj, klass)()
def __set__(self, obj, value):
raise AttributeError("can't set attribute")
class defaults(object):
project = Project(linkname='test-project', name='Test Project',
def project(cls):
name = 'Test Project'
projects = Project.objects.filter(name=name)
if projects:
return projects[0]
return Project(linkname='test-project', name='Test Project',
patch_author = 'Patch Author <>'
patch_author_person = Person(name='Patch Author',
def patch_author_person(cls):
email = ''
persons = Person.objects.filter(email=email)
if persons:
return persons[0]
return Person(name='Patch Author', email=email)
comment_author = 'Comment Author <>'
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