def test_has_batch_navigation(self): # The page has the usual batch navigation links. with person_logged_in(self.p3a_owner): view = create_initialized_view(self.private_ppa, '+subscriptions', principal=self.p3a_owner) html = view.render() has_batch_navigation = HTMLContains( Tag('batch navigation links', 'td', attrs={'class': 'batch-navigation-links'}, count=2)) self.assertThat(html, has_batch_navigation)
def test_search_macro_css_for_form_node(self): # The <form> node has the CSS classes # "primary search dynamic_bug_listing". product = self.factory.makeProduct(displayname='Test Product', official_malone=True) attributes = { 'name': 'search', 'class': 'primary search dynamic_bug_listing', } search_form_matches = Tag('Search form CSS classes', tag_type='form', attrs=attributes) view = create_initialized_view(product, '+bugs') self.assertThat(view.render(), HTMLContains(search_form_matches))
def test_search_macro_title(self): # The title text is displayed for the macro `simple-search-form`. product = self.factory.makeProduct(displayname='Test Product', official_malone=True) view = create_initialized_view(product, '+bugs') self.assertEqual('Search bugs in Test Product', view.search_macro_title) # The title is shown. form_title_matches = Tag('Search form title', 'h3', text=view.search_macro_title) view = create_initialized_view(product, '+bugs') self.assertThat(view.render(), HTMLContains(form_title_matches))
def test_multiple_info_type_errors(self): # Multiple information type errors are presented at once. product = self.factory.makeProduct() self.factory.makeBranch(product=product) self.factory.makeSpecification(product=product) browser = self.getViewBrowser(product, '+edit', user=product.owner) info_type = browser.getControl(name='field.information_type') info_type.value = ['PROPRIETARY'] browser.getControl('Change').click() tag = Tag('error', 'div', attrs={'class': 'message'}, text='Some blueprints are public. ' 'Some branches are neither proprietary nor embargoed.') self.assertThat(browser.contents, HTMLContains(tag))
def test_bug_comment_metadata(self): owner = self.factory.makePerson() login_person(owner) bug_comment = self.factory.makeBugComment() browser = self.getViewBrowser(bug_comment) iso_date = bug_comment.datecreated.isoformat() self.assertThat( browser.contents, HTMLContains(Tag( 'comment time tag', 'time', attrs=dict( itemprop='commentTime', title=True, datetime=iso_date))))
def test_search_macro_div_node_with_css_class(self): # The <div> enclosing the search form in the macro # `simple-search-form` has the CSS class "dynamic_bug_listing". product = self.factory.makeProduct(displayname='Test Product', official_malone=True) attributes = { 'id': 'bugs-search-form', 'class': 'dynamic_bug_listing', } search_div_with_class_attribute_matches = Tag('Main search div', tag_type='div', attrs=attributes) view = create_initialized_view(product, '+bugs') self.assertThat(view.render(), HTMLContains(search_div_with_class_attribute_matches))
def test_change_information_type_proprietary_packaged(self): # It should be an error to make a Product private if it is packaged. product = self.factory.makeProduct() sourcepackage = self.factory.makeSourcePackage() sourcepackage.setPackaging(product.development_focus, product.owner) browser = self.getViewBrowser(product, '+edit', user=product.owner) info_type = browser.getControl(name='field.information_type') info_type.value = ['PROPRIETARY'] old_url = browser.url browser.getControl('Change').click() self.assertEqual(old_url, browser.url) tag = Tag('error', 'div', text='Some series are packaged.', attrs={'class': 'message'}) self.assertThat(browser.contents, HTMLContains(tag))
def test_link_upstream_handles_proprietary(self): # Proprietary products produce an 'invalid value' error. owner = self.factory.makePerson() product = self.factory.makeProduct(owner=owner) product_name = product.name product_displayname = product.displayname sourcepackage = self.factory.makeSourcePackage( sourcepackagename=product_name) with person_logged_in(None): browser = self.getViewBrowser(sourcepackage, user=owner) with person_logged_in(owner): product.information_type = InformationType.PROPRIETARY browser.getControl(product_displayname).click() browser.getControl("Link to Upstream Project").click() error = Tag( 'error', 'div', attrs={'class': 'message'}, text='Invalid value') self.assertThat(browser.contents, HTMLContains(error)) self.assertNotIn( 'The project %s was linked to this source package.' % str(product_displayname), browser.contents)
def hasLink(url): return HTMLContains(Tag('link', 'a', attrs={'href': url}))
def hasAutoImport(value): tag = Tag('importall', 'input', attrs={'name': 'field.translations_autoimport_mode', 'value': value}) return HTMLContains(tag)