def test_subscribe_uses_bug_notification_level(self):
        # When a user subscribes to a bug using the advanced features on
        # the Bug +subscribe page, the bug notification level they
        # choose is taken into account.
        bug = self.factory.makeBug()
        # We unsubscribe the bug's owner because if we don't there will
        # be two COMMENTS-level subscribers.
        with person_logged_in(bug.owner):
            bug.unsubscribe(bug.owner, bug.owner)

        displayed_levels = [
            level for level in BugNotificationLevel.items]
        for level in displayed_levels:
            person = self.factory.makePerson()
            with person_logged_in(person):
                harness = LaunchpadFormHarness(
                    bug.default_bugtask, BugSubscriptionSubscribeSelfView)
                form_data = {
                    'field.subscription': person.name,
                    'field.bug_notification_level': level.title,
                    }
                harness.submit('continue', form_data)

            subscription = bug.getSubscriptionForPerson(person)
            self.assertEqual(
                level, subscription.bug_notification_level,
                "Bug notification level of subscription should be %s, is "
                "actually %s." % (
                    level.title,
                    subscription.bug_notification_level.title))
Example #2
0
    def test_subscribe_uses_bug_notification_level(self):
        # When a user subscribes to a bug using the advanced features on
        # the Bug +subscribe page, the bug notification level they
        # choose is taken into account.
        bug = self.factory.makeBug()
        # We unsubscribe the bug's owner because if we don't there will
        # be two COMMENTS-level subscribers.
        with person_logged_in(bug.owner):
            bug.unsubscribe(bug.owner, bug.owner)

        displayed_levels = [level for level in BugNotificationLevel.items]
        for level in displayed_levels:
            person = self.factory.makePerson()
            with person_logged_in(person):
                harness = LaunchpadFormHarness(
                    bug.default_bugtask, BugSubscriptionSubscribeSelfView)
                form_data = {
                    'field.subscription': person.name,
                    'field.bug_notification_level': level.title,
                }
                harness.submit('continue', form_data)

            subscription = bug.getSubscriptionForPerson(person)
            self.assertEqual(
                level, subscription.bug_notification_level,
                "Bug notification level of subscription should be %s, is "
                "actually %s." %
                (level.title, subscription.bug_notification_level.title))
    def test_field_values_set_correctly_for_existing_subscriptions(self):
        # When a user who is already subscribed to a bug visits the
        # BugSubscriptionSubscribeSelfView, its bug_notification_level
        # field will be set according to their current susbscription
        # level.
        bug = self.factory.makeBug()
        person = self.factory.makePerson()
        with person_logged_in(person):
            # We subscribe using the harness rather than doing it
            # directly so that we don't have to commit() between
            # subscribing and checking the default value.
            level = BugNotificationLevel.METADATA
            harness = LaunchpadFormHarness(
                bug.default_bugtask, BugSubscriptionSubscribeSelfView)
            form_data = {
                'field.subscription': person.name,
                'field.bug_notification_level': level.title,
                }
            harness.submit('continue', form_data)

            # The default value for the bug_notification_level field
            # should now be the same as the level used to subscribe
            # above.
            harness = LaunchpadFormHarness(
                bug.default_bugtask, BugSubscriptionSubscribeSelfView)
            bug_notification_level_widget = (
                harness.view.widgets['bug_notification_level'])
            default_notification_level_value = (
                bug_notification_level_widget._getDefault())
            self.assertEqual(
                BugNotificationLevel.METADATA,
                default_notification_level_value,
                "Default value for bug_notification_level should be "
                "METADATA, is actually %s"
                % default_notification_level_value)
    def test_user_can_update_subscription(self):
        # A user can update their bug subscription using the
        # BugSubscriptionSubscribeSelfView.
        bug = self.factory.makeBug()
        person = self.factory.makePerson()
        with person_logged_in(person):
            bug.subscribe(person, person, BugNotificationLevel.COMMENTS)
            # Now the person updates their subscription so they're
            # subscribed at the METADATA level.
            level = BugNotificationLevel.METADATA
            harness = LaunchpadFormHarness(
                bug.default_bugtask, BugSubscriptionSubscribeSelfView)
            form_data = {
                'field.subscription': 'update-subscription',
                'field.bug_notification_level': level.title,
                }
            harness.submit('continue', form_data)
            self.assertFalse(harness.hasErrors())

        subscription = bug.getSubscriptionForPerson(person)
        self.assertEqual(
            BugNotificationLevel.METADATA,
            subscription.bug_notification_level,
            "Bug notification level of subscription should be METADATA, is "
            "actually %s." % subscription.bug_notification_level.title)
 def _assert_subscription_fails(self, team):
     with person_logged_in(self.user):
         harness = LaunchpadFormHarness(
             self.bug.default_bugtask, BugSubscriptionAddView)
         form_data = {'field.person': team.name}
         harness.submit('add', form_data)
     subscription = removeSecurityProxy(self.bug).getSubscriptionForPerson(
         team)
     error_msg = harness.getFieldError('person')
     expected_msg = (u'Open and delegated teams cannot be subscribed to '
         'private bugs.')
     self.assertEqual(expected_msg, error_msg)
     self.assertIs(None, subscription)
Example #6
0
 def _assert_subscription_fails(self, team):
     with person_logged_in(self.user):
         harness = LaunchpadFormHarness(self.bug.default_bugtask,
                                        BugSubscriptionAddView)
         form_data = {'field.person': team.name}
         harness.submit('add', form_data)
     subscription = removeSecurityProxy(
         self.bug).getSubscriptionForPerson(team)
     error_msg = harness.getFieldError('person')
     expected_msg = (u'Open and delegated teams cannot be subscribed to '
                     'private bugs.')
     self.assertEqual(expected_msg, error_msg)
     self.assertIs(None, subscription)
    def _testCancelAction(self, view_class, token):
        """Test the 'Cancel' action of the given view, using the given token.

        To test that the action works, we just submit the form with that
        action, check that there are no errors and make sure that the view's
        next_url is what we expect.
        """
        harness = LaunchpadFormHarness(token, view_class)
        harness.submit('cancel', {})
        actions = harness.view.actions.byname
        self.assertIn('field.actions.cancel', actions)
        self.assertEquals(actions['field.actions.cancel'].submitted(), True)
        self.assertEquals(harness.view.errors, [])
        self.assertEquals(harness.view.next_url, self.expected_next_url)
Example #8
0
    def _testCancelAction(self, view_class, token):
        """Test the 'Cancel' action of the given view, using the given token.

        To test that the action works, we just submit the form with that
        action, check that there are no errors and make sure that the view's
        next_url is what we expect.
        """
        harness = LaunchpadFormHarness(token, view_class)
        harness.submit('cancel', {})
        actions = harness.view.actions.byname
        self.assertIn('field.actions.cancel', actions)
        self.assertEqual(actions['field.actions.cancel'].submitted(), True)
        self.assertEqual(harness.view.errors, [])
        self.assertEqual(harness.view.next_url, self.expected_next_url)
 def test_form_initializes(self):
     # It's a start.
     with person_logged_in(self.subscriber):
         self.product.addBugSubscription(self.subscriber, self.subscriber)
         harness = LaunchpadFormHarness(self.product,
                                        TargetSubscriptionView)
         harness.view.initialize()
Example #10
0
    def test_data_subscription_lp_admin(self):
        # For a subscription, subscriber_data_js has can_edit
        # set to true for a Launchpad admin.
        bug = self._makeBugWithNoSubscribers()
        member = self.factory.makePerson()
        subscriber = self.factory.makePerson(name='user',
                                             displayname='Subscriber Name')
        with person_logged_in(member):
            bug.subscribe(subscriber,
                          subscriber,
                          level=BugNotificationLevel.LIFECYCLE)
        harness = LaunchpadFormHarness(bug, BugPortletSubscribersWithDetails)
        api_request = IWebServiceClientRequest(harness.request)

        expected_result = {
            'subscriber': {
                'name': 'user',
                'display_name': 'Subscriber Name',
                'is_team': False,
                'can_edit': True,
                'web_link': canonical_url(subscriber),
                'self_link': absoluteURL(subscriber, api_request),
                'display_subscribed_by': 'Self-subscribed',
            },
            'subscription_level': "Lifecycle",
        }

        # Login as admin
        admin = getUtility(IPersonSet).find(ADMIN_EMAIL).any()
        with person_logged_in(admin):
            self.assertEqual(dumps([expected_result]),
                             harness.view.subscriber_data_js)
Example #11
0
    def test_data_person_subscription(self):
        # subscriber_data_js returns JSON string of a list
        # containing all subscriber information needed for
        # subscribers_list.js subscribers loading.
        bug = self._makeBugWithNoSubscribers()
        subscriber = self.factory.makePerson(name='user',
                                             displayname='Subscriber Name')
        with person_logged_in(subscriber):
            bug.subscribe(subscriber,
                          subscriber,
                          level=BugNotificationLevel.LIFECYCLE)
        harness = LaunchpadFormHarness(bug, BugPortletSubscribersWithDetails)
        api_request = IWebServiceClientRequest(harness.request)

        expected_result = {
            'subscriber': {
                'name': 'user',
                'display_name': 'Subscriber Name',
                'is_team': False,
                'can_edit': False,
                'web_link': canonical_url(subscriber),
                'self_link': absoluteURL(subscriber, api_request),
                'display_subscribed_by': 'Self-subscribed',
            },
            'subscription_level': "Lifecycle",
        }
        self.assertEqual(dumps([expected_result]),
                         harness.view.subscriber_data_js)
Example #12
0
    def test_data_team_subscription_member_looks(self):
        # For a team subscription, subscriber_data_js has can_edit
        # set to true for team member.
        bug = self._makeBugWithNoSubscribers()
        member = self.factory.makePerson()
        teamowner = self.factory.makePerson(name="team-owner",
                                            displayname="Team Owner")
        subscriber = self.factory.makeTeam(name='team',
                                           displayname='Team Name',
                                           owner=teamowner,
                                           members=[member])
        with person_logged_in(subscriber.teamowner):
            bug.subscribe(subscriber,
                          subscriber.teamowner,
                          level=BugNotificationLevel.LIFECYCLE)
        harness = LaunchpadFormHarness(bug, BugPortletSubscribersWithDetails)
        api_request = IWebServiceClientRequest(harness.request)

        expected_result = {
            'subscriber': {
                'name': 'team',
                'display_name': 'Team Name',
                'is_team': True,
                'can_edit': True,
                'web_link': canonical_url(subscriber),
                'self_link': absoluteURL(subscriber, api_request),
                'display_subscribed_by': \
                    'Subscribed by Team Owner (team-owner)',
                },
            'subscription_level': "Lifecycle",
            }
        with person_logged_in(subscriber.teamowner):
            self.assertEqual(dumps([expected_result]),
                             harness.view.subscriber_data_js)
Example #13
0
    def test_bugtask(self):
        # This view works for the bug-task as well, when it renders
        # the same data as for the bug.
        bug = self.factory.makeBug()

        # It works even for anonymous users, so no log-in is needed.
        harness_bug = LaunchpadFormHarness(bug,
                                           BugPortletSubscribersWithDetails)
        bug_content = harness_bug.view.render()

        # It works even for anonymous users, so no log-in is needed.
        harness_bugtask = LaunchpadFormHarness(
            bug.default_bugtask, BugPortletSubscribersWithDetails)
        bugtask_content = harness_bugtask.view.render()

        self.assertEqual(bug_content, bugtask_content)
Example #14
0
 def test_form_initializes(self):
     # It's a start.
     with person_logged_in(self.subscriber):
         self.product.addBugSubscription(self.subscriber, self.subscriber)
         harness = LaunchpadFormHarness(self.bug.default_bugtask,
                                        BugSubscriptionListView)
         harness.view.initialize()
Example #15
0
    def test_data_person_subscription_subscriber(self):
        # For a subscription, subscriber_data_js has can_edit
        # set to true for the subscriber.
        bug = self._makeBugWithNoSubscribers()
        subscriber = self.factory.makePerson(name='user',
                                             displayname='Subscriber Name')
        subscribed_by = self.factory.makePerson(name='someone',
                                                displayname='Someone')
        with person_logged_in(subscriber):
            bug.subscribe(subscriber,
                          subscribed_by,
                          level=BugNotificationLevel.LIFECYCLE)
        harness = LaunchpadFormHarness(bug, BugPortletSubscribersWithDetails)
        api_request = IWebServiceClientRequest(harness.request)

        expected_result = {
            'subscriber': {
                'name': 'user',
                'display_name': 'Subscriber Name',
                'is_team': False,
                'can_edit': True,
                'web_link': canonical_url(subscriber),
                'self_link': absoluteURL(subscriber, api_request),
                'display_subscribed_by': 'Subscribed by Someone (someone)',
            },
            'subscription_level': "Lifecycle",
        }
        with person_logged_in(subscribed_by):
            self.assertEqual(dumps([expected_result]),
                             harness.view.subscriber_data_js)
Example #16
0
    def test_user_can_unsubscribe(self):
        # A user can unsubscribe from a bug using the
        # BugSubscriptionSubscribeSelfView.
        bug = self.factory.makeBug()
        person = self.factory.makePerson()
        with person_logged_in(person):
            bug.subscribe(person, person)
            harness = LaunchpadFormHarness(bug.default_bugtask,
                                           BugSubscriptionSubscribeSelfView)
            form_data = {
                'field.subscription': person.name,
            }
            harness.submit('continue', form_data)

        subscription = bug.getSubscriptionForPerson(person)
        self.assertIs(None, subscription,
                      "There should be no BugSubscription for this person.")
Example #17
0
    def test_content_type(self):
        bug = self.factory.makeBug()

        # It works even for anonymous users, so no log-in is needed.
        harness = LaunchpadFormHarness(bug, BugPortletSubscribersWithDetails)
        harness.view.render()

        self.assertEqual(harness.request.response.getHeader('content-type'),
                         'application/json')
    def test_user_can_unsubscribe(self):
        # A user can unsubscribe from a bug using the
        # BugSubscriptionSubscribeSelfView.
        bug = self.factory.makeBug()
        person = self.factory.makePerson()
        with person_logged_in(person):
            bug.subscribe(person, person)
            harness = LaunchpadFormHarness(
                bug.default_bugtask, BugSubscriptionSubscribeSelfView)
            form_data = {
                'field.subscription': person.name,
                }
            harness.submit('continue', form_data)

        subscription = bug.getSubscriptionForPerson(person)
        self.assertIs(
            None, subscription,
            "There should be no BugSubscription for this person.")
Example #19
0
    def test_field_values_set_correctly_for_existing_subscriptions(self):
        # When a user who is already subscribed to a bug visits the
        # BugSubscriptionSubscribeSelfView, its bug_notification_level
        # field will be set according to their current susbscription
        # level.
        bug = self.factory.makeBug()
        person = self.factory.makePerson()
        with person_logged_in(person):
            # We subscribe using the harness rather than doing it
            # directly so that we don't have to commit() between
            # subscribing and checking the default value.
            level = BugNotificationLevel.METADATA
            harness = LaunchpadFormHarness(bug.default_bugtask,
                                           BugSubscriptionSubscribeSelfView)
            form_data = {
                'field.subscription': person.name,
                'field.bug_notification_level': level.title,
            }
            harness.submit('continue', form_data)

            # The default value for the bug_notification_level field
            # should now be the same as the level used to subscribe
            # above.
            harness = LaunchpadFormHarness(bug.default_bugtask,
                                           BugSubscriptionSubscribeSelfView)
            bug_notification_level_widget = (
                harness.view.widgets['bug_notification_level'])
            default_notification_level_value = (
                bug_notification_level_widget._getDefault())
            self.assertEqual(
                BugNotificationLevel.METADATA,
                default_notification_level_value,
                "Default value for bug_notification_level should be "
                "METADATA, is actually %s" % default_notification_level_value)
Example #20
0
    def test_data_person_subscription_user_excluded(self):
        # With the subscriber logged in, he is not included in the results.
        bug = self._makeBugWithNoSubscribers()
        subscriber = self.factory.makePerson(name='a-person',
                                             displayname='Subscriber Name')

        with person_logged_in(subscriber):
            bug.subscribe(subscriber,
                          subscriber,
                          level=BugNotificationLevel.LIFECYCLE)
            harness = LaunchpadFormHarness(bug,
                                           BugPortletSubscribersWithDetails)
            self.assertEqual(dumps([]), harness.view.subscriber_data_js)
Example #21
0
 def test_bug_notification_level_field_hidden_for_dupe_subs(self):
     # If the user is subscribed to the bug via a duplicate, the
     # bug_notification_level field won't be visible on the form.
     bug = self.factory.makeBug()
     duplicate = self.factory.makeBug()
     person = self.factory.makePerson()
     with person_logged_in(person):
         duplicate.markAsDuplicate(bug)
         duplicate.subscribe(person, person)
         harness = LaunchpadFormHarness(bug.default_bugtask,
                                        BugSubscriptionSubscribeSelfView)
         self.assertFalse(
             harness.view.widgets['bug_notification_level'].visible)
Example #22
0
 def test_update_subscription_fails_if_user_not_subscribed(self):
     # If the user is not directly subscribed to the bug, trying to
     # update the subscription will fail (since you can't update a
     # subscription that doesn't exist).
     bug = self.factory.makeBug()
     person = self.factory.makePerson()
     with person_logged_in(person):
         harness = LaunchpadFormHarness(bug.default_bugtask,
                                        BugSubscriptionSubscribeSelfView)
         subscription_field = (
             harness.view.form_fields['subscription'].field)
         # The update-subscription option won't appear.
         self.assertNotIn('update-subscription',
                          subscription_field.vocabulary.by_token)
Example #23
0
    def test_user_can_update_subscription(self):
        # A user can update their bug subscription using the
        # BugSubscriptionSubscribeSelfView.
        bug = self.factory.makeBug()
        person = self.factory.makePerson()
        with person_logged_in(person):
            bug.subscribe(person, person, BugNotificationLevel.COMMENTS)
            # Now the person updates their subscription so they're
            # subscribed at the METADATA level.
            level = BugNotificationLevel.METADATA
            harness = LaunchpadFormHarness(bug.default_bugtask,
                                           BugSubscriptionSubscribeSelfView)
            form_data = {
                'field.subscription': 'update-subscription',
                'field.bug_notification_level': level.title,
            }
            harness.submit('continue', form_data)
            self.assertFalse(harness.hasErrors())

        subscription = bug.getSubscriptionForPerson(person)
        self.assertEqual(
            BugNotificationLevel.METADATA, subscription.bug_notification_level,
            "Bug notification level of subscription should be METADATA, is "
            "actually %s." % subscription.bug_notification_level.title)
Example #24
0
 def test_update_subscription_fails_for_users_subscribed_via_teams(self):
     # If the user is not directly subscribed, but is subscribed via
     # a team, they will not be able to use the "Update my
     # subscription" option.
     bug = self.factory.makeBug()
     person = self.factory.makePerson()
     team = self.factory.makeTeam(owner=person)
     with person_logged_in(person):
         bug.subscribe(team, person)
         harness = LaunchpadFormHarness(bug.default_bugtask,
                                        BugSubscriptionSubscribeSelfView)
         subscription_field = (
             harness.view.form_fields['subscription'].field)
         # The update-subscription option won't appear.
         self.assertNotIn('update-subscription',
                          subscription_field.vocabulary.by_token)
Example #25
0
 def test_data_person_subscription_other_subscriber_query_count(self):
     # All subscriber data should be retrieved with a single query.
     bug = self._makeBugWithNoSubscribers()
     subscribed_by = self.factory.makePerson(name="someone",
                                             displayname='Someone')
     subscriber = self.factory.makePerson(name='user',
                                          displayname='Subscriber Name')
     with person_logged_in(subscriber):
         bug.subscribe(person=subscriber,
                       subscribed_by=subscribed_by,
                       level=BugNotificationLevel.LIFECYCLE)
     harness = LaunchpadFormHarness(bug, BugPortletSubscribersWithDetails)
     # Invoke the view method, ignoring the results.
     Store.of(bug).invalidate()
     with StormStatementRecorder() as recorder:
         harness.view.direct_subscriber_data(bug)
     self.assertThat(recorder, HasQueryCount(Equals(1)))
Example #26
0
    def test_bug_673288(self):
        # If the user is not directly subscribed, but is subscribed via
        # a team and via a duplicate, they will not be able to use the
        # "Update my subscription" option.
        # This is a regression test for bug 673288.
        bug = self.factory.makeBug()
        duplicate = self.factory.makeBug()
        person = self.factory.makePerson()
        team = self.factory.makeTeam(owner=person)
        with person_logged_in(person):
            duplicate.markAsDuplicate(bug)
            duplicate.subscribe(person, person)
            bug.subscribe(team, person)

            harness = LaunchpadFormHarness(bug.default_bugtask,
                                           BugSubscriptionSubscribeSelfView)
            subscription_field = (
                harness.view.form_fields['subscription'].field)
            # The update-subscription option won't appear.
            self.assertNotIn('update-subscription',
                             subscription_field.vocabulary.by_token)
Example #27
0
 def _claimToken(self, token):
     harness = LaunchpadFormHarness(token, ClaimTeamView)
     harness.submit('confirm', {})
     return [n.message for n in harness.request.notifications]
Example #28
0
 def test_data_no_subscriptions(self):
     bug = self._makeBugWithNoSubscribers()
     harness = LaunchpadFormHarness(bug, BugPortletSubscribersWithDetails)
     self.assertEqual(dumps([]), harness.view.subscriber_data_js)
 def _claimToken(self, token):
     harness = LaunchpadFormHarness(token, ClaimTeamView)
     harness.submit('confirm', {})
     return [n.message for n in harness.request.notifications]