Ejemplo n.º 1
0
    def test_unparseable_event(self, caplog, token, line):
        if token is not None:
            line = token + line

        caplog.clear()

        assert parse_line(line, token=token) is None
        assert caplog.record_tuples == [("linehaul.server", logging.ERROR, ANY)
                                        ]
        assert caplog.record_tuples[0][2].startswith("Unparseable event:")
Ejemplo n.º 2
0
    def test_returns_download_event(self):
        event = (
            "2@Fri, 20 Jul 2018 02:19:19 GMT|JP|/packages/ba/c8/"
            "a928c55457441c87366eb2423efca9aa0f46380994fd8a476153493c319a/"
            "cfn_flip-1.0.3.tar.gz|TLSv1.2|ECDHE-RSA-AES128-GCM-SHA256|"
            "cfn-flip|1.0.3|sdist|"
            "bandersnatch/2.2.1 (cpython 3.7.0-final0, Darwin x86_64)")
        line = "<134>2018-07-20T02:19:20Z cache-itm18828 linehaul[411617]: " + event

        expected = _cattr.structure(
            {
                "country_code":
                "JP",
                "details": {
                    "installer": {
                        "name": "bandersnatch",
                        "version": "2.2.1"
                    }
                },
                "file": {
                    "filename": "cfn_flip-1.0.3.tar.gz",
                    "project": "cfn-flip",
                    "type": "sdist",
                    "version": "1.0.3",
                },
                "timestamp":
                "Fri, 20 Jul 2018 02:19:19 GMT",
                "tls_cipher":
                "ECDHE-RSA-AES128-GCM-SHA256",
                "tls_protocol":
                "TLSv1.2",
                "url":
                ("/packages/ba/c8/a928c55457441c87366eb2423efca9aa0f4638099"
                 "4fd8a476153493c319a/cfn_flip-1.0.3.tar.gz"),
            },
            Download,
        )

        assert parse_line(line.encode("utf8")) == expected
Ejemplo n.º 3
0
    def test_parsing_raises(self, caplog, event, exception):
        line = "<134>2018-07-20T02:19:20Z cache-itm18828 linehaul[411617]: " + event

        assert parse_line(line.encode("utf8")) is None
        assert caplog.record_tuples == [("linehaul.server", logging.ERROR,
                                         "Unhandled error:")]
Ejemplo n.º 4
0
 def test_invalid_token_skips(self, token, line):
     assert parse_line(line, token=token) is None