Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_includes_list_of_filtered_tags():
html_soup = get_html_soup(
req_url=hyperlink.URL.from_text("http://localhost:1234/?tag=alfa&tag=bravo"),
tag_query=["alfa", "bravo"]
)
alert_div = html_soup.find("div", attrs={"class": ["alert", "tag_query"]})
actual_text = re.sub(r"\s+", " ", alert_div.text.strip())
expected_text = "Filtering to documents tagged with alfa x bravo x"
assert actual_text == expected_text
links = {
a_tag.attrs["id"].split(":")[1]: a_tag.attrs["href"]
for a_tag in alert_div.find_all("a")
}
assert links == {
def test_next_page_link(self, req_url, expected_url):
html_soup = get_html_soup(
pagination=Pagination(
page_size=25,
current_page=4,
total_documents=200
),
req_url=hyperlink.URL.from_text(req_url)
)
pagination_div = html_soup.find("nav", attrs={"id": "pagination"})
next_li = pagination_div.find("li", attrs={"id": "pagination__next"})
assert next_li.find("a").attrs["href"] == expected_url
def test_prev_page_link_on_page_1(self, req_url, expected_url):
html_soup = get_html_soup(
pagination=Pagination(
page_size=25,
current_page=2,
total_documents=50
),
req_url=hyperlink.URL.from_text(req_url)
)
pagination_div = html_soup.find("nav", attrs={"id": "pagination"})
prev_li = pagination_div.find("li", attrs={"id": "pagination__prev"})
assert prev_li.find("a").attrs["href"] == expected_url
def assert_query_param_equal(query1, query2):
assert (
sorted(hyperlink.URL.from_text(query1).query) ==
sorted(hyperlink.URL.from_text(query2).query)
)
def test_removes_page_pagesize_in_document_tags(self, document):
document["tags"] = ["alfa", "bravo"]
html_soup = get_html_soup(
documents=[(1, document)],
req_url=hyperlink.URL.from_text("http://localhost:1234?page=4")
)
document_tags = html_soup.find(
"div", attrs={"class": "document__metadata__tags"})
links = [a_tag.attrs["href"] for a_tag in document_tags.find_all("a")]
assert links == [
"?tag=alfa",
"?tag=bravo",
]
def test_can_render_tag_counter(tag_counter): # pragma: no cover
req_url = hyperlink.URL.from_text("http://localhost:1234/")
html = render_tags(req_url=req_url, tag_counter=tag_counter)
assert html.count("<ul>") == html.count("</ul>")
assert html.count("<li>") == html.count("</li>")
assert html.count("<a>")
assert html.count("<span span="">")
</span></a>
def test_preserves_other_query_params_setting_sort_option(self):
html_soup = get_html_soup(
req_url=hyperlink.URL.from_text(
"http://localhost:1234?tag=x&tag=y"
)
)
expected = {
"title (a-z)": "?tag=x&tag=y&sort=title:a_z",
"title (z-a)": "?tag=x&tag=y&sort=title:z_a",
"date created (newest first)": "?tag=x&tag=y&sort=date_created:newest_first",
"date created (oldest first)": "?tag=x&tag=y&sort=date_created:oldest_first",
}
for label, url in self.get_sort_options(html_soup).items():
self.assert_query_param_equal(url, expected[label])
def path_from_url(url):
url = str(url)
return "/" + "/".join(URL.from_text(url).path)
def _reconstitute(self):
"""
Reconstitute this L{URLPath} from all its given attributes.
"""
urltext = urlquote(
urlparse.urlunsplit((self._scheme, self._netloc,
self._path, self._query, self._fragment)),
safe=_allascii
)
self._url = _URL.fromText(urltext.encode("ascii").decode("ascii"))
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
import re
import datetime
from boltons.iterutils import unique
from hyperlink import parse as parse_url
import requests
MW_API_URL = parse_url('https://en.wikipedia.org/w/api.php')
REST_API_BASE_URL = parse_url('https://en.wikipedia.org/api/rest_v1/')
REF_API_BASE_URL = REST_API_BASE_URL.child('page', 'references')
from log import tlog
def format_datetime(dt):
if isinstance(dt, datetime.date):
dt = datetime.datetime(dt.year, dt.month, dt.day, 0, 0, 0)
return dt.isoformat().split('.')[0] + 'Z'
## PTArticle-based Metrics
def get_revid(pta):