Пример #1
0
    def test_expose_user_subscriptions_to_js__uses_cached_teams(self):
        # The function expose_user_subscriptions_to_js() uses a
        # cached list of administrated teams.
        user = self.factory.makePerson()
        target = self.factory.makeProduct()
        request = LaunchpadTestRequest()
        with person_logged_in(user):
            sub = target.addBugSubscription(user, user)

        # The first call requires one query to retrieve the administrated
        # teams.
        with StormStatementRecorder() as recorder:
            expose_user_subscriptions_to_js(user, [sub], request)
        statements_for_admininstrated_teams = [
            statement for statement in recorder.statements
            if 'TeamMembership' in statement
        ]
        self.assertEqual(1, len(statements_for_admininstrated_teams))

        # Calling the function a second time does not require an
        # SQL call to retrieve the administrated teams.
        with person_logged_in(user):
            with StormStatementRecorder() as recorder:
                expose_user_subscriptions_to_js(user, [sub], request)
        statements_for_admininstrated_teams = [
            statement for statement in recorder.statements
            if 'TeamMembership' in statement
        ]
        self.assertEqual(0, len(statements_for_admininstrated_teams))
Пример #2
0
 def test_team_admin_subscription(self):
     # Make a team subscription where the user is an admin, and see what
     # we record.
     user = self.factory.makePerson()
     target = self.factory.makeProduct()
     request = LaunchpadTestRequest()
     team = self.factory.makeTeam()
     with person_logged_in(team.teamowner):
         team.addMember(user,
                        team.teamowner,
                        status=TeamMembershipStatus.ADMIN)
         sub = target.addBugSubscription(team, team.teamowner)
     expose_user_subscriptions_to_js(user, [sub], request)
     info = IJSONRequestCache(request).objects['subscription_info']
     self.assertEqual(len(info), 1)  # One target.
     target_info = info[0]
     self.assertEqual(target_info['target_title'], target.title)
     self.assertEqual(target_info['target_url'],
                      canonical_url(target, rootsite='mainsite'))
     self.assertEqual(len(target_info['filters']), 1)  # One filter.
     filter_info = target_info['filters'][0]
     self.assertEqual(filter_info['filter'], sub.bug_filters[0])
     self.assertTrue(filter_info['subscriber_is_team'])
     self.assertTrue(filter_info['user_is_team_admin'])
     self.assertTrue(filter_info['can_mute'])
     self.assertFalse(filter_info['is_muted'])
     self.assertEqual(filter_info['subscriber_title'], team.title)
     self.assertEqual(filter_info['subscriber_link'],
                      absoluteURL(team, IWebServiceClientRequest(request)))
     self.assertEqual(filter_info['subscriber_url'],
                      canonical_url(team, rootsite='mainsite'))
Пример #3
0
    def test_expose_user_subscriptions_to_js__uses_cached_teams(self):
        # The function expose_user_subscriptions_to_js() uses a
        # cached list of administrated teams.
        user = self.factory.makePerson()
        target = self.factory.makeProduct()
        request = LaunchpadTestRequest()
        with person_logged_in(user):
            sub = target.addBugSubscription(user, user)

        # The first call requires one query to retrieve the administrated
        # teams.
        with StormStatementRecorder() as recorder:
            expose_user_subscriptions_to_js(user, [sub], request)
        statements_for_admininstrated_teams = [
            statement for statement in recorder.statements
            if statement.startswith("SELECT *")]
        self.assertEqual(1, len(statements_for_admininstrated_teams))

        # Calling the function a second time does not require an
        # SQL call to retrieve the administrated teams.
        with person_logged_in(user):
            with StormStatementRecorder() as recorder:
                expose_user_subscriptions_to_js(user, [sub], request)
        statements_for_admininstrated_teams = [
            statement for statement in recorder.statements
            if statement.startswith("SELECT *")]
        self.assertEqual(0, len(statements_for_admininstrated_teams))
Пример #4
0
 def test_team_admin_subscription(self):
     # Make a team subscription where the user is an admin, and see what
     # we record.
     user = self.factory.makePerson()
     target = self.factory.makeProduct()
     request = LaunchpadTestRequest()
     team = self.factory.makeTeam()
     with person_logged_in(team.teamowner):
         team.addMember(user, team.teamowner,
                        status=TeamMembershipStatus.ADMIN)
         sub = target.addBugSubscription(team, team.teamowner)
     expose_user_subscriptions_to_js(user, [sub], request)
     info = IJSONRequestCache(request).objects['subscription_info']
     self.assertEqual(len(info), 1)  # One target.
     target_info = info[0]
     self.assertEqual(target_info['target_title'], target.title)
     self.assertEqual(
         target_info['target_url'], canonical_url(
             target, rootsite='mainsite'))
     self.assertEqual(len(target_info['filters']), 1)  # One filter.
     filter_info = target_info['filters'][0]
     self.assertEqual(filter_info['filter'], sub.bug_filters[0])
     self.assertTrue(filter_info['subscriber_is_team'])
     self.assertTrue(filter_info['user_is_team_admin'])
     self.assertTrue(filter_info['can_mute'])
     self.assertFalse(filter_info['is_muted'])
     self.assertEqual(filter_info['subscriber_title'], team.title)
     self.assertEqual(
         filter_info['subscriber_link'],
         absoluteURL(team, IWebServiceClientRequest(request)))
     self.assertEqual(
         filter_info['subscriber_url'],
         canonical_url(team, rootsite='mainsite'))
Пример #5
0
 def test_empty_expose_user_subscriptions_to_js(self):
     # This function is tested in integration more fully below, but we
     # can easily test the empty case with our stubs.
     request = FakeRequest()
     user = FakeUser()
     subscriptions = []
     expose_user_subscriptions_to_js(user, subscriptions, request)
     self.assertEqual(request.objects['subscription_info'], [])
Пример #6
0
 def test_empty_expose_user_subscriptions_to_js(self):
     # This function is tested in integration more fully below, but we
     # can easily test the empty case with our stubs.
     request = FakeRequest()
     user = FakeUser()
     subscriptions = []
     expose_user_subscriptions_to_js(user, subscriptions, request)
     self.assertEqual(request.objects['subscription_info'], [])
Пример #7
0
 def test_muted_team_member_subscription(self):
     # Show that a muted team subscription is correctly represented.
     user = self.factory.makePerson()
     target = self.factory.makeProduct()
     request = LaunchpadTestRequest()
     team = self.factory.makeTeam(members=[user])
     with person_logged_in(team.teamowner):
         sub = target.addBugSubscription(team, team.teamowner)
     sub.bug_filters.one().mute(user)
     expose_user_subscriptions_to_js(user, [sub], request)
     info = IJSONRequestCache(request).objects['subscription_info']
     filter_info = info[0]['filters'][0]
     self.assertTrue(filter_info['can_mute'])
     self.assertTrue(filter_info['is_muted'])
Пример #8
0
 def test_muted_team_member_subscription(self):
     # Show that a muted team subscription is correctly represented.
     user = self.factory.makePerson()
     target = self.factory.makeProduct()
     request = LaunchpadTestRequest()
     team = self.factory.makeTeam(members=[user])
     with person_logged_in(team.teamowner):
         sub = target.addBugSubscription(team, team.teamowner)
     sub.bug_filters.one().mute(user)
     expose_user_subscriptions_to_js(user, [sub], request)
     info = IJSONRequestCache(request).objects['subscription_info']
     filter_info = info[0]['filters'][0]
     self.assertTrue(filter_info['can_mute'])
     self.assertTrue(filter_info['is_muted'])
Пример #9
0
 def test_self_subscription(self):
     # Make a subscription directly for the user and see what we record.
     user = self.factory.makePerson()
     target = self.factory.makeProduct()
     request = LaunchpadTestRequest()
     with person_logged_in(user):
         sub = target.addBugSubscription(user, user)
     expose_user_subscriptions_to_js(user, [sub], request)
     info = IJSONRequestCache(request).objects['subscription_info']
     filter_info = info[0]['filters'][0]
     self.assertFalse(filter_info['subscriber_is_team'])
     self.assertEqual(filter_info['subscriber_title'], user.title)
     self.assertFalse(filter_info['can_mute'])
     self.assertFalse(filter_info['is_muted'])
     self.assertEqual(filter_info['subscriber_link'],
                      absoluteURL(user, IWebServiceClientRequest(request)))
     self.assertEqual(filter_info['subscriber_url'],
                      canonical_url(user, rootsite='mainsite'))
Пример #10
0
 def test_self_subscription(self):
     # Make a subscription directly for the user and see what we record.
     user = self.factory.makePerson()
     target = self.factory.makeProduct()
     request = LaunchpadTestRequest()
     with person_logged_in(user):
         sub = target.addBugSubscription(user, user)
     expose_user_subscriptions_to_js(user, [sub], request)
     info = IJSONRequestCache(request).objects['subscription_info']
     filter_info = info[0]['filters'][0]
     self.assertFalse(filter_info['subscriber_is_team'])
     self.assertEqual(filter_info['subscriber_title'], user.title)
     self.assertFalse(filter_info['can_mute'])
     self.assertFalse(filter_info['is_muted'])
     self.assertEqual(
         filter_info['subscriber_link'],
         absoluteURL(user, IWebServiceClientRequest(request)))
     self.assertEqual(
         filter_info['subscriber_url'],
         canonical_url(user, rootsite='mainsite'))
Пример #11
0
 def test_team_member_subscription(self):
     # Make a team subscription where the user is not an admin, and
     # see what we record.
     user = self.factory.makePerson()
     target = self.factory.makeProduct()
     request = LaunchpadTestRequest()
     team = self.factory.makeTeam(members=[user])
     with person_logged_in(team.teamowner):
         sub = target.addBugSubscription(team, team.teamowner)
     expose_user_subscriptions_to_js(user, [sub], request)
     info = IJSONRequestCache(request).objects['subscription_info']
     filter_info = info[0]['filters'][0]
     self.assertTrue(filter_info['subscriber_is_team'])
     self.assertFalse(filter_info['user_is_team_admin'])
     self.assertTrue(filter_info['can_mute'])
     self.assertFalse(filter_info['is_muted'])
     self.assertEqual(filter_info['subscriber_title'], team.title)
     self.assertEqual(filter_info['subscriber_link'],
                      absoluteURL(team, IWebServiceClientRequest(request)))
     self.assertEqual(filter_info['subscriber_url'],
                      canonical_url(team, rootsite='mainsite'))
Пример #12
0
 def test_team_member_subscription(self):
     # Make a team subscription where the user is not an admin, and
     # see what we record.
     user = self.factory.makePerson()
     target = self.factory.makeProduct()
     request = LaunchpadTestRequest()
     team = self.factory.makeTeam(members=[user])
     with person_logged_in(team.teamowner):
         sub = target.addBugSubscription(team, team.teamowner)
     expose_user_subscriptions_to_js(user, [sub], request)
     info = IJSONRequestCache(request).objects['subscription_info']
     filter_info = info[0]['filters'][0]
     self.assertTrue(filter_info['subscriber_is_team'])
     self.assertFalse(filter_info['user_is_team_admin'])
     self.assertTrue(filter_info['can_mute'])
     self.assertFalse(filter_info['is_muted'])
     self.assertEqual(filter_info['subscriber_title'], team.title)
     self.assertEqual(
         filter_info['subscriber_link'],
         absoluteURL(team, IWebServiceClientRequest(request)))
     self.assertEqual(
         filter_info['subscriber_url'],
         canonical_url(team, rootsite='mainsite'))