904
904
expected = 'This bug no longer affects %s.' % target_name
905
905
self.assertEqual(expected, notifications[0].message)
907
def test_delete_only_bugtask(self):
908
# Test that the deleting the only bugtask results in an error message.
909
bug = self.factory.makeBug()
910
with FeatureFixture(DELETE_BUGTASK_ENABLED):
911
login_person(bug.owner)
913
'field.actions.delete_bugtask': 'Delete',
915
view = create_initialized_view(
916
bug.default_bugtask, name='+delete', form=form,
918
self.assertEqual([bug.default_bugtask], bug.bugtasks)
919
notifications = view.request.response.notifications
920
self.assertEqual(1, len(notifications))
921
expected = ('Cannot delete only bugtask affecting: %s.'
922
% bug.default_bugtask.target.bugtargetdisplayname)
923
self.assertEqual(expected, notifications[0].message)
907
925
def _create_bugtask_to_delete(self):
908
926
bug = self.factory.makeBug()
909
927
bugtask = self.factory.makeBugTask(bug=bug)
945
963
expected_url = canonical_url(bug.default_bugtask, rootsite='bugs')
946
964
self.assertEqual(dict(bugtask_url=expected_url), result_data)
966
def test_ajax_delete_only_bugtask(self):
967
# Test that deleting the only bugtask returns an empty JSON response
968
# with an error notification.
969
bug = self.factory.makeBug()
970
with FeatureFixture(DELETE_BUGTASK_ENABLED):
971
login_person(bug.owner)
972
# Set up the request so that we correctly simulate an XHR call
973
# from the URL of the bugtask we are deleting.
974
server_url = canonical_url(
975
getUtility(ILaunchpadRoot), rootsite='bugs')
977
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
980
'field.actions.delete_bugtask': 'Delete'
982
view = create_initialized_view(
983
bug.default_bugtask, name='+delete', server_url=server_url,
984
form=form, principal=bug.owner, **extra)
985
result_data = simplejson.loads(view.render())
986
self.assertEqual([bug.default_bugtask], bug.bugtasks)
987
notifications = simplejson.loads(
988
view.request.response.getHeader('X-Lazr-Notifications'))
989
self.assertEqual(1, len(notifications))
990
expected = ('Cannot delete only bugtask affecting: %s.'
991
% bug.default_bugtask.target.bugtargetdisplayname)
992
self.assertEqual(expected, notifications[0][1])
995
view.request.response.getHeader('content-type'))
996
self.assertEqual(None, result_data)
948
998
def test_ajax_delete_non_current_bugtask(self):
949
999
# Test that deleting the non-current bugtask returns the new bugtasks
950
1000
# table as HTML.