def test_step_two_initialize(self): # Step two collects additional license, owner, and packaging info. registrant = self.factory.makePerson(name='pting') transaction.commit() login_person(registrant) form = make_product_form(action=1) view = create_initialized_view(self.product_set, '+new', form=form) owner_widget = view.view.widgets['owner'] self.assertEqual('pting', view.view.initial_values['owner']) self.assertEqual('Select the maintainer', owner_widget.header) self.assertIs(True, owner_widget.show_create_team_link) disclaim_widget = view.view.widgets['disclaim_maintainer'] self.assertEqual('subordinate', disclaim_widget.cssClass) self.assertEqual( ['displayname', 'name', 'title', 'summary', 'description', 'homepageurl', 'information_type', 'licenses', 'license_info', 'driver', 'bug_supervisor', 'owner', '__visited_steps__'], view.view.field_names) self.assertEqual( ['displayname', 'name', 'title', 'summary', 'description', 'homepageurl', 'information_type', 'licenses', 'driver', 'bug_supervisor', 'owner', 'disclaim_maintainer', 'source_package_name', 'distroseries', '__visited_steps__', 'license_info'], [f.__name__ for f in view.view.form_fields])
def test_packages_unauthorized(self): """A person with no subscription will not be able to view +packages """ login_person(self.fred) self.assertRaises( Unauthorized, create_initialized_view, self.private_ppa, "+packages")
def setUp(self): super(TestQuestionTarget_answer_contacts_with_languages, self).setUp() self.answer_contact = self.factory.makePerson() login_person(self.answer_contact) lang_set = getUtility(ILanguageSet) self.answer_contact.addLanguage(lang_set['pt_BR']) self.answer_contact.addLanguage(lang_set['en'])
def _test_teams_with_branch_review_requests(self, private=True): # Users who can see a branch can also see private teams for which # reviews have been requested. # Make the merge proposal. login_person(self.priv_owner) product = self.factory.makeProduct() if private: information_type = InformationType.USERDATA else: information_type = InformationType.PUBLIC target_branch = self.factory.makeBranch( owner=self.priv_owner, product=product, information_type=information_type) source_branch = self.factory.makeBranch( owner=self.priv_owner, product=product) self.factory.makeBranchMergeProposal( source_branch=source_branch, target_branch=target_branch, reviewer=self.priv_team, registrant=self.priv_owner) # All users can see public branches, so in that case, the team is # now visible, else team is still not visible. some_person = self.factory.makePerson() self._check_permission(some_person, not private) # Subscribe the user to the branch. login_person(self.priv_owner) self.factory.makeBranchSubscription( branch=target_branch, person=some_person, subscribed_by=self.priv_owner) # The team is now visible. self._check_permission(some_person, True)
def test_getTermByToken_match(self): # Verify the token by lookup. bug_tracker = self.factory.makeBugTracker() login_person(bug_tracker.owner) bug_tracker.name = 'mink' term = self.vocab.getTermByToken('mink') self.assertEqual(bug_tracker, term.value)
def test_PersonPickerEntrySourceAdapter_visible_email_logged_in(self): # Logged in users can see visible email addresses. observer = self.factory.makePerson() login_person(observer) person = self.factory.makePerson(email='*****@*****.**') self.assertEqual( '*****@*****.**', get_picker_entry(person, None).description)
def setUp(self): super(TestPersonSpecWorkloadView, self).setUp() self.owner = self.factory.makePerson(name='blue') login_person(self.owner) self.team = self.factory.makeTeam(name='square', owner='blue') self.member = self.factory.makePerson(name='green') self.team.addMember(self.member, self.owner)
def test_new_source_package_import(self): # Test the email for a new sourcepackage import. eric = self.factory.makePerson(name='eric') distro = self.factory.makeDistribution(name='foobuntu') series = self.factory.makeDistroSeries( name='manic', distribution=distro) fooix = self.factory.makeSourcePackage( sourcepackagename='fooix', distroseries=series) # Eric needs to be logged in for the mail to be sent. login_person(eric) code_import = self.factory.makePackageCodeImport( git_repo_url='git://git.example.com/fooix.git', branch_name='master', sourcepackage=fooix, registrant=eric) transaction.commit() msg = message_from_string(stub.test_emails[0][2]) self.assertEqual('code-import', msg['X-Launchpad-Notification-Type']) self.assertEqual( '~eric/foobuntu/manic/fooix/master', msg['X-Launchpad-Branch']) self.assertEqual( 'A new git code import has been requested ' 'by Eric:\n' ' http://code.launchpad.dev/~eric/foobuntu/manic/fooix/master\n' 'from\n' ' git://git.example.com/fooix.git\n' '\n' '-- \nYou are getting this email because you are a member of the ' 'vcs-imports team.\n', msg.get_payload(decode=True))
def setUpRegistryExpert(self): """Create a registry expert and logs in as them.""" login_person(self.admin) self.expert = self.factory.makePerson() getUtility(ILaunchpadCelebrities).registry_experts.addMember( self.expert, self.admin) login_person(self.expert)
def test_reset_resets(self): # Calling reset() on a watch resets all of the attributes of the # bug watch. admin_user = getUtility(IPersonSet).getByEmail(ADMIN_EMAIL) login_person(admin_user) self.bug_watch.reset() self._assertBugWatchHasBeenChanged()
def test_validate_passes_for_admin(self): # Users in the team that adminsters a blacklisted name may create # matching names. field = self.makeTestField() date_value = u'fnord' login_person(self.team.teamowner) self.assertEqual(None, field.validate(date_value))
def test_bug_filing_view_with_dupe_search_enabled(self): # When a user files a bug for a product where searching for # duplicate bugs is enabled, he is asked to provide a # summary of the bug. This summary is used to find possible # existing duplicates f this bug. product = self.factory.makeProduct() login_person(product.owner) product.official_malone = True product.enable_bugfiling_duplicate_search = True user = self.factory.makePerson() login_person(user) view = create_initialized_view( product, name='+filebug', principal=user) html = view.render() self.assertIsNot(None, find_tag_by_id(html, 'filebug-search-form')) # The main bug filing form is rendered but hidden inside an invisible # filebug-container. main_content = find_main_content(html) filebug_form = main_content.find(id='filebug-form') self.assertIsNot(None, filebug_form) filebug_form_container = filebug_form.findParents( id='filebug-form-container')[0] class_attrs = [item.strip() for item in filebug_form_container['class'].split(" ")] self.assertTrue('hidden' in class_attrs)
def test_product_no_duplicate_search(self): product = self.factory.makeProduct(official_malone=True) removeSecurityProxy(product).enable_bugfiling_duplicate_search = False user = self.factory.makePerson() login_person(user) view = create_initialized_view(product, '+filebug', principal=user) self._assert_cache_values(view, False)
def test_bug_filed_acknowlegdgement_notification(self): # When a user files a bug, an acknowledgement notification is added # to the response. product = self.factory.makeProduct() login_person(product.owner) create_initialized_view(product, name='+filebug') form_data = { 'title': 'A bug title', 'comment': 'whatever', } view = create_initialized_view(product, name='+filebug') view.submit_bug_action.success(form_data) self.assertEqual( ['<p class="last">Thank you for your bug report.</p>'], [notification.message for notification in view.request.response.notifications]) # This message can be customized. product.bug_reported_acknowledgement = ( u"We really appreciate your bug report") view = create_initialized_view(product, name='+filebug') view.submit_bug_action.success(form_data) self.assertEqual( [u'<p class="last">We really appreciate your bug report</p>'], [notification.message for notification in view.request.response.notifications])
def test_team_without_super_teams_is_fine(self): # A team with no members and no super teams # merges without errors. test_team = self.factory.makeTeam() target_team = self.factory.makeTeam() login_person(test_team.teamowner) self._do_merge(test_team, target_team, test_team.teamowner)
def test_user_in_private_teams(self): # Private teams are included in the vocabulary. user = self.factory.makePerson() team = self.factory.makeTeam( members=[user], visibility=PersonVisibility.PRIVATE) login_person(user) self.assertEqual([team], self._vocabTermValues())
def test_ppa_packages_menu_is_enabled(self): joe = self.factory.makePerson() ppa = self.factory.makeArchive() login_person(joe) view = create_initialized_view(ppa, "+index") menu = ArchiveNavigationMenu(view) self.assertTrue(menu.packages().enabled)
def test_user_no_private_teams(self): # Private teams are shown in the vocabulary. team_owner = self.factory.makePerson() team = self.factory.makeTeam( owner=team_owner, visibility=PersonVisibility.PRIVATE) login_person(team_owner) self.assertEqual([team_owner, team], self._vocabTermValues())
def _test_team_assigned_to_bug(self, private=True): # Users can see teams assigned to bugs. bug_owner = self.factory.makePerson() product = self.factory.makeProduct(owner=bug_owner) if private: information_type = InformationType.USERDATA else: information_type = InformationType.PUBLIC bug = self.factory.makeBug( owner=bug_owner, target=product, information_type=information_type) # Initially no visibility. some_person = self.factory.makePerson() self._check_permission(some_person, False) clear_cache() # Assign the private team to a bugtask. login_person(bug_owner) bug.default_bugtask.transitionToAssignee(self.priv_team) # All users can see public bugs, so in that case, the team is # now visible, else team is still not visible. some_person = self.factory.makePerson() self._check_permission(some_person, not private) # Subscribe the user to the bug. login_person(bug_owner) bug.subscribe(some_person, bug_owner) # The team is now visible. self._check_permission(some_person, True)
def makeCommentAndSubscriber(self, notification_level=None, body=None, as_reply=False, vote=None, vote_tag=None, subject=None): """Return a comment and a subscriber.""" sender = self.factory.makePerson( displayname='Sender', email='*****@*****.**') comment = self.factory.makeCodeReviewComment( sender, body=body, vote=vote, vote_tag=vote_tag, subject=subject) if as_reply: comment = self.factory.makeCodeReviewComment( sender, body=body, parent=comment, subject=subject) subscriber = self.factory.makePerson( displayname='Subscriber', email='*****@*****.**') if notification_level is None: notification_level = CodeReviewNotificationLevel.FULL comment.branch_merge_proposal.source_branch.subscribe( subscriber, BranchSubscriptionNotificationLevel.NOEMAIL, None, notification_level, subscriber) # Email is not sent on construction, so fake a root message id on the # merge proposal. login_person(comment.branch_merge_proposal.registrant) comment.branch_merge_proposal.root_message_id = 'fake-id' # Log our test user back in. login('*****@*****.**') return comment, subscriber
def test_query_count(self): # The function issues a constant number of queries regardless of # team count. login_person(self.user) context = self.factory.makeProduct(owner=self.user) self._setup_teams(self.user) IStore(Person).invalidate() clear_cache() with StormStatementRecorder() as recorder: expose_user_administered_teams_to_js( self.request, self.user, context, absoluteURL=fake_absoluteURL) self.assertThat(recorder, HasQueryCount(Equals(4))) # Create some new public teams owned by the user, and a private # team administered by the user. for i in range(3): self.factory.makeTeam(owner=self.user) pt = self.factory.makeTeam( visibility=PersonVisibility.PRIVATE, members=[self.user]) with person_logged_in(pt.teamowner): pt.addMember( self.user, pt.teamowner, status=TeamMembershipStatus.ADMIN) IStore(Person).invalidate() clear_cache() del IJSONRequestCache(self.request).objects['administratedTeams'] with StormStatementRecorder() as recorder: expose_user_administered_teams_to_js( self.request, self.user, context, absoluteURL=fake_absoluteURL) self.assertThat(recorder, HasQueryCount(Equals(4)))
def _test_subscriber_to_branch_subscribed_to_by_team(self, private=True): """A person with visibility to any of the branches subscribed to by the private team will be granted limited view permission on the team. """ branch_owner = self.factory.makePerson() if private: information_type = InformationType.USERDATA else: information_type = InformationType.PUBLIC private_branch = self.factory.makeBranch( owner=branch_owner, information_type=information_type) some_person = self.factory.makePerson() # Initially no visibility. self._check_permission(some_person, False) # Subscribe the team to the branch. login_person(branch_owner) self.factory.makeBranchSubscription( branch=private_branch, person=self.priv_team, subscribed_by=branch_owner) # All users can see public branches, so in that case, the team is # now visible, else team is still not visible. self._check_permission(some_person, not private) # Subscribe the user to the branch. login_person(branch_owner) self.factory.makeBranchSubscription( branch=private_branch, person=some_person, subscribed_by=branch_owner) # The team is now visible. self._check_permission(some_person, True)
def setUp(self): super(TestBugTrackerWithComponents, self).setUp() regular_user = self.factory.makePerson() login_person(regular_user) self.bug_tracker = self.factory.makeBugTracker()
def setUp(self): TestCaseWithFactory.setUp(self) self.user = self.factory.makePerson(name="macadamia") login_person(self.user) # Use a FakeLogger fixture to prevent Memcached warnings to be # printed to stdout while browsing pages. self.useFixture(FakeLogger())
def test_search_name(self): # Verify that queries match name text. bug_tracker = self.factory.makeBugTracker() login_person(bug_tracker.owner) bug_tracker.name = 'skunkworks' bug_trackers = self.searchForBugTrackers('skunk') self.assertEqual([bug_tracker], bug_trackers)
def test_join_restricted_team_error(self): # Calling join with a Restricted team raises an error. team = self.factory.makeTeam( membership_policy=TeamMembershipPolicy.RESTRICTED) user = self.factory.makePerson() login_person(user) self.assertRaises(JoinNotAllowed, user.join, team, user)
def test_search_title(self): # Verify that queries match title text. bug_tracker = self.factory.makeBugTracker() login_person(bug_tracker.owner) bug_tracker.title = 'A ferret in your pants' bug_trackers = self.searchForBugTrackers('ferret') self.assertEqual([bug_tracker], bug_trackers)
def test_search_summary(self): # Verify that queries match summary text. bug_tracker = self.factory.makeBugTracker() login_person(bug_tracker.owner) bug_tracker.summary = 'A badger is a member of the weasel family.' bug_trackers = self.searchForBugTrackers('badger') self.assertEqual([bug_tracker], bug_trackers)
def setUp(self): super(TestBugSubscriptionFilter, self).setUp() self.target = self.factory.makeProduct() self.subscriber = self.target.owner login_person(self.subscriber) self.subscription = self.target.addBugSubscription( self.subscriber, self.subscriber)
def makeBranchAndOldMergeProposal(self, timedelta): """Make an old merge proposal and a branch with the same target.""" bmp = self.factory.makeBranchMergeProposal( date_created=datetime.now(utc) - timedelta) login_person(bmp.registrant) target = bmp.target_branch return target, self.factory.makeBranchTargetBranch(target.target)
def test_add_attachment_with_bad_filename_raises_exception(self): # Test that addAttachment raises BadRequest when the filename given # contains slashes. owner = self.factory.makePerson() bug = self.factory.makeBug(owner=owner) login_person(owner) launchpad = launchpadlib_for('test', owner) lp_bug = launchpad.load(api_url(bug)) self.assertRaises(BadRequest, lp_bug.addAttachment, comment='foo', data='foo', filename='/home/foo/bar.txt')
def test_bug_supervisor_view_attributes(self): login_person(self.bug_supervisor) view = create_initialized_view( self.product, name='+configure-bugtracker') label = 'Configure bug tracker' self.assertEqual(label, view.label) fields = [ 'bugtracker', 'enable_bug_expiration', 'remote_product', 'bug_reporting_guidelines', 'bug_reported_acknowledgement', 'enable_bugfiling_duplicate_search'] self.assertEqual(fields, view.field_names) self.assertEqual('http://launchpad.dev/boing', view.next_url) self.assertEqual('http://launchpad.dev/boing', view.cancel_url)
def test_cannot_delete_watch_if_linked_to_comment(self): # It isn't possible to delete a bug watch that's linked to a bug # comment. message = getUtility(IMessageSet).fromText( "Example message", "With some example content to read.", owner=self.person) # We need to log in as an admin here as only admins can link a # watch to a comment. login(ADMIN_EMAIL) removeSecurityProxy(self.bug_watch).addComment('comment-id', message) login_person(self.person) view = create_initialized_view(self.bug_watch, '+edit') self.assertFalse(view.bugWatchIsUnlinked(None))
def test_rejectedOwnCodeReview(self): # Rejecting your own merge proposal isn't such a significant event # either, and I don't know why someone would, but hey, people are # strange. reviewer = self.factory.makePerson() target_branch = self.factory.makeProductBranch(owner=reviewer) proposal = self.factory.makeBranchMergeProposal( target_branch=target_branch, registrant=reviewer) self.karma_events = [] login_person(reviewer) with BranchMergeProposalNoPreviewDiffDelta.monitor(proposal): proposal.rejectBranch(reviewer, "A rev id.") self.assertOneKarmaEvent(reviewer, 'branchmergerejectedown')
def setUp(self): super(ProjectGroupSearchTestCase, self).setUp() self.person = self.factory.makePerson() self.project1 = self.factory.makeProject(name="zazzle", owner=self.person) self.project2 = self.factory.makeProject(name="zazzle-dazzle", owner=self.person) self.project3 = self.factory.makeProject( name="razzle-dazzle", owner=self.person, description="Giving 110% at all times.") self.projectset = getUtility(IProjectGroupSet) login_person(self.person)
def test_has_logo_without_watermark(self): root = getUtility(ILaunchpadRoot) user = self.factory.makePerson() login_person(user) view = create_initialized_view(root, 'index.html', principal=user) # Replace the blog posts so the view does not make a network request. view.getRecentBlogPosts = lambda: [] markup = BeautifulSoup( view(), parseOnlyThese=SoupStrainer(id='document')) self.assertIs(False, view.has_watermark) self.assertIs(None, markup.find(True, id='watermark')) logo = markup.find(True, id='launchpad-logo-and-name') self.assertIsNot(None, logo) self.assertEqual('/@@/launchpad-logo-and-name.png', logo['src'])
def setUp(self): super(TestArchiveSubscriptionBreadcrumb, self).setUp() # Create a private ppa self.ppa = self.factory.makeArchive() login('*****@*****.**') self.ppa.private = True owner = self.ppa.owner login_person(owner) self.ppa_subscription = self.ppa.newSubscription(owner, owner) self.ppa_token = self.ppa.newAuthToken(owner) self.personal_archive_subscription = PersonalArchiveSubscription( owner, self.ppa)
def test_uses_current_user(self): # test_traverse performs the traversal as the currently logged # in user. person = self.factory.makePerson() login_person(person) users = [] def record_user(): users.append(getUtility(ILaunchBag).user) context, view, request = test_traverse( self.registerViewCallable(record_user)) self.assertEqual(1, len(users)) self.assertEqual(person, users[0])
def test_change_information_type_public(self): owner = self.factory.makePerson(name='pting') product = self.factory.makeProduct( name='fnord', information_type=InformationType.PROPRIETARY, owner=owner) login_person(owner) form = self._make_product_edit_form(product) view = create_initialized_view(product, '+edit', form=form) self.assertEqual(0, len(view.errors)) updated_product = getUtility(IProductSet).getByName('fnord') self.assertEqual(InformationType.PUBLIC, updated_product.information_type)
def test_get_structural_subscriptions_level(self): # get_structural_subscriptions() respects the given level. subscriber = self.factory.makePerson() login_person(subscriber) product, bug = self.make_product_with_bug() subscription = product.addBugSubscription(subscriber, subscriber) filter = subscription.bug_filters.one() filter.bug_notification_level = BugNotificationLevel.METADATA self.assertContentEqual([subscription], get_structural_subscriptions( bug, BugNotificationLevel.METADATA)) self.assertContentEqual([], get_structural_subscriptions( bug, BugNotificationLevel.COMMENTS))
def test_submit_action_unauthorised(self): # An unauthorised user sees an error on the bug target page. login_person(None) view = create_initialized_view(self.bug_task, name='+nominate') self.assertEqual( canonical_url(self.bug_task), view.request.response.getHeader('Location')) notifications = view.request.notifications self.assertEqual(1, len(notifications)) self.assertEqual( BrowserNotificationLevel.ERROR, notifications[0].level) self.assertEqual( "You do not have permission to nominate this bug.", notifications[0].message)
def test_package_with_upstream_launchpad_project(self): upstream_project = self._makeBugTargetProduct(bug_tracker='launchpad', packaging=True) login_person(upstream_project.owner) bug_target = self._getBugTarget( upstream_project.distrosourcepackages[0]) view = create_initialized_view(bug_target, '+bugs', principal=upstream_project.owner) self.assertEqual(upstream_project, view.upstream_launchpad_project) self.assertEqual(upstream_project, view.upstream_project) content = find_tag_by_id(view.render(), 'also-in-upstream') link = canonical_url(upstream_project, rootsite='bugs') self.assertEqual(link, content.a['href'])
def test_workitems_text_with_implicit_and_explicit_milestone_reverse(self): spec = self.factory.makeSpecification() milestone = self.factory.makeMilestone(product=spec.product) login_person(spec.owner) work_item1 = self.factory.makeSpecificationWorkItem(specification=spec, title=u'Work item with set milestone', status=SpecificationWorkItemStatus.TODO, milestone=milestone) work_item2 = self.factory.makeSpecificationWorkItem(specification=spec, title=u'Work item with default milestone', status=SpecificationWorkItemStatus.TODO, milestone=None) items = [milestone, work_item1, self.wi_header, work_item2] self.assertWorkItemsTextContains(spec, items)
def test_traversal_to_nonexistent_bugtask(self): # Test that a traversing to a non-existent bugtask redirects to the # bug's default bugtask. bug = self.factory.makeBug() bugtask = self.factory.makeBugTask(bug=bug) bugtask_url = canonical_url(bugtask, rootsite='bugs') login_person(bugtask.owner) bugtask.delete() obj, view, request = test_traverse(bugtask_url) view() naked_view = removeSecurityProxy(view) self.assertEqual(301, request.response.getStatus()) self.assertEqual(naked_view.target, canonical_url(bug.default_bugtask, rootsite='bugs'))
def test_authenticated_view(self): # Authenticated users can see private assignees or subscribers. bug, assignee, subscriber = self._makeBug() request = LaunchpadTestRequest() bug_view = create_view(bug, name='+text', request=request) any_person = self.factory.makePerson() login_person(any_person, request) bug_view.initialize() view_text = bug_view.render() naked_subscriber = removeSecurityProxy(subscriber) self.assertIn("assignee: %s" % assignee.unique_displayname, view_text) self.assertTextMatchesExpressionIgnoreWhitespace( "subscribers:\n.*%s \(%s\)" % (naked_subscriber.displayname, naked_subscriber.name), view_text)
def test_execute_bug_id_new(self): user = self.factory.makePerson() login_person(user) message = self.factory.makeSignedMessage( body='borked\n affects fnord', subject='title borked', to_address='*****@*****.**') filealias = self.factory.makeLibraryFileAlias() command = BugEmailCommand('bug', ['new']) params, event = command.execute(message, filealias) self.assertEqual(None, event) self.assertEqual(user, params.owner) self.assertEqual('title borked', params.title) self.assertEqual(message['Message-Id'], params.msg.rfc822msgid)
def test_getBugTarget_project_group_error(self): owner = self.factory.makePerson() login_person(owner) project_group = self.factory.makeProject(name='fnord', owner=owner) project_1 = self.factory.makeProduct(name='pting', owner=owner) project_1.projectgroup = project_group project_2 = self.factory.makeProduct(name='snarf', owner=owner) project_2.projectgroup = project_group message = ( "fnord is a group of projects. To report a bug, you need to " "specify which of these projects the bug applies to: " "pting, snarf") self.assertRaisesWithContent(BugTargetNotFound, message, AffectsEmailCommand.getBugTarget, 'fnord')
def assertNotifications(self, ppa, notification, person=None): # Assert that while requesting a 'ppa' page as 'person', the # 'notification' appears. if person is not None: login_person(ppa.owner) principal = LaunchpadPrincipal(ppa.owner.account.id, ppa.owner.displayname, ppa.owner.displayname, ppa.owner) else: principal = None page = create_initialized_view(ppa, "+packages", principal=principal).render() notifications = get_feedback_messages(page) self.assertIn(notification, notifications)
def test_admin_livefs(self): # Admins can change require_virtualized. login("*****@*****.**") ppa_admin = self.factory.makePerson( member_of=[getUtility(ILaunchpadCelebrities).ppa_admin]) login_person(self.person) livefs = self.factory.makeLiveFS(registrant=self.person) self.assertTrue(livefs.require_virtualized) browser = self.getViewBrowser(livefs, user=ppa_admin) browser.getLink("Administer live filesystem").click() browser.getControl("Require virtualized builders").selected = False browser.getControl("Update live filesystem").click() login_person(self.person) self.assertFalse(livefs.require_virtualized)
def test_rejectFromInvalidStates(self): """Test that reject() cannot be called when the question status is not one of OPEN or NEEDSINFO. """ valid_statuses = [status.name for status in QuestionStatus.items if status.name != 'INVALID'] # Reject user must be an answer contact, (or admin, or product owner). # Answer contacts must speak a language self.answerer.addLanguage(getUtility(ILanguageSet)['en']) self.ubuntu.addAnswerContact(self.answerer, self.answerer) login_person(self.answerer) self._testInvalidTransition( valid_statuses, self.question.reject, self.answerer, "This is lame.", datecreated=self.nowPlus(1))
def add_bug(self, count): login_person(self.owner) for i in range(count): bug = self.factory.makeBug(target=self.ubuntu) distrosourcepackage = self.factory.makeDistributionSourcePackage( distribution=self.ubuntu) self.factory.makeSourcePackagePublishingHistory( distroseries=self.ubuntu.currentseries, sourcepackagename=distrosourcepackage.sourcepackagename) bug.bugtasks[0].transitionToTarget(distrosourcepackage, self.owner) bug.bugtasks[0].transitionToMilestone(self.milestone, self.owner) # This is necessary to test precaching of assignees. bug.bugtasks[0].transitionToAssignee(self.factory.makePerson()) logout()
def test_partner_admin_can_accept_partner_upload(self): # A person with queue admin access for partner # can accept uploads to the partner archive. login_person(self.partner_queue_admin) self.assertTrue( self.partner_archive.canAdministerQueue( self.partner_queue_admin, self.partner_spr.component)) package_upload_id = self.partner_spr.package_upload.id self.form['QUEUE_ID'] = [package_upload_id] request = LaunchpadTestRequest(form=self.form) request.method = 'POST' self.setupQueueView(request) self.assertStatus(package_upload_id, PackageUploadStatus.DONE)
def test_merge_with_duplicated_branches(self): # If both the from and to people have branches with the same name, # merging renames the duplicate from the from person's side. product = self.factory.makeProduct() from_branch = self.factory.makeBranch(name='foo', product=product) to_branch = self.factory.makeBranch(name='foo', product=product) mergee = to_branch.owner duplicate = from_branch.owner self._do_premerge(duplicate, mergee) login_person(mergee) duplicate, mergee = self._do_merge(duplicate, mergee) branches = [b.name for b in mergee.getBranches()] self.assertEqual(2, len(branches)) self.assertContentEqual([u'foo', u'foo-1'], branches)
def test_context_uses_answers(self): # If a target doesn't use answers, it doesn't provide the form. #logout() owner = removeSecurityProxy(self.question_target).owner with person_logged_in(owner): self.question_target.answers_usage = ServiceUsage.NOT_APPLICABLE login_person(self.user) view = create_initialized_view(self.question_target, name='+addquestion', principal=self.user) self.assertFalse(view.context_uses_answers) contents = view.render() msg = "<strong>does not use</strong> Launchpad as its answer forum" self.assertIn(msg, contents)
def test_execute_bug_params_many_subscriber(self): user = self.factory.makePerson() login_person(user) subscriber_1 = self.factory.makePerson() subscriber_2 = self.factory.makePerson() bug_params = CreateBugParams(title='bug title', owner=user, subscribers=[subscriber_1]) command = SubscribeEmailCommand('subscribe', [subscriber_2.name]) dummy_event = object() params, event = command.execute(bug_params, dummy_event) self.assertEqual(bug_params, params) self.assertContentEqual([subscriber_1, subscriber_2], bug_params.subscribers) self.assertEqual(dummy_event, event)
def test_execute_bug_params_with_security(self): # BugSet.createBug() requires new security bugs to be private. user = self.factory.makePerson() login_person(user) bug_params = CreateBugParams( title='bug title', owner=user, information_type=InformationType.PRIVATESECURITY) command = PrivateEmailCommand('private', ['no']) dummy_event = object() params, event = command.execute(bug_params, dummy_event) self.assertEqual(bug_params, params) self.assertEqual(InformationType.PRIVATESECURITY, bug_params.information_type) self.assertEqual(dummy_event, event)
def test_execute_bug_params_distribution(self): user = self.factory.makePerson() login_person(user) distribution = self.factory.makeDistribution(name='fnord') message = self.factory.makeMessage(subject='bug title', content='borked\n affects fnord') command = AffectsEmailCommand('affects', ['fnord']) bug_params = CreateBugParams(title='bug title', msg=message, owner=user) bugtask, bugtask_event, bug_event = command.execute(bug_params, None) self.assertEqual(distribution, bugtask.target) self.assertEqual('bug title', bugtask.bug.title) self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event)) self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
def test_retarget_with_other_changed(self): # Retargeting must be the last change made to the question # to ensure that user permission do not change while there # are more changes to make. target = self.factory.makeProduct() question = self.factory.makeQuestion(target=target) other_target = self.factory.makeProduct() login_person(target.owner) form = self.getForm(question) form['field.whiteboard'] = 'comment' form['field.target.product'] = other_target.name view = create_initialized_view(question, name='+edit', form=form) self.assertEqual([], view.errors) self.assertEqual(other_target, question.target) self.assertEqual('comment', question.whiteboard)
def assertSubscriptionMerges(self, target): # Given a subscription target, we want to make sure that subscriptions # that the duplicate person made are carried over to the merged # account. duplicate = self.factory.makePerson() with person_logged_in(duplicate): target.addSubscription(duplicate, duplicate) person = self.factory.makePerson() self._do_premerge(duplicate, person) login_person(person) duplicate, person = self._do_merge(duplicate, person) # The merged person has the subscription, and the duplicate person # does not. self.assertTrue(target.getSubscription(person) is not None) self.assertTrue(target.getSubscription(duplicate) is None)
def assert_bugtasks_query_count(self, milestone, bugtask_count, query_limit): # Assert that the number of queries run by view.bugtasks is low. self.add_bug(bugtask_count) login_person(self.owner) view = create_initialized_view(milestone, '+index') # Eliminate permission check for the admin team from the # recorded queries by loading it now. If the test ever breaks, # the person fixing it won't waste time trying to track this # query down. getUtility(ILaunchpadCelebrities).admin with StormStatementRecorder() as recorder: bugtasks = list(view.bugtasks) self.assertThat(recorder, HasQueryCount(LessThan(query_limit))) self.assertEqual(bugtask_count, len(bugtasks))