def test_set_log_line_attributes_with_base_attributes(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        request.add_log_and_thread("log2", "Log two", {})

        event_base = Event()
        event_base.add_attributes({
            "source": "stdout",
            "base": "base"
        },
                                  overwrite_existing=False)

        event_one = Event(base=event_base)
        event_one.set_message("eventOne")
        event_one.add_attributes({
            "source": "stdin",
            "event": "event"
        },
                                 overwrite_existing=True)

        self.assertTrue(request.add_event(event_one, timestamp=1))

        self.assertEquals(
            request.get_payload(),
            b"""{"token":"fakeToken", events: [{attrs:{"event":"event","source":"stdin",message:`s\x00\x00\x00\x08eventOne},ts:"1"}], """
            b"""logs: [{"attrs":{},"id":"log2"}], threads: [{"id":"log2","name":"Log two"}], client_time: 1 }""",
        )
        request.close()
    def test_maximum_bytes_exceeded_from_logs_and_threads(self):
        request = AddEventsRequest(self.__body, max_size=131)
        request.set_client_time(1)

        self.assertTrue(request.add_log_and_thread("t1", "name1", {}))
        self.assertFalse(request.add_log_and_thread("t2", "name2", {}))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [], logs: [{"attrs":{},"id":"t1"}], threads: [{"id":"t1","name":"name1"}], client_time: 1 }""")

        request.close()
    def test_add_log_and_thread(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)

        self.assertEquals(request.total_events, 0)

        self.assertTrue(request.add_event(Event().set_message("eventOne"), timestamp=1L))
        self.assertTrue(request.add_log_and_thread('t1', 'n1', {"l1": "L1"}))
        self.assertTrue(request.add_event(Event().set_message("eventTwo"), timestamp=2L))
        self.assertTrue(request.add_log_and_thread('t2', 'n2', {"l2": "L2"}))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"},{attrs:{message:`s\x00\x00\x00\x08eventTwo},ts:"2"}]"""
            """, logs: [{"attrs":{"l1":"L1"},"id":"t1"},{"attrs":{"l2":"L2"},"id":"t2"}], threads: [{"id":"t1","name":"n1"},{"id":"t2","name":"n2"}], client_time: 1 }""")

        self.assertEquals(request.total_events, 2)
        request.close()
    def test_set_position_with_log_and_thread(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        request.add_log_and_thread('log1', 'Hi there', {})
        self.assertTrue(request.add_event(Event().set_message('eventOne'), timestamp=1L))
        self.assertTrue(request.add_event(Event().set_message('eventTwo'), timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_log_and_thread('log2', 'Log two', {}))
        self.assertTrue(request.add_event(Event().set_message('eventThree'), timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\neventThree},ts:"3"}], """
            """logs: [{"attrs":{},"id":"log2"}], threads: [{"id":"log2","name":"Log two"}], client_time: 1 }""")

        request.close()