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_sequence_number_but_no_id(self):
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(Event().set_message("eventOne"),
                           timestamp=1L,
                           sequence_number=1234))
Beispiel #3
0
 def test_same_sequence_id( self ):
     expected_id = '1234'
     expected_number = 1234
     expected_delta = 1
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L, sequence_id=expected_id, sequence_number=expected_number))
    def test_same_sequence_id(self):
        expected_id = b"1234"
        expected_number = 1234
        expected_delta = 1
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        self.assertTrue(
            request.add_event(
                Event().set_message("eventOne"),
                timestamp=1,
                sequence_id=expected_id,
                sequence_number=expected_number,
            ))
        self.assertTrue(
            request.add_event(
                Event().set_message("eventTwo"),
                timestamp=2,
                sequence_id=expected_id,
                sequence_number=expected_number + expected_delta,
            ))
        self.assertEquals(request.total_events, 2)

        json = test_util.parse_scalyr_request(request.get_payload())
        event = json["events"][1]

        self.assertFalse("si" in event)
        self.assertFalse("sn" in event)
        self.assertEquals(expected_delta, event["sd"])
        request.close()
Beispiel #5
0
 def test_different_sequence_id( self ):
     first_id = '1234'
     second_id = '1235'
     first_number = 1234
     second_number = 1234
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L, sequence_id=first_id, sequence_number=first_number))
    def test_multiple_calls_to_get_payload(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)

        self.assertTrue(request.add_event(Event().set_message("eventOne"), timestamp=1))
        self.assertTrue(request.add_event(Event().set_message("eventTwo"), timestamp=2))

        self.assertEquals(request.get_payload(), request.get_payload())
        request.close()
Beispiel #7
0
 def test_exceeds_size_doesnt_effect_sequence( self ):
     first_id = '1234'
     second_id = '1235'
     first_number = 1234
     second_number = 4321
     expected_delta = 10
     request = AddEventsRequest(self.__body, max_size=180)
     request.set_client_time(1)
     self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L, sequence_id=first_id, sequence_number=first_number))
Beispiel #8
0
 def test_set_position_resets_sequence_compression( self ):
     first_id = '1234'
     second_id = '1235'
     first_number = 1234
     second_number = 4321
     expected_delta = 10
     request = AddEventsRequest(self.__body )
     request.set_client_time(1)
     self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L, sequence_id=first_id, sequence_number=first_number))
Beispiel #9
0
    def test_multiple_calls_to_get_payload(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)

        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L))

        self.assertEquals(request.get_payload(), request.get_payload())
        request.close()
    def test_maximum_bytes_exceeded(self):
        request = AddEventsRequest(self.__body, max_size=90)
        request.set_client_time(1)

        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertFalse(request.add_event({'name': 'eventTwo'}, timestamp=2L))

        self.assertEquals(request.get_payload(),
                          """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"}], client_time: 1 }""")
        request.close()
 def test_sequence_id_and_number(self):
     expected_id = '1234'
     expected_number = 1234
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(Event().set_message('eventOne'),
                           timestamp=1L,
                           sequence_id=expected_id,
                           sequence_number=expected_number))
 def test_sequence_id_and_number(self):
     expected_id = "1234"
     expected_number = 1234
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(
             Event().set_message("eventOne"), timestamp=1L, sequence_id=expected_id, sequence_number=expected_number
         )
     )
    def test_maximum_bytes_exceeded(self):
        request = AddEventsRequest(self.__body, max_size=112)
        request.set_client_time(1)

        self.assertTrue(request.add_event(Event().set_message('eventOne'), timestamp=1L))
        self.assertFalse(request.add_event(Event().set_message('eventTwo'), timestamp=2L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"}], logs: [], threads: [], client_time: 1 }""")
        request.close()
Beispiel #14
0
    def test_maximum_bytes_exceeded(self):
        request = AddEventsRequest(self.__body, max_size=103)
        request.set_client_time(1)

        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertFalse(request.add_event({'name': 'eventTwo'}, timestamp=2L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"}], threads: [], client_time: 1 }""")
        request.close()
    def test_maximum_bytes_exceeded(self):
        request = AddEventsRequest(self.__body, max_size=103)
        request.set_client_time(1)

        self.assertTrue(request.add_event(Event().set_message("eventOne"), timestamp=1L))
        self.assertFalse(request.add_event(Event().set_message("eventTwo"), timestamp=2L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"}], threads: [], client_time: 1 }""",
        )
        request.close()
Beispiel #16
0
    def test_maximum_bytes_exceeded_from_threads(self):
        request = AddEventsRequest(self.__body, max_size=100)
        request.set_client_time(1)

        self.assertTrue(request.add_thread("t1", "name1"))
        self.assertFalse(request.add_thread("t2", "name2"))

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

        request.close()
 def test_different_sequence_id(self):
     first_id = "1234"
     second_id = "1235"
     first_number = 1234
     second_number = 1234
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(
             Event().set_message("eventOne"), timestamp=1L, sequence_id=first_id, sequence_number=first_number
         )
     )
    def test_basic_case(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)

        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"},{"name":"eventTwo","ts":"2"}]"""
            """, client_time: 1 }""")
        request.close()
 def test_same_sequence_id(self):
     expected_id = "1234"
     expected_number = 1234
     expected_delta = 1
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(
             Event().set_message("eventOne"),
             timestamp=1L,
             sequence_id=expected_id,
             sequence_number=expected_number,
         ))
 def test_set_position_resets_sequence_compression(self):
     first_id = "1234"
     second_id = "1235"
     first_number = 1234
     second_number = 4321
     expected_delta = 10
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(
             Event().set_message("eventOne"), timestamp=1L, sequence_id=first_id, sequence_number=first_number
         )
     )
 def test_exceeds_size_doesnt_effect_sequence(self):
     first_id = "1234"
     second_id = "1235"
     first_number = 1234
     second_number = 4321
     expected_delta = 10
     request = AddEventsRequest(self.__body, max_size=180)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(
             Event().set_message("eventOne"), timestamp=1L, sequence_id=first_id, sequence_number=first_number
         )
     )
 def test_different_sequence_id(self):
     first_id = "1234"
     second_id = "1235"
     first_number = 1234
     second_number = 1234
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(
             Event().set_message("eventOne"),
             timestamp=1L,
             sequence_id=first_id,
             sequence_number=first_number,
         ))
    def test_basic_case(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_event(Event().set_message("eventTwo"), timestamp=2L))

        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: [], threads: [], client_time: 1 }""")
        self.assertEquals(request.total_events, 2)
        request.close()
 def test_set_position_resets_sequence_compression(self):
     first_id = "1234"
     second_id = "1235"
     first_number = 1234
     second_number = 4321
     expected_delta = 10
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(
             Event().set_message("eventOne"),
             timestamp=1L,
             sequence_id=first_id,
             sequence_number=first_number,
         ))
 def test_exceeds_size_doesnt_effect_sequence(self):
     first_id = "1234"
     second_id = "1235"
     first_number = 1234
     second_number = 4321
     expected_delta = 10
     request = AddEventsRequest(self.__body, max_size=180)
     request.set_client_time(1)
     self.assertTrue(
         request.add_event(
             Event().set_message("eventOne"),
             timestamp=1L,
             sequence_id=first_id,
             sequence_number=first_number,
         ))
Beispiel #26
0
    def test_set_position(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_event({'name': 'eventThree'}, timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{"name":"eventThree","ts":"3"}], threads: [], client_time: 1 }""")

        request.close()
    def test_set_position(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        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_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: [], threads: [], client_time: 1 }""")

        request.close()
Beispiel #28
0
    def test_basic_case(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)

        self.assertEquals(request.total_events, 0)

        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"},{"name":"eventTwo","ts":"2"}]"""
            """, threads: [], client_time: 1 }""")
        self.assertEquals(request.total_events, 2)
        request.close()
    def test_basic_case(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_event(Event().set_message("eventTwo"), timestamp=2L))

        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"}]"""
            """, threads: [], client_time: 1 }""",
        )
        self.assertEquals(request.total_events, 2)
        request.close()
    def test_set_position(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        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_event(Event().set_message("eventThree"), timestamp=3L))

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

        request.close()
    def test_sequence_number_but_no_id(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        self.assertTrue(
            request.add_event(Event().set_message("eventOne"),
                              timestamp=1,
                              sequence_number=1234))
        self.assertEquals(request.total_events, 1)

        json = test_util.parse_scalyr_request(request.get_payload())
        event = json["events"][0]

        self.assertFalse("si" in event)
        self.assertFalse("sn" in event)
        self.assertFalse("sd" in event)
        request.close()
    def test_timestamp_none(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(100)

        ts = int(time.time() * 1e9)

        self.assertTrue(
            request.add_event(Event().set_message("eventOne"), timestamp=None))

        json = test_util.parse_scalyr_request(request.get_payload())
        event = json["events"][0]
        event_ts = int(event["ts"])
        threshold = abs(event_ts - ts)

        # allow a threshold of 1 second to have elapsed between reading the time.time and
        # setting the event timestamp in add_event
        self.assertTrue(threshold < 1e9)
    def test_add_thread(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)

        self.assertEquals(request.total_events, 0)

        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertTrue(request.add_thread('t1', 'n1'))
        self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L))
        self.assertTrue(request.add_thread('t2', 'n2'))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"},{"name":"eventTwo","ts":"2"}]"""
            """, threads: [{"id":"t1","name":"n1"},{"id":"t2","name":"n2"}], client_time: 1 }""")

        self.assertEquals(request.total_events, 2)
        request.close()
    def test_add_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_thread('t1', 'n1'))
        self.assertTrue(request.add_event(Event().set_message("eventTwo"), timestamp=2L))
        self.assertTrue(request.add_thread('t2', 'n2'))

        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"}]"""
            """, 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()
Beispiel #36
0
    def test_set_position_with_thread(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        request.add_thread('log1', 'Hi there')
        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_thread('log2', 'Log two'))
        self.assertTrue(request.add_event({'name': 'eventThree'}, timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{"name":"eventThree","ts":"3"}], """
            """threads: [{"id":"log2","name":"Log two"}], 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_client_time(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(100)

        self.assertTrue(request.add_event(Event().set_message('eventOne'), timestamp=1L))
        self.assertTrue(request.add_event(Event().set_message('eventTwo'), timestamp=2L))

        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: [], threads: [], client_time: 100 }""")

        request.set_client_time(2)
        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: [], threads: [], client_time: 2 }""")
        request.close()
    def test_set_position_with_thread(self):
        scalyr_client._set_last_timestamp( 0 )
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        request.add_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_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"}], """
            """threads: [{"id":"log2","name":"Log two"}], client_time: 1 }""")

        request.close()
    def test_set_client_time(self):
        scalyr_client._set_last_timestamp( 0 )
        request = AddEventsRequest(self.__body)
        request.set_client_time(100)

        self.assertTrue(request.add_event(Event().set_message('eventOne'), timestamp=1L))
        self.assertTrue(request.add_event(Event().set_message('eventTwo'), timestamp=2L))

        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"}]"""
            """, threads: [], client_time: 100 }""")

        request.set_client_time(2)
        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"}]"""
            """, threads: [], client_time: 2 }""")
        request.close()
    def test_exceeds_size_doesnt_effect_sequence(self):
        first_id = "1234"
        second_id = "1235"
        first_number = 1234
        second_number = 4321
        expected_delta = 10
        request = AddEventsRequest(self.__body, max_size=180)
        request.set_client_time(1)
        self.assertTrue(
            request.add_event(
                Event().set_message("eventOne"),
                timestamp=1,
                sequence_id=first_id,
                sequence_number=first_number,
            )
        )
        self.assertFalse(
            request.add_event(
                Event(
                    attrs={"name": "eventTwo", "long": "some really long text"}
                ).set_message("eventTwo"),
                timestamp=2,
                sequence_id=second_id,
                sequence_number=second_number,
            )
        )
        self.assertTrue(
            request.add_event(
                Event().set_message("eventThree"),
                timestamp=3,
                sequence_id=first_id,
                sequence_number=first_number + expected_delta,
            )
        )
        self.assertEquals(request.total_events, 2)

        json = test_util.parse_scalyr_request(request.get_payload())
        event = json["events"][1]

        self.assertFalse("si" in event)
        self.assertEquals(expected_delta, event["sd"])
        self.assertFalse("sn" in event)
        request.close()
    def test_set_position_resets_sequence_compression(self):
        first_id = "1234"
        second_id = "1235"
        first_number = 1234
        second_number = 4321
        expected_delta = 10
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        self.assertTrue(
            request.add_event(
                Event().set_message("eventOne"),
                timestamp=1,
                sequence_id=first_id,
                sequence_number=first_number,
            )
        )
        position = request.position()
        self.assertTrue(
            request.add_event(
                Event().set_message("eventTwo"),
                timestamp=2,
                sequence_id=first_id,
                sequence_number=first_number + expected_delta,
            )
        )
        request.set_position(position)
        self.assertTrue(
            request.add_event(
                Event().set_message("eventThree"),
                timestamp=3,
                sequence_id=first_id,
                sequence_number=second_number,
            )
        )
        self.assertEquals(request.total_events, 2)

        json = test_util.parse_scalyr_request(request.get_payload())
        event = json["events"][1]

        self.assertEquals(second_number, event["sn"])
        self.assertFalse("sd" in event)
        request.close()
    def test_sequence_id_and_number(self):
        expected_id = "1234"
        expected_number = 1234
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        self.assertTrue(
            request.add_event(
                Event().set_message("eventOne"),
                timestamp=1,
                sequence_id=expected_id,
                sequence_number=expected_number,
            ))
        self.assertEquals(request.total_events, 1)

        json = test_util.parse_scalyr_request(request.get_payload())
        event = json["events"][0]

        self.assertEquals(expected_id, event["si"])
        self.assertEquals(expected_number, event["sn"])
        self.assertFalse("sd" in event)
        request.close()
 def test_sequence_number_but_no_id(self):
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(request.add_event(Event().set_message("eventOne"), timestamp=1L, sequence_number=1234))
 def test_sequence_number_but_no_id( self ):
     request = AddEventsRequest(self.__body)
     request.set_client_time(1)
     self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L, sequence_number=1234))