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)
def test_list_bug_335(self): """Ensure we retrieve the embedded series project in O(1).""" series = create_series() create_patches(5, series=series) with self.assertNumQueries(5): self.client.get(self.api_url())
def test_list_bug_335(self): """Ensure we retrieve the embedded series project in O(1).""" series = create_series() create_patches(5, series=series) # TODO(stephenfin): Remove when we drop support for Django < 3.2 num_queries = 7 if django.VERSION < (3, 2) else 5 with self.assertNumQueries(num_queries): self.client.get(self.api_url())
def setUp(self, count=3): self.user = create_user() self.client.login(username=self.user.username, password=self.user.username) self.bundle = create_bundle(owner=self.user) self.project = create_project() self.patches = create_patches(count, project=self.project)
def test_create_two_patch_relation_user(self): patches = create_patches(2, project=self.project) self.client.force_authenticate(user=self.normal_user) resp = self.client.patch(self.api_url(item=patches[0].pk), {'related': [patches[1].pk]}) self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
def test_unexpired_notification_merge(self): """Test that when there are multiple pending notifications, with at least one within the notification delay, that other notifications are held""" patches = create_patches(2, project=self.project) for patch in patches: patch.save() PatchChangeNotification(patch=patch, orig_state=patch.state).save() state = create_state() self.assertEqual(PatchChangeNotification.objects.count(), len(patches)) self._expire_notifications() # update one notification, to bring it out of the notification delay patches[0].state = state patches[0].save() # the updated notification should prevent the other from being sent errors = send_notifications() self.assertEqual(errors, []) self.assertEqual(len(mail.outbox), 0) # expire the updated notification self._expire_notifications() errors = send_notifications() self.assertEqual(errors, []) self.assertEqual(len(mail.outbox), 1) msg = mail.outbox[0] for patch in patches: self.assertIn(patch.get_absolute_url(), msg.body)
def setUp(self): super(TestCheckAPI, self).setUp() self.patch = create_patches()[0] self.urlbase = reverse('api_1.0:patch-detail', args=[self.patch.id]) self.urlbase += 'checks/' defaults.project.save() self.user = create_maintainer(defaults.project)
def test_create_two_patch_relation_nobody(self): patches = create_patches(2, project=self.project) resp = self.client.patch( self.api_url(item=patches[0].pk), {'related': [patches[1].pk]} ) self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
def test_redirect(self): patches = create_patches() patch_id = patches[0].id requested_url = reverse('cover-detail', kwargs={'cover_id': patch_id}) redirect_url = reverse('patch-detail', kwargs={'patch_id': patch_id}) response = self.client.post(requested_url) self.assertRedirects(response, redirect_url)
def test_delete_two_patch_relation_nobody(self): relation = create_relation() patch = create_patches(2, project=self.project, related=relation)[0] self.assertEqual(PatchRelation.objects.count(), 1) resp = self.client.patch(self.api_url(item=patch.pk), {'related': []}) self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(PatchRelation.objects.count(), 1)
def setUp(self, patch_count=3): self.user = create_user() self.client.login(username=self.user.username, password=self.user.username) defaults.project.save() self.bundle = Bundle(owner=self.user, project=defaults.project, name='testbundle') self.bundle.save() self.patches = create_patches(patch_count)
def test_forbid_moving_patch_between_relations(self): """Test the break-before-make logic""" relation_a = create_relation() create_patches(2, project=self.project, related=relation_a) relation_b = create_relation() create_patches(2, project=self.project, related=relation_b) patch_a = relation_a.patches.first() patch_b = relation_b.patches.first() self.client.force_authenticate(user=self.maintainer) resp = self.client.patch(self.api_url(item=patch_a.pk), {'related': [patch_b.pk]}) self.assertEqual(resp.status_code, status.HTTP_409_CONFLICT) resp = self.client.patch(self.api_url(item=patch_b.pk), {'related': [patch_a.pk]}) self.assertEqual(resp.status_code, status.HTTP_409_CONFLICT)
def test_user_profile_todos(self): patches = utils.create_patches(5) for patch in patches: patch.delegate = self.user patch.save() response = self.client.get(reverse('user-profile')) self.assertContains(response, 'contains 5') self.assertContains(response, reverse('user-todos'))
def testUserProfileTodos(self): patches = utils.create_patches(5) for patch in patches: patch.delegate = self.user.user patch.save() response = self.client.get('/user/') self.assertContains(response, 'contains 5') self.assertContains(response, reverse('user-todos'))
def setUp(self): defaults.project.save() self.user = create_maintainer(defaults.project) self.client.login(username=self.user.username, password=self.user.username) self.properties_form_id = 'patchform-properties' self.url = reverse('patch-list', args=[defaults.project.linkname]) self.base_data = { 'action': 'Update', 'project': str(defaults.project.id), 'form': 'patchlistform', 'archived': '*', 'delegate': '*', 'state': '*'} self.patches = create_patches(3)
def test_delete_from_three_patch_relation(self): relation = create_relation() patch = create_patches(3, project=self.project, related=relation)[0] self.assertEqual(PatchRelation.objects.count(), 1) self.client.force_authenticate(user=self.maintainer) resp = self.client.patch(self.api_url(item=patch.pk), {'related': []}) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertIsNone(Patch.objects.get(id=patch.pk).related) self.assertEqual(PatchRelation.objects.count(), 1) self.assertEqual(PatchRelation.objects.first().patches.count(), 2)
def test_delete_two_patch_relation_maintainer(self): relation = create_relation() patch = create_patches(2, project=self.project, related=relation)[0] self.assertEqual(PatchRelation.objects.count(), 1) self.client.force_authenticate(user=self.maintainer) resp = self.client.patch(self.api_url(item=patch.pk), {'related': []}) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(PatchRelation.objects.count(), 0) self.assertEqual( Patch.objects.filter(related__isnull=False).exists(), False)
def test_create_two_patch_relation_maintainer(self): patches = create_patches(2, project=self.project) self.client.force_authenticate(user=self.maintainer) resp = self.client.patch(self.api_url(item=patches[0].pk), {'related': [patches[1].pk]}) self.assertEqual(resp.status_code, status.HTTP_200_OK) # reload and verify patches = Patch.objects.all() self.assertIsNotNone(patches[0].related) self.assertIsNotNone(patches[1].related) self.assertEqual(patches[1].related, patches[0].related)
def test_remove_one_patch_from_relation_good(self): relation = create_relation() target_patch = create_patches(3, project=self.project, related=relation)[0] # maintainer self.client.force_authenticate(user=self.maintainer) resp = self.client.patch(self.api_url(item=target_patch.pk), {'related': []}) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertIsNone(Patch.objects.get(id=target_patch.id).related) self.assertEqual(relation.patches.count(), 2)
def test_extend_relation_through_new(self): relation = create_relation() existing_patch_a = create_patches(2, project=self.project, related=relation)[0] new_patch = create_patch(project=self.project) self.client.force_authenticate(user=self.maintainer) resp = self.client.patch(self.api_url(item=new_patch.pk), {'related': [existing_patch_a.pk]}) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(relation, Patch.objects.get(pk=new_patch.pk).related) self.assertEqual(relation.patches.count(), 3)
def test_remove_one_patch_from_relation_bad(self): relation = create_relation() patches = create_patches(3, project=self.project, related=relation) keep_patch_a = patches[1] keep_patch_b = patches[1] # this should do nothing - it is interpreted as # _adding_ keep_patch_b again which is a no-op. # maintainer self.client.force_authenticate(user=self.maintainer) resp = self.client.patch(self.api_url(item=keep_patch_a.pk), {'related': [keep_patch_b.pk]}) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(relation.patches.count(), 3)
def test_notification_merge(self): """Ensure only one summary email is delivered to each user.""" patches = create_patches(2, project=self.project) for patch in patches: PatchChangeNotification(patch=patch, orig_state=patch.state).save() self.assertEqual(PatchChangeNotification.objects.count(), len(patches)) self._expire_notifications() errors = send_notifications() self.assertEqual(errors, []) self.assertEqual(len(mail.outbox), 1) msg = mail.outbox[0] for patch in patches: self.assertIn(patch.get_absolute_url(), msg.body)
def setUp(self): self.project = create_project() self.user = create_maintainer(self.project) self.patches = create_patches(3, project=self.project) self.client.login(username=self.user.username, password=self.user.username) self.url = reverse('patch-list', args=[self.project.linkname]) self.base_data = { 'action': 'Update', 'project': str(self.project.id), 'form': 'patchlistform', 'archived': '*', 'delegate': '*', 'state': '*' }
def test_patch_relations_changed(self): # purposefully setting series to None to minimize additional events relation = utils.create_relation() patches = utils.create_patches(3, series=None) # mark the first two patches as related; the second patch should be the # one that the event is raised for patches[0].related = relation patches[0].save() patches[1].related = relation patches[1].save() events = _get_events(patch=patches[1]) self.assertEqual(events.count(), 2) self.assertEqual(events[1].category, Event.CATEGORY_PATCH_RELATION_CHANGED) self.assertEqual(events[1].project, patches[1].project) self.assertIsNone(events[1].previous_relation) self.assertIsNone(events[1].current_relation) # add the third patch patches[2].related = relation patches[2].save() events = _get_events(patch=patches[2]) self.assertEqual(events.count(), 2) self.assertEqual(events[1].category, Event.CATEGORY_PATCH_RELATION_CHANGED) self.assertEqual(events[1].project, patches[1].project) self.assertIsNone(events[1].previous_relation) self.assertIsNone(events[1].current_relation) # drop the third patch patches[2].related = None patches[2].save() events = _get_events(patch=patches[2]) self.assertEqual(events.count(), 3) self.assertEqual(events[2].category, Event.CATEGORY_PATCH_RELATION_CHANGED) self.assertEqual(events[2].project, patches[1].project) self.assertIsNone(events[2].previous_relation) self.assertIsNone(events[2].current_relation)
def test_list_two_patch_relation(self): relation = create_relation() patches = create_patches(2, project=self.project, related=relation) # nobody resp = self.client.get(self.api_url(item=patches[0].pk)) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertIn('related', resp.data) self.assertEqual(len(resp.data['related']), 1) self.assertEqual(resp.data['related'][0]['id'], patches[1].pk) resp = self.client.get(self.api_url(item=patches[1].pk)) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertIn('related', resp.data) self.assertEqual(len(resp.data['related']), 1) self.assertEqual(resp.data['related'][0]['id'], patches[0].pk)
def setUp(self): self.patches = create_patches()
def create_single(self, **kwargs): return utils.create_patches(**kwargs)[0]
def testListMultiple(self): utils.create_patches(5) patches = self.rpc.patch_list() self.assertEqual(len(patches), 5)
def setUp(self): self.patch = create_patches()[0] self.user = create_user()
def setUp(self): self.user = create_user() self.user.profile.items_per_page = ITEMS_PER_PAGE self.user.profile.save() self.project = create_project() self.patches = create_patches(10, project=self.project)
def test_list_single(self): patch_objs = create_patches() patches = self.rpc.patch_list() self.assertEqual(len(patches), 1) self.assertEqual(patches[0]['id'], patch_objs[0].id)
def test_list_multiple(self): create_patches(5) patches = self.rpc.patch_list() self.assertEqual(len(patches), 5)
def test_list_max_count(self): patch_objs = create_patches(5) patches = self.rpc.patch_list({'max_count': 2}) self.assertEqual(len(patches), 2) self.assertEqual(patches[0]['id'], patch_objs[0].id)
def test_list_negative_max_count(self): patch_objs = create_patches(5) patches = self.rpc.patch_list({'max_count': -1}) self.assertEqual(len(patches), 1) self.assertEqual(patches[0]['id'], patch_objs[-1].id)