~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/browser/tests/test_bugtask.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-11-19 05:44:39 UTC
  • mfrom: (14307.1.2 delete-all-bugtasks-889202)
  • Revision ID: launchpad@pqm.canonical.com-20111119054439-j50wq607sp3mpmrm
[r=sinzui][bug=889202] Display a user friendly error message when a
        user attempts to delete the last bug task.

Show diffs side-by-side

added added

removed removed

Lines of Context:
904
904
            expected = 'This bug no longer affects %s.' % target_name
905
905
            self.assertEqual(expected, notifications[0].message)
906
906
 
 
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)
 
912
            form = {
 
913
                'field.actions.delete_bugtask': 'Delete',
 
914
                }
 
915
            view = create_initialized_view(
 
916
                bug.default_bugtask, name='+delete', form=form,
 
917
                principal=bug.owner)
 
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)
 
924
 
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)
947
965
 
 
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')
 
976
            extra = {
 
977
                'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
 
978
                }
 
979
            form = {
 
980
                'field.actions.delete_bugtask': 'Delete'
 
981
                }
 
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])
 
993
            self.assertEqual(
 
994
                'application/json',
 
995
                view.request.response.getHeader('content-type'))
 
996
            self.assertEqual(None, result_data)
 
997
 
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.