def setUp(self): super(APITestBase, self).setUp() self.series = Series.objects.all()[0] self.patch = Patch.objects.all()[2] self.user = TestUser(username='******') self.maintainer = TestUser(username='******') self.maintainer.add_to_maintainers(self.project) self.maintainer2 = TestUser(username='******') self.maintainer2.add_to_maintainers(self.project) # a second series so we can test ordering/filtering test_series = TestSeries(3, project=self.project) time.sleep(1) test_series.insert() self.series2 = Series.objects.all().order_by('submitted')[1] # different user so sorting by submitter is a simple list reversal series3_sender = 'Test Author 3 <*****@*****.**>' # no cover letter test_series = TestSeries(3, project=self.project, sender=series3_sender, has_cover_letter=False) time.sleep(1) test_series.insert() self.series3 = Series.objects.all().order_by('submitted')[2] self.n_series = Series.objects.all().count() self.last_inserted_series = self.series3
def testStringRepresentation(self): series = TestSeries(2) series.insert() series = Series.objects.all()[0] self.assertEquals(str(series), defaults.series_name) revision = series.revisions()[0] self.assertEquals(str(revision), 'Revision 1')
def testSinglePatchUpdateNoCoverLetterNoSeriesMarker(self): """ + patch 1/2 +--+ patch 2/2 +--> patch v2 (but no 2/2) """ series = TestSeries(2, has_cover_letter=False) mails = series.create_mails() patch_2_2_v2 = series.create_patch(in_reply_to=mails[1]) del patch_2_2_v2['Subject'] patch_2_2_v2['Subject'] = '[v2] ' + defaults.patch_name mails.append(patch_2_2_v2) series.insert(mails) self.assertEquals(Series.objects.count(), 1) series = Series.objects.all()[0] self.assertEquals(series.last_revision.version, 2) revisions = SeriesRevision.objects.all() self.assertEquals(revisions.count(), 2) revision = revisions[0] patches = revision.ordered_patches() self.assertEqual(len(patches), 2) self.assertEqual(patches[0].name, '[1/2] ' + defaults.patch_name) self.assertEqual(patches[1].name, '[2/2] ' + defaults.patch_name) revision = revisions[1] patches = revision.ordered_patches() self.assertEqual(len(patches), 2) self.assertEqual(patches[0].name, '[1/2] ' + defaults.patch_name) self.assertEqual(patches[1].name, '[v2] ' + defaults.patch_name)
def testStringRepresentation(self): series = TestSeries(2) series.insert() series = Series.objects.all()[0] self.assertEquals(str(series), defaults.series_name) revision = series.revisions()[0] self.assertEquals(str(revision), 'Revision: 1')
def _create_series(self, n_patches, has_cover_letter=True): self.n_patches = n_patches series = TestSeries(self.n_patches, has_cover_letter) mails = series.create_mails() self.root_msgid = mails[0].get('Message-Id') self.has_cover_letter = has_cover_letter if has_cover_letter: self.series_name = defaults.series_name self.cover_letter = defaults.series_cover_letter else: self.series_name = SERIES_DEFAULT_NAME self.cover_letter = None return (series, mails)
def testSetPatchState(self): series = TestSeries(1, has_cover_letter=False) series.insert() patch = Patch.objects.all()[0] superseded = State.objects.get(name='Superseded') self.rpc.patch_set(patch.pk, {'state': superseded.pk}) patch = Patch.objects.get(pk=patch.pk) self.assertEqual(patch.state, superseded) # make sure we've logged the correct user with the change event self.assertEqual(Patch.objects.count(), 1) events = EventLog.objects.filter(event_id=2) self.assertEqual(events.count(), 1) event = events[0] self.assertEquals(event.user, self.maintainer.user)
def testPartialReferences(self): """Tests using the db to get the full list of references, for emails that only have partial list of ancestors in their References header""" series = TestSeries(3) mails = series.create_mails() self.setMessageId(mails[1], "patch_1_3_v1") self.setMessageId(mails[2], "patch_2_3_v1") self.setMessageId(mails[3], "patch_3_3_v1") # review of patch 2/3 reply_1 = series.create_reply(mails[2]) mails.append(reply_1) self.setMessageId(reply_1, "reply_1") # reply to the review reply_2 = series.create_reply(reply_1) mails.append(reply_2) self.setMessageId(reply_2, "reply_2") # let's add yet another reply reply_3 = series.create_reply(reply_2) mails.append(reply_3) self.setMessageId(reply_3, "reply_3") # now a revised patch (v2), which won't have the whole reference chain patch_v2 = series.create_patch(2, in_reply_to=reply_3, subject_prefix="PATCH v2") mails.append(patch_v2) self.setMessageId(patch_v2, "patch_2_3_v2") # for good measure, a reply to that new patch reply_4 = series.create_reply(patch_v2) mails.append(reply_4) self.setMessageId(reply_4, "reply_4") series.insert(mails) # and now the v3 of that patch, we'll need to reconstruct the full # list of references patch_v3 = series.create_patch(2, in_reply_to=reply_4, subject_prefix="PATCH v3") self.setMessageId(patch_v3, "patch_2_3_v3") self.assertEquals( build_references_list(patch_v3), [ reply_4.get("Message-Id"), patch_v2.get("Message-Id"), reply_3.get("Message-Id"), reply_2.get("Message-Id"), reply_1.get("Message-Id"), mails[2].get("Message-Id"), mails[0].get("Message-Id"), ], )
def testSinglePatchUpdatesNotSerialized(self): """ + patch v1 +--> patch v2 +--> patch v3 """ mails = [] dummy = TestSeries(1) patch_v1 = dummy.create_patch() mails.append(patch_v1) patch_v2 = dummy.create_patch(in_reply_to=mails[0], subject_prefix="PATCH v2") mails.append(patch_v2) patch_v3 = dummy.create_patch(in_reply_to=mails[0], subject_prefix="PATCH v3") mails.append(patch_v3) dummy.insert(mails) self.assertEquals(Series.objects.count(), 1) series = Series.objects.all()[0] self.assertEquals(series.last_revision.version, 3) revisions = SeriesRevision.objects.all() self.assertEquals(revisions.count(), 3) revision = revisions[0] patches = revision.ordered_patches() self.assertEqual(len(patches), 1) self.assertEqual(patches[0].name, defaults.patch_name) revision = revisions[1] patches = revision.ordered_patches() self.assertEqual(len(patches), 1) self.assertEqual(patches[0].name, '[v2] ' + defaults.patch_name) revision = revisions[2] patches = revision.ordered_patches() self.assertEqual(len(patches), 1) self.assertEqual(patches[0].name, '[v3] ' + defaults.patch_name)
def testSeriesAsReplyofSinglePatchCrossSeriesAwarePatchwork(self): """ + initia_patch \ +--+ reply_1 | Before patchwork knew +--+ patch_v2 | about series +--+ reply_2 / +--+ cover letter (0/3) \ +--> patch 1/3 | After patchwork knew +--> patch 2/3 | about series +--> patch 3/3 / """ initial_series = TestSeries(1, has_cover_letter=False) mails = initial_series.create_mails() initial_patch = mails[0] self.setMessageId(initial_patch, 'initial_patch') reply_1 = initial_series.create_reply(initial_patch) mails.append(reply_1) self.setMessageId(reply_1, 'reply_1') patch_v2 = initial_series.create_patch(in_reply_to=reply_1, subject_prefix="PATCH v2") mails.append(patch_v2) reply_2 = initial_series.create_reply(patch_v2) mails.append(reply_2) self.setMessageId(reply_2, 'reply_2') initial_series.insert(mails) # deleting the Series objects so far simulates the transition to # a series-aware patchwork from a previous version not creating # Series objects. Series.objects.all().delete() series = TestSeries(3) series_mails = series.create_mails() self.setMessageId(series_mails[0], 'cover_letter') self.setParentMail(series_mails[0], reply_2) for mail in series_mails[1:]: self.setParentMail(mail, series_mails[0], references=(reply_2, series_mails[0])) series.insert(series_mails) series = Series.objects.all() self.assertEqual(len(series), 1) revisions = series[0].revisions() # FIXME: We don't treat a series sent as a reply as a single # entity. Something that will need fixing. self.assertEqual(len(revisions), 3)
def testPartialReferences(self): """Tests using the db to get the full list of references, for emails that only have partial list of ancestors in their References header""" series = TestSeries(3) mails = series.create_mails() self.setMessageId(mails[1], 'patch_1_3_v1') self.setMessageId(mails[2], 'patch_2_3_v1') self.setMessageId(mails[3], 'patch_3_3_v1') # review of patch 2/3 reply_1 = series.create_reply(mails[2]) mails.append(reply_1) self.setMessageId(reply_1, 'reply_1') # reply to the review reply_2 = series.create_reply(reply_1) mails.append(reply_2) self.setMessageId(reply_2, 'reply_2') # let's add yet another reply reply_3 = series.create_reply(reply_2) mails.append(reply_3) self.setMessageId(reply_3, 'reply_3') # now a revised patch (v2), which won't have the whole reference chain patch_v2 = series.create_patch(2, in_reply_to=reply_3, subject_prefix="PATCH v2") mails.append(patch_v2) self.setMessageId(patch_v2, 'patch_2_3_v2') # for good measure, a reply to that new patch reply_4 = series.create_reply(patch_v2) mails.append(reply_4) self.setMessageId(reply_4, 'reply_4') series.insert(mails) # and now the v3 of that patch, we'll need to reconstruct the full # list of references patch_v3 = series.create_patch(2, in_reply_to=reply_4, subject_prefix="PATCH v3") self.setMessageId(patch_v3, 'patch_2_3_v3') self.assertEquals(build_references_list(patch_v3), [ reply_4.get('Message-Id'), patch_v2.get('Message-Id'), reply_3.get('Message-Id'), reply_2.get('Message-Id'), reply_1.get('Message-Id'), mails[2].get('Message-Id'), mails[0].get('Message-Id') ])
def testThread2Mails(self): series = TestSeries(1) mails = series.create_mails() refs = build_references_list(mails[1]) self.assertEquals(len(refs), 1) self.assertEquals(refs[0], mails[0].get('Message-Id'))
def testSingleMail(self): series = TestSeries(1, has_cover_letter=False) mails = series.create_mails() refs = build_references_list(mails[0]) self.assertEquals(refs, [])