Exemplo n.º 1
0
 def test_disconnectionerror_view_integration(self):
     # Test setup.
     self.useFixture(Urllib2Fixture())
     bouncer = PGBouncerFixture()
     # XXX gary bug=974617, bug=1011847, bug=504291 2011-07-03:
     # In parallel tests, we are rarely encountering instances of
     # bug 504291 while running this test.  These cause the tests
     # to fail entirely (the store.rollback() described in comment
     # 11 does not fix the insane state) despite nultiple retries.
     # As mentioned in that bug, we are trying aborts to see if they
     # eliminate the problem.  If this works, we can find which of
     # these two aborts are actually needed.
     transaction.abort()
     self.useFixture(bouncer)
     transaction.abort()
     # Verify things are working initially.
     url = 'http://launchpad.dev/'
     self.retryConnection(url, bouncer)
     # Now break the database, and we get an exception, along with
     # our view.
     bouncer.stop()
     error = self.getHTTPError(url)
     self.assertEqual(503, error.code)
     self.assertThat(error.read(), Contains(DisconnectionErrorView.reason))
     # We keep seeing the correct exception on subsequent requests.
     error = self.getHTTPError(url)
     self.assertEqual(503, error.code)
     self.assertThat(error.read(), Contains(DisconnectionErrorView.reason))
     # When the database is available again, requests succeed.
     bouncer.start()
     self.retryConnection(url, bouncer)
Exemplo n.º 2
0
 def test_json_cache_not_populated_on_init(self):
     # LongPollApplicationRequestSubscriber does not put the name of the
     # new queue into the JSON cache.
     request = LaunchpadTestRequest()
     cache = IJSONRequestCache(request)
     self.assertThat(cache.objects, Not(Contains("longpoll")))
     ILongPollSubscriber(request)
     self.assertThat(cache.objects, Not(Contains("longpoll")))
Exemplo n.º 3
0
 def test_links_owner(self):
     # An owner can change details but not administer a project group.
     with person_logged_in(self.project_group.owner):
         user = getUtility(ILaunchBag).user
         view = create_initialized_view(
             self.project_group, '+index', principal=user)
         contents = view.render()
         self.assertThat(contents, Contains("Change details"))
         self.assertThat(contents, Not(Contains("Administer")))
Exemplo n.º 4
0
 def test_links_admin(self):
     # An admin can change details and administer a project group.
     with celebrity_logged_in('admin'):
         user = getUtility(ILaunchBag).user
         view = create_initialized_view(
             self.project_group, '+index', principal=user)
         contents = view.render()
         self.assertThat(contents, Contains("Change details"))
         self.assertThat(contents, Contains("Administer"))
Exemplo n.º 5
0
 def test_links_registry_expert(self):
     # A registry expert cannot change details but can administer a project
     # group.
     with celebrity_logged_in('registry_experts'):
         user = getUtility(ILaunchBag).user
         view = create_initialized_view(
             self.project_group, '+index', principal=user)
         contents = view.render()
         self.assertThat(contents, Not(Contains("Change details")))
         self.assertThat(contents, Contains("Administer"))
 def test_undocumented_scope_displayed(self):
     """The undocumented scope names are displayed on the page."""
     browser = self.getUserBrowserAsAdmin()
     # Stash away any already encountered undocumented scopes.
     saved_undocumented = undocumented_scopes.copy()
     undocumented_scopes.clear()
     undocumented_scopes.update(['first', 'second'])
     browser.open(self.getFeatureInfoUrl())
     # Put the saved undocumented scopes back.
     undocumented_scopes.clear()
     undocumented_scopes.update(saved_undocumented)
     # Are the (injected) undocumented scopes shown in the page?
     self.assertThat(browser.contents, Contains('first'))
     self.assertThat(browser.contents, Contains('second'))
Exemplo n.º 7
0
 def test_index_page(self):
     view = create_traversed_view(path_info='/+yuitest')
     view.initialize()
     output = view.render()
     self.assertThat(
         output,
         Contains('href="/+yuitest/lp/testing/tests/test_yuixhr_fixture'))
 def test_reading_undocumented_feature_flags(self):
     """Reading undocumented feature flags records them as undocumented."""
     controller = NullFeatureController()
     # This test assumes there is no flag named "does-not-exist".
     assert 'does-not-exist' not in documented_flags
     controller.getFlag('does-not-exist')
     self.assertThat(undocumented_flags, Contains('does-not-exist'))
 def test_value_domain_documentation_displayed(self):
     """The value domain documentation is displayed on the page."""
     browser = self.getUserBrowserAsAdmin()
     browser.open(self.getFeatureInfoUrl())
     for record in value_domain_info:
         for item in record:
             self.assertThat(browser.contents, Contains(item))
Exemplo n.º 10
0
 def test_run_reprocessing_script_no_params(self):
     # cronscripts/reprocess-hwdb-submissions.py needs at least the
     # parameter --start-file
     retcode, stdout, stderr = run_script(
         'cronscripts/reprocess-hwdb-submissions.py', [])
     self.assertThat(stderr, Contains('Option --start-file not specified.'))
     DatabaseLayer.force_dirty_database()
Exemplo n.º 11
0
    def test_teams_for_distro_with_no_bug_super(self):
        self._setup_teams(self.user)
        context = self.factory.makeDistribution(owner=self.user,
                                                members=self.bug_super_team)

        expose_user_administered_teams_to_js(self.request,
                                             self.user,
                                             context,
                                             absoluteURL=fake_absoluteURL)

        # The team information should have been added to the request.
        self.assertThat(self.request.objects, Contains('administratedTeams'))
        team_info = self.request.objects['administratedTeams']

        # Since the distro has no bug supervisor set, all administered teams
        # are returned.
        expected_number_teams = 3
        self.assertThat(len(team_info), Equals(expected_number_teams))
        # The items info consist of a dictionary with link and title keys.
        for i in range(expected_number_teams):
            self.assertThat(
                team_info[i],
                KeysEqual('has_preferredemail', 'link', 'title', 'url'))
        # The link is the unique display name of the team.
        self.assertThat(
            team_info[0]['title'],
            Equals(u'Bug Supervisor Sub Team (bug-supervisor-sub-team)'))
        self.assertThat(team_info[1]['title'],
                        Equals(u'Bug Supervisor Team (bug-supervisor-team)'))
        self.assertThat(team_info[2]['title'],
                        Equals(u'Unrelated Team (unrelated-team)'))
        # The link is the API link to the team.
        self.assertThat(team_info[0]['link'],
                        Equals(u'http://example.com/bug-supervisor-sub-team'))
Exemplo n.º 12
0
    def test_teams_for_distro_with_bug_super(self):
        self._setup_teams(self.user)
        context = self.factory.makeDistribution(
            owner=self.user, members=self.bug_super_team)
        with person_logged_in(self.user):
            context.bug_supervisor = self.bug_super_team

        expose_user_administered_teams_to_js(self.request, self.user, context,
            absoluteURL=fake_absoluteURL)

        # The team information should have been added to the request.
        self.assertThat(self.request.objects, Contains('administratedTeams'))
        team_info = self._sort(self.request.objects['administratedTeams'])

        # Since the distro only returns teams that are members of the bug
        # supervisor team, we only expect two.
        expected_number_teams = 2
        self.assertThat(len(team_info), Equals(expected_number_teams))
        # The items info consist of a dictionary with link and title keys.
        for i in range(expected_number_teams):
            self.assertThat(
                team_info[i],
                KeysEqual('has_preferredemail', 'link', 'title', 'url'))
        # The link is the title of the team.
        self.assertThat(
            team_info[0]['title'],
            Equals(u'\u201cBug Supervisor Sub Team\u201d team'))
        self.assertThat(
            team_info[1]['title'],
            Equals(u'\u201cBug Supervisor Team\u201d team'))
        # The link is the API link to the team.
        self.assertThat(team_info[0]['link'],
            Equals(u'http://example.com/\u201cBugSupervisorSubTeam\u201dteam'))
Exemplo n.º 13
0
    def test_teams_for_non_distro(self):
        # The expose_user_administered_teams_to_js function loads some data
        # about the teams the requesting user administers into the response to
        # be made available to JavaScript.

        context = self.factory.makeProduct(owner=self.user)
        self._setup_teams(self.user)

        expose_user_administered_teams_to_js(self.request, self.user, context,
            absoluteURL=fake_absoluteURL)

        # The team information should have been added to the request.
        self.assertThat(self.request.objects, Contains('administratedTeams'))
        team_info = self._sort(self.request.objects['administratedTeams'])
        # Since there are three teams, there should be three items in the
        # list of team info.
        expected_number_teams = 3
        self.assertThat(len(team_info), Equals(expected_number_teams))
        # The items info consist of a dictionary with link and title keys.
        for i in range(expected_number_teams):
            self.assertThat(
                team_info[i],
                KeysEqual('has_preferredemail', 'link', 'title', 'url'))
        # The link is the title of the team.
        self.assertThat(
            team_info[0]['title'],
            Equals(u'\u201cBug Supervisor Sub Team\u201d team'))
        self.assertThat(
            team_info[1]['title'],
            Equals(u'\u201cBug Supervisor Team\u201d team'))
        self.assertThat(
            team_info[2]['title'], Equals(u'\u201cUnrelated Team\u201d team'))
        # The link is the API link to the team.
        self.assertThat(team_info[0]['link'],
            Equals(u'http://example.com/\u201cBugSupervisorSubTeam\u201dteam'))
Exemplo n.º 14
0
 def test_declining_approved_is_noop(self):
     nomination = self.getNomination()
     self.assertApproves(nomination)
     self.assertThat(
         self.getNominationEditView(
             nomination,
             {'field.actions.decline': 'Decline'}).render(),
         Contains("This nomination has already been approved."))
 def test_changing_on_different_bugtasks_is_not_undoing(self):
     with lp_dbuser():
         product2 = self.factory.makeProduct(owner=self.product_owner)
         self.bug.addTask(self.product_owner, product2)
     self.change(self.old, self.new, index=0)
     self.change(self.new, self.old, index=1)
     message, body = self.get_messages().next()
     self.assertThat(body, Contains(self.unexpected_text))
Exemplo n.º 16
0
 def test_json_cache_populated_on_subscribe(self):
     # To aid with debugging the event_key of subscriptions are added to
     # the JSON cache.
     request = LaunchpadTestRequest()
     cache = IJSONRequestCache(request)
     event1 = FakeEvent()
     ILongPollSubscriber(request).subscribe(event1)  # Side-effects!
     self.assertThat(cache.objects, Contains("longpoll"))
     self.assertThat(cache.objects["longpoll"], Contains("key"))
     self.assertThat(cache.objects["longpoll"], Contains("subscriptions"))
     self.assertEqual([event1.event_key],
                      cache.objects["longpoll"]["subscriptions"])
     # More events can be subscribed.
     event2 = FakeEvent()
     ILongPollSubscriber(request).subscribe(event2)
     self.assertEqual([event1.event_key, event2.event_key],
                      cache.objects["longpoll"]["subscriptions"])
 def test_run_reprocessing_script_max_submission_not_integer(self):
     # If the parameter --max-submissions is not an integer,
     # cronscripts/reprocess-hwdb-submissions.py reports an error.
     retcode, stdout, stderr = run_script(
         'cronscripts/reprocess-hwdb-submissions.py',
         ['--max-submissions', 'nonsense'])
     expected = "Invalid value for --max_submissions specified: 'nonsense'"
     self.assertThat(stderr, Contains(expected))
     DatabaseLayer.force_dirty_database()
 def test_run_reprocessing_script_startfile_does_not_exist(self):
     # If the specified start file does not exist,
     # cronscripts/reprocess-hwdb-submissions.py reports an error.
     does_not_exist = mktemp()
     retcode, stdout, stderr = run_script(
         'cronscripts/reprocess-hwdb-submissions.py',
         ['--start-file', does_not_exist])
     self.assertThat(
         stderr, Contains('Cannot access file %s' % does_not_exist))
     DatabaseLayer.force_dirty_database()
Exemplo n.º 19
0
 def test_change_logging_note(self):
     """When submitting changes the name of the logger is shown."""
     browser = self.getUserBrowserAsAdmin()
     browser.open(self.getFeatureRulesEditURL())
     browser.getControl(name="field.feature_rules").value = (
         'beta_user some_key 10 some value with spaces')
     browser.getControl(name="field.comment").value = 'comment'
     browser.getControl(name="field.actions.change").click()
     self.assertThat(browser.contents,
                     Contains('logged by the lp.services.features logger'))
Exemplo n.º 20
0
 def test_reading_documented_feature_flags(self):
     """Reading documented flags does not record them as undocumented."""
     controller = NullFeatureController()
     # Make sure there is no flag named "documented-flag-name" before we
     # start testing.
     assert 'documented-flag-name' not in documented_flags
     documented_flags.update(['documented-flag-name'])
     controller.getFlag('documented-flag-name')
     self.assertThat(undocumented_flags,
                     Not(Contains('documented-flag-name')))
Exemplo n.º 21
0
 def test_change_message(self):
     """Submitting shows a message that the changes have been applied."""
     browser = self.getUserBrowserAsAdmin()
     browser.open(self.getFeatureRulesEditURL())
     textarea = browser.getControl(name="field.feature_rules")
     textarea.value = 'beta_user some_key 10 some value with spaces'
     browser.getControl(name="field.comment").value = 'comment'
     browser.getControl(name="field.actions.change").click()
     self.assertThat(browser.contents,
                     Contains('Your changes have been applied'))
Exemplo n.º 22
0
 def test_emit(self):
     # LongPollEvent.emit() sends the given data to `event_key`.
     event = FakeEvent("source")
     event_data = {"hello": 1234}
     with capture_longpoll_emissions() as log:
         event.emit(**event_data)
     expected_message = LongPollEventRecord(event_key=event.event_key,
                                            data=dict(
                                                event_data,
                                                event_key=event.event_key))
     self.assertThat(log, Contains(expected_message))
 def test_new_series_help(self):
     # The LP branch URL displayed to the user on the +code-summary page
     # for a product series will relate to that series instead of to the
     # default series for the Product.
     product = self.factory.makeProduct()
     series = self.factory.makeProductSeries(product=product)
     person = product.owner
     branch_url = "lp:~%s/%s/%s" % (person.name, product.name, series.name)
     with person_logged_in(person):
         self.factory.makeSSHKey(person=person)
         view = create_initialized_view(series, '+code-summary')
         self.assertThat(view(), Contains(branch_url))
Exemplo n.º 24
0
 def test_change_diff(self):
     """Submitting shows a diff of the changes."""
     browser = self.getUserBrowserAsAdmin()
     browser.open(self.getFeatureRulesEditURL())
     browser.getControl(name="field.feature_rules").value = (
         'beta_user some_key 10 some value with spaces')
     browser.getControl(name="field.comment").value = 'comment'
     browser.getControl(name="field.actions.change").click()
     browser.getControl(name="field.comment").value = 'comment'
     browser.getControl(name="field.feature_rules").value = (
         'beta_user some_key 10 another value with spaces')
     browser.getControl(name="field.actions.change").click()
     # The diff is formatted nicely using CSS.
     self.assertThat(browser.contents,
                     Contains('<td class="diff-added text">'))
     # Removed rules are displayed as being removed.
     self.assertThat(
         browser.contents.replace('\t', ' '),
         Contains('-beta_user some_key 10 some value with spaces'))
     # Added rules are displayed as being added.
     self.assertThat(
         browser.contents.replace('\t', ' '),
         Contains('+beta_user some_key 10 another value with spaces'))
 def test_run_reprocessing_script_startfile_with_negative_integer(self):
     # If the specified start file contains any non-integer string,
     # cronscripts/reprocess-hwdb-submissions.py reports an error.
     start_file_name = mktemp()
     start_file = open(start_file_name, 'w')
     start_file.write('-1')
     start_file.close()
     retcode, stdout, stderr = run_script(
         'cronscripts/reprocess-hwdb-submissions.py',
         ['--start-file', start_file_name])
     self.assertThat(
         stderr,
         Contains('%s must contain a positive integer' % start_file_name))
     DatabaseLayer.force_dirty_database()
Exemplo n.º 26
0
    def test_operationalerror_view_integration(self):
        # Test setup.
        self.useFixture(Urllib2Fixture())

        class BrokenView(object):
            """A view that raises an OperationalError"""
            def __call__(self, *args, **kw):
                raise OperationalError()

        ztapi.browserView(None, "error-test", BrokenView())

        url = 'http://launchpad.dev/error-test'
        error = self.getHTTPError(url)
        self.assertEqual(httplib.SERVICE_UNAVAILABLE, error.code)
        self.assertThat(error.read(), Contains(OperationalErrorView.reason))
Exemplo n.º 27
0
 def test_error_for_duplicate_priority(self):
     """Duplicate priority values for a flag result in a nice error."""
     browser = self.getUserBrowserAsAdmin()
     browser.open(self.getFeatureRulesEditURL())
     textarea = browser.getControl(name="field.feature_rules")
     textarea.value = dedent("""\
         key foo 10 foo
         key bar 10 bar
         """)
     browser.getControl(name="field.comment").value = 'comment'
     browser.getControl(name="field.actions.change").click()
     self.assertThat(
         browser.contents,
         Contains(
             html_escape(
                 'Invalid rule syntax: duplicate priority for flag "key": '
                 '10')))
 def test_manage_notifications_message_is_included(self):
     # Set up a subscription to a product.
     subscriber = self.factory.makePerson()
     submitter = self.factory.makePerson()
     product = self.factory.makeProduct(
         bug_supervisor=submitter)
     product.addSubscription(subscriber, subscriber)
     # Create a bug that will match the subscription.
     bug = product.createBug(CreateBugParams(
         title=self.factory.getUniqueString(),
         comment=self.factory.getUniqueString(),
         owner=submitter))
     notification = fetch_notifications(subscriber, bug).one()
     _, _, (message,) = construct_email_notifications([notification])
     payload = message.get_payload()
     self.assertThat(payload, Contains(
         'To manage notifications about this bug go to:\nhttp://'))
Exemplo n.º 29
0
 def test_mismatch_sets_expected(self):
     matcher = Contains("bar")
     mismatch = matcher.match("foo")
     self.assertEqual("bar", mismatch.expected)
Exemplo n.º 30
0
 def test_mismatch_sets_matchee(self):
     matcher = Contains("bar")
     mismatch = matcher.match("foo")
     self.assertEqual("foo", mismatch.matchee)
Exemplo n.º 31
0
 def test_mismatch_returns_does_not_start_with(self):
     matcher = Contains("bar")
     self.assertIsInstance(matcher.match("foo"), DoesNotContain)
Exemplo n.º 32
0
 def test_match(self):
     matcher = Contains("bar")
     self.assertIs(None, matcher.match("foo bar baz"))
 def test_added_another_removed_sends_emails(self):
     self.add(self.old)
     self.remove(self.new)
     message, body = self.get_messages().next()
     self.assertThat(body, Contains(self.added_message))
     self.assertThat(body, Contains(self.removed_message))
 def test_added_seen(self):
     self.add(self.old)
     message, body = self.get_messages().next()
     self.assertThat(body, Contains(self.added_message))