def test_reset_changed_custom_css(app): data = DEFAULT_DATA.copy() data['custom-css-account-header-background-color'] = '#044189' unexpected_custom_css = '.account-masthead {background: #044187}' expected_custom_css = list(DEFAULT_CUSTOM_CSS) expected_custom_css.remove(unexpected_custom_css) expected_custom_css.append('.account-masthead {background: #044189}') response = do_post(app, CUSTOM_CSS_URL, is_sysadmin=True, data=data) assert unexpected_custom_css not in response reset_response = do_post(app, RESET_CUSTOM_CSS_URL, data={}) check_custom_css_page_html(reset_response, expected_form_data=DEFAULT_DATA.copy(), expected_css_data=DEFAULT_CUSTOM_CSS)
def test_add_unsupported_link_to_custom_header(app): title = 'example' link = 'http://example.com' data = { 'new_title': title, 'new_link': link, } expected_links = [ {'position': 4, 'title': title, 'link': link}, ] expected_links.extend(DEFAULT_LINKS) expected_headers = list(DEFAULT_HEADERS) custom_header_response = do_get(app, CUSTOM_HEADER_URL, is_sysadmin=True) check_custom_header_page_html(custom_header_response, links=[], headers=expected_headers, default_layout=True) response = do_post(app, ADD_LINK_TO_HEADER_URL, data, is_sysadmin=True) expected_error_messages = [ 'Ckanext.opendata theme.custom header.data: Only HTTPS urls supported "{}"'.format(link) ] check_custom_header_page_html(response, links=expected_links, headers=expected_headers, errors=expected_error_messages)
def test_update_multiple_custom_header_links(app): data = { 'layout_type': 'default', 'link': ['/dataset/', '/organization/', '/group/', '/about'], 'position': ['3', '2', '1', '0'], 'title': ['datasets updated', 'organizations updated', 'groups updated', 'about'] } expected_links = ( {'position': 3, 'title': 'datasets updated', 'link': '/dataset/'}, {'position': 2, 'title': 'organizations updated', 'link': '/organization/'}, {'position': 1, 'title': 'groups updated', 'link': '/group/'}, {'position': 0, 'title': 'about', 'link': '/about'}, ) expected_headers = ( {'title': 'datasets updated', 'link': '/dataset/'}, {'title': 'organizations updated', 'link': '/organization/'}, {'title': 'groups updated', 'link': '/group/'}, {'title': 'about', 'link': '/about'}, ) custom_header_response = do_get(app, CUSTOM_HEADER_URL, is_sysadmin=True) check_custom_header_page_html(custom_header_response, links=[], headers=list(DEFAULT_HEADERS), default_layout=True) response = do_post(app, CUSTOM_HEADER_URL, data, is_sysadmin=True) check_custom_header_page_html(response, links=expected_links, headers=expected_headers)
def test_post_full_custom_footer_form(app): data = { 'layout_type': 4, 'content_0': 'content 1', 'content_1': 'content 2', 'content_2': 'content 3', 'content_3': 'content 4', } response = do_post(app, CUSTOM_FOOTER_URL, data, is_sysadmin=True) check_custom_footer_page_html(response, **data)
def test_reset_custom_homepage_changes(app): data = { 'custom_homepage_layout': '2', 'datasets-popular-custom-name': 'Test 1', 'datasets-recent-custom-name': 'Test 2', 'groups-custom-name': 'Test 3', 'showcase-custom-name': 'Test 4' } response = do_post(app, CUSTOM_HOMEPAGE_URL, is_sysadmin=True, data=data) assert response.status_code == 200 reset_response = do_post(app, RESET_CUSTOM_HOMEPAGE_URL, is_sysadmin=True, data={}) check_custom_homepage_html(reset_response, expected_form_data=DEFAULT_DATA.copy()) homepage_response = do_get(app, '/', is_sysadmin=False) check_homepage_html(homepage_response, expected_data=DEFAULT_HEADERS)
def test_reset_custom_footer_form_after_some_footer_modification(app): data = { 'layout_type': 4, 'content_0': 'content 1', 'content_1': 'content 2', 'content_2': 'content 3', 'content_3': 'content 4', } response = do_post(app, CUSTOM_FOOTER_URL, data, is_sysadmin=True) check_custom_footer_page_html(response, **data) reset_response = do_post(app, RESET_CUSTOM_FOOTER_URL, data={}, is_sysadmin=True) expected_data = { 'layout_type': 1, 'content_0': '', 'content_1': '', 'content_2': '', 'content_3': '', } check_custom_footer_page_html(reset_response, **expected_data)
def test_remove_link_to_custom_header(app): data = { 'to_remove': 'about', } expected_links = list(DEFAULT_LINKS) expected_links.pop(3) expected_headers = list(DEFAULT_HEADERS) expected_headers.pop(3) custom_header_response = do_get(app, CUSTOM_HEADER_URL, is_sysadmin=True) check_custom_header_page_html(custom_header_response, links=[], headers=expected_headers, default_layout=True) response = do_post(app, REMOVE_LINK_FROM_HEADER_URL, data, is_sysadmin=True) check_custom_header_page_html(response, links=expected_links, headers=expected_headers) assert 'about' not in response
def test_post_custom_css_page_with_changed_color_respond_with_contrast_connected_message( app): data = DEFAULT_DATA.copy() data['custom-css-account-header-background-color'] = '#ffffff' unexpected_custom_css = '.account-masthead {background: #ffffff}' expected_custom_css = list(DEFAULT_CUSTOM_CSS) response = do_post(app, CUSTOM_CSS_URL, is_sysadmin=True, data=data) messages = [ 'Account Header Background Color and Account Header Text Color: Contrast ratio is not high enough.' ] check_custom_css_page_html(response, expected_form_data=data, expected_css_data=expected_custom_css, errors=messages) assert unexpected_custom_css not in response
def test_update_single_custom_header_links(app): data = { 'layout_type': 'compressed', 'link': '/dataset/', 'position': '0', 'title': 'datasets updated', } expected_links = ( {'position': 0, 'title': 'datasets updated', 'link': '/dataset/'}, ) expected_headers = ( {'title': 'datasets updated', 'link': '/dataset/'}, ) custom_header_response = do_get(app, CUSTOM_HEADER_URL, is_sysadmin=True) check_custom_header_page_html(custom_header_response, links=[], headers=list(DEFAULT_HEADERS), default_layout=True) response = do_post(app, CUSTOM_HEADER_URL, data, is_sysadmin=True) check_custom_header_page_html(response, links=expected_links, headers=expected_headers, default_layout=False)
def test_post_custom_homepage_with_changes(app): data = { 'custom_homepage_layout': '2', 'datasets-popular-custom-name': 'Test 1', 'datasets-recent-custom-name': 'Test 2', 'groups-custom-name': 'Test 3', 'showcase-custom-name': 'Test 4' } response = do_post(app, CUSTOM_HOMEPAGE_URL, is_sysadmin=True, data=data) check_custom_homepage_html(response, expected_form_data=data.copy()) homepage_response = do_get(app, '/', is_sysadmin=False) expected_homepage_headers = ( 'Test 1', 'Test 2', ) check_homepage_html(homepage_response, expected_data=expected_homepage_headers)
def test_post_custom_footer_form_with_forbidden_html_tags(app): data = { 'layout_type': 4, 'content_0': '<iframe src="https://www.w3schools.com" title="Iframe></iframe>', 'content_1': '<form action="/action.php" method="get"><input type="submit" value=""></form>', 'content_2': '<script></script>', 'content_3': '<video></video>', } expected_contents = { 'layout_type': 4, 'content_0': '', 'content_1': '<form action="/action.php" method="get"><input type="submit" value=""></form>', 'content_2': '<script></script>', 'content_3': '<video></video>' } response = do_post(app, CUSTOM_FOOTER_URL, data, is_sysadmin=True) check_custom_footer_page_html(response, **expected_contents)
def test_add_link_to_custom_header(app): title = 'example' link = 'https://example.com' data = { 'new_title': title, 'new_link': link, } expected_links = [ {'position': 4, 'title': title, 'link': link}, ] expected_links.extend(DEFAULT_LINKS) expected_headers = [ {'title': title, 'link': link}, ] expected_headers.extend(DEFAULT_HEADERS) custom_header_response = do_get(app, CUSTOM_HEADER_URL, is_sysadmin=True) check_custom_header_page_html(custom_header_response, links=[], headers=DEFAULT_HEADERS, default_layout=True) response = do_post(app, ADD_LINK_TO_HEADER_URL, data, is_sysadmin=True) check_custom_header_page_html(response, links=expected_links, headers=expected_headers)