summaryrefslogtreecommitdiff
path: root/patchwork/tests
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2019-12-01 17:10:43 +0000
committerStephen Finucane <stephen@that.guru>2019-12-27 13:21:03 +0000
commit9f72eb793dfb6e9d7ff54465d4b07291e9a75e38 (patch)
treeea75b3298bcd616c3686fee1d340de59b49fc30f /patchwork/tests
parent757b33fa606aa7fcf3d2aafc1a6c2297fe3c9e3d (diff)
downloadpatchwork-9f72eb793dfb6e9d7ff54465d4b07291e9a75e38.tar
patchwork-9f72eb793dfb6e9d7ff54465d4b07291e9a75e38.tar.gz
models: Use database constraints to prevent split Series
Currently, the 'SeriesReference' object has a unique constraint on the two fields it has, 'series', which is a foreign key to 'Series', and 'msgid'. This is the wrong constraint. What we actually want to enforce is that a patch, cover letter or comment is referenced by a single series, or rather a single series per project the submission appears on. As such, we should be enforcing uniqueness on the msgid and the project that the patch, cover letter or comment belongs to. This requires adding a new field to the object, 'project', since it's not possible to do something like the following: unique_together = [('msgid', 'series__project')] This is detailed here [1]. In addition, the migration needs a precursor migration step to merge any broken series. [1] https://stackoverflow.com/a/4440189/613428 Signed-off-by: Stephen Finucane <stephen@that.guru> Closes: #241 Cc: Daniel Axtens <dja@axtens.net> Cc: Petr Vorel <petr.vorel@gmail.com>
Diffstat (limited to 'patchwork/tests')
-rw-r--r--patchwork/tests/test_parser.py9
-rw-r--r--patchwork/tests/utils.py6
2 files changed, 11 insertions, 4 deletions
diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py
index 0bf7158..0edbd87 100644
--- a/patchwork/tests/test_parser.py
+++ b/patchwork/tests/test_parser.py
@@ -421,17 +421,20 @@ class SeriesCorrelationTest(TestCase):
msgids = [make_msgid()]
project = create_project()
series_v1 = create_series(project=project)
- create_series_reference(msgid=msgids[0], series=series_v1)
+ create_series_reference(msgid=msgids[0], series=series_v1,
+ project=project)
# ...and three patches
for i in range(3):
msgids.append(make_msgid())
- create_series_reference(msgid=msgids[-1], series=series_v1)
+ create_series_reference(msgid=msgids[-1], series=series_v1,
+ project=project)
# now create a new series with "cover letter"
msgids.append(make_msgid())
series_v2 = create_series(project=project)
- ref_v2 = create_series_reference(msgid=msgids[-1], series=series_v2)
+ ref_v2 = create_series_reference(msgid=msgids[-1], series=series_v2,
+ project=project)
# ...and the "first patch" of this new series
msgid = make_msgid()
diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py
index 91bcbe1..5e6a1b1 100644
--- a/patchwork/tests/utils.py
+++ b/patchwork/tests/utils.py
@@ -283,8 +283,12 @@ def create_series(**kwargs):
def create_series_reference(**kwargs):
"""Create 'SeriesReference' object."""
+ project = kwargs.pop('project', create_project())
+ series = kwargs.pop('series', create_series(project=project))
+
values = {
- 'series': create_series() if 'series' not in kwargs else None,
+ 'series': series,
+ 'project': project,
'msgid': make_msgid(),
}
values.update(**kwargs)