Beispiel #1
0
    def do_json(self):
        """Return json log with appropriate headers."""
        self.send_response(HTTPStatus.OK)
        self.send_header("Content-type", "application/json")
        self.end_headers()

        with open(LOG_FILE, "rb") as file:
            write_json_output(file, self.wfile)
Beispiel #2
0
def test_empty_logfile(empty_log_file, output_stream):
    """Test empty logs."""
    with open(empty_log_file.name, "rb") as file:
        write_json_output(file, output_stream)

    try:
        json_log = json.loads(output_stream.getvalue())
    except ValueError:
        assert False, "Invalid json generated."
    else:
        assert not json_log
Beispiel #3
0
def test_single_logfile(single_log_file, output_stream):
    """Test with single log."""
    with open(single_log_file.name, "rb") as file:
        write_json_output(file, output_stream)

    try:
        json_log = json.loads(output_stream.getvalue())
    except ValueError:
        assert False, "Invalid json generated."
    else:
        assert len(json_log) == 1
        assert json_log[0]["from"] == "*****@*****.**"
Beispiel #4
0
def test_logfile(log_file, output_stream):
    """Test log file happy path with 2 logs."""
    with open(log_file.name, "rb") as file:
        write_json_output(file, output_stream)

    try:
        json_log = json.loads(output_stream.getvalue())
    except ValueError:
        assert False, "Invalid json generated."
    else:
        assert len(json_log) == 2
        assert json_log[0]["from"] == "*****@*****.**"
        assert json_log[1]["from"] == "*****@*****.**"
Beispiel #5
0
def test_logfile_log_entries_on_same_line(log_on_same_line, output_stream):
    """Test with single log."""
    with open(log_on_same_line.name, "rb") as file:
        write_json_output(file, output_stream)

    try:
        json_log = json.loads(output_stream.getvalue())
    except ValueError:
        assert False, "Invalid json generated."
    else:
        assert len(json_log) == 3
        assert json_log[0]["message"] == 1
        assert json_log[1]["message"] == 2
        assert json_log[2]["message"] == 3