Пример #1
0
 def test_it_returns_false_and_logs_error_if_the_blacklist_does_not_exist(
     self, mock_open, caplog
 ):
     mock_open.side_effect = FileNotFoundError
     caplog.set_level(logging.DEBUG)
     assert on_blacklist("") is False
     assert f"Could not read blacklist file {os.getcwd()}/.urlignore" in caplog.text
Пример #2
0
    def from_requests(cls, requests: Iterable[Request]) -> Iterator["Task"]:
        """
        Generates a set of Tasks from a given set of Requests.
        """

        for req in sorted(requests, key=lambda r: r.timestamp):
            if on_blacklist(req.url.netloc):
                continue
            else:
                yield cls(name=req.task_name(), request=req)
Пример #3
0
 def from_requests(cls, requests: Iterable[Request]) -> Iterator["Task2"]:
     """
     Generates a set of tasks from a given set of HTTP requests.
     Each request will be turned into an unevaluated function call making
     the actual request.
     The returned tasks are ordered by increasing timestamp of the
     corresponding request.
     """
     # TODO: Update me when merging Task with Task2: "statements" needs to
     #   contain the equivalent of LocustRequest.
     #   See https://github.com/zalando-incubator/Transformer/issues/11.
     for req in sorted(requests, key=lambda r: r.timestamp):
         if not on_blacklist(req.url.netloc):
             yield cls(name=req.task_name(), request=req, statements=...)
Пример #4
0
    def from_requests(
            cls,
            requests: Iterable[Request],
            blacklist: Optional[Blacklist] = None) -> Iterator["Task"]:
        """
        Generates a set of Tasks from a given set of Requests.
        """
        if blacklist is None:
            blacklist = get_empty()

        for req in sorted(requests, key=lambda r: r.timestamp):
            if on_blacklist(blacklist, req.url.netloc):
                continue
            else:
                yield cls(name=req.task_name(), request=req)
Пример #5
0
    def from_requests(cls, requests: Iterable[Request]) -> Iterator["Task2"]:
        """
        Generates a set of tasks from a given set of HTTP requests.

        Each request will be turned into an unevaluated function call
        (:class:`transformer.python.FunctionCall`)
        making the actual request.

        The returned tasks are ordered by increasing :any:`timestamp
        <transformer.request.Request.timestamp>` of the corresponding request.
        """
        # TODO: Update me when merging Task with Task2: "statements" needs to
        #   contain a ExpressionView to Task2.request.
        #   See what is done in from_task (but without the LocustRequest part).
        #   See https://github.com/zalando-incubator/Transformer/issues/11.
        for req in sorted(requests, key=lambda r: r.timestamp):
            if not on_blacklist(req.url.netloc):
                yield cls(name=req.task_name(), request=req, statements=...)
Пример #6
0
 def test_it_ignores_empty_lines(self, mock_open):
     mock_open.return_value = io.StringIO("\nwww.amazon.com")
     assert on_blacklist("www.zalando.de") is False
Пример #7
0
 def test_it_returns_true_if_a_partial_match_is_found(self, mock_open):
     mock_open.return_value = io.StringIO("www.amazon.com")
     assert on_blacklist("http://www.amazon.com/") is True
Пример #8
0
 def test_it_returns_true_if_url_is_on_blacklist(self, mock_open):
     mock_open.return_value = io.StringIO("www.google.com\nwww.amazon.com")
     assert on_blacklist("www.amazon.com") is True
Пример #9
0
 def test_it_returns_false_if_url_is_not_on_blacklist(self, mock_open):
     mock_open.return_value = io.StringIO("www.amazon.com")
     assert on_blacklist("www.zalando.de") is False
Пример #10
0
 def test_it_returns_false_if_the_blacklist_is_empty(self, mock_open):
     mock_open.return_value = io.StringIO("")
     assert on_blacklist("") is False
Пример #11
0
 def test_it_ignores_whitespace_only_lines(self, mock_open):
     mock_open.return_value = io.StringIO(" \n   \r\nwww.amazon.com")
     assert on_blacklist(read_blacklist(), "www.zalando.de") is False