summaryrefslogtreecommitdiff
path: root/patchwork/tests
diff options
context:
space:
mode:
authorRohit Sarkar <rohitsarkar5398@gmail.com>2020-08-01 11:54:15 +0530
committerDaniel Axtens <dja@axtens.net>2020-08-10 11:44:40 +1000
commitfe0c0ca7279e35904c488dea57345e1d4f13f895 (patch)
treeb8729932c03925beaed944463c2046de152663ac /patchwork/tests
parent8abd63eb75617ffff14205376ca6283c8f5e0ba2 (diff)
downloadpatchwork-fe0c0ca7279e35904c488dea57345e1d4f13f895.tar
patchwork-fe0c0ca7279e35904c488dea57345e1d4f13f895.tar.gz
management: introduce replacerelations command
The replacerelations script is used to ingest relations into Patchwork's patch database. A patch groups file is taken as input, which on each line contains a space separated list of patchwork ids denoting a relation. All the existing relations in Patchwork's database are removed and the relations read from the patch groups file are ingested. Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com> [dja: pep8, drop relations directory as empty dirs don't get stored by git, comment about how lines are generated.] Signed-off-by: Daniel Axtens <dja@axtens.net>
Diffstat (limited to 'patchwork/tests')
-rw-r--r--patchwork/tests/test_management.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/patchwork/tests/test_management.py b/patchwork/tests/test_management.py
index 66c6bad..d24eea9 100644
--- a/patchwork/tests/test_management.py
+++ b/patchwork/tests/test_management.py
@@ -5,6 +5,7 @@
import os
import sys
+import tempfile
from io import StringIO
from django.core.management import call_command
@@ -124,3 +125,47 @@ class ParsearchiveTest(TestCase):
self.assertIn('Processed 1 messages -->', out.getvalue())
self.assertIn(' 1 dropped', out.getvalue())
+
+
+class ReplacerelationsTest(TestCase):
+
+ def test_invalid_path(self):
+ out = StringIO()
+ with self.assertRaises(SystemExit) as exc:
+ call_command('replacerelations', 'xyz123random', '-v 0',
+ stdout=out)
+ self.assertEqual(exc.exception.code, 1)
+
+ def test_valid_relations(self):
+ test_submitter = utils.create_person()
+ utils.create_patches(8, submitter=test_submitter)
+ patch_ids = (models.Patch.objects
+ .filter(submitter=test_submitter)
+ .values_list('id', flat=True))
+
+ with tempfile.NamedTemporaryFile(delete=False,
+ mode='w+') as f1:
+ for i in range(0, len(patch_ids), 3):
+ # we write out the patch IDs this way so that we can
+ # have a mix of 3-patch and 2-patch lines without special
+ # casing the format string.
+ f1.write('%s\n' % ' '.join(map(str, patch_ids[i:(i + 3)])))
+
+ out = StringIO()
+ call_command('replacerelations', f1.name, stdout=out)
+ self.assertEqual(models.PatchRelation.objects.count(), 3)
+ os.unlink(f1.name)
+
+ patch_ids_with_missing = (
+ list(patch_ids) +
+ [i for i in range(max(patch_ids), max(patch_ids) + 3)]
+ )
+ with tempfile.NamedTemporaryFile(delete=False,
+ mode='w+') as f2:
+ for i in range(0, len(patch_ids_with_missing), 3):
+ f2.write('%s\n' % ' '.join(
+ map(str, patch_ids_with_missing[i:(i + 3)])))
+
+ call_command('replacerelations', f2.name, stdout=out)
+ self.assertEqual(models.PatchRelation.objects.count(), 3)
+ os.unlink(f2.name)