def test_mutate_closed_entity(): segment = Segment('seg') segment.close() with pytest.raises(AlreadyEndedException): segment.put_annotation('key', 'value') with pytest.raises(AlreadyEndedException): segment.put_metadata('key', 'value') with pytest.raises(AlreadyEndedException): segment.put_http_meta('url', 'my url') with pytest.raises(AlreadyEndedException): segment.close()
def test_put_http_meta(): segment = Segment('seg') segment.put_http_meta(http.URL, 'my url') segment.put_http_meta(http.STATUS, 200) # unsupported key should be dropped segment.put_http_meta('somekey', 'somevalue') doc = entity_to_dict(segment) assert doc['http']['request'][http.URL] == 'my url' assert doc['http']['response'][http.STATUS] == 200 assert 'somekey' not in doc
def test_serialize_segment_with_http(): segment = Segment('test') segment.put_http_meta(http.URL, 'https://aws.amazon.com') segment.put_http_meta(http.METHOD, 'get') segment.put_http_meta(http.USER_AGENT, 'test') segment.put_http_meta(http.CLIENT_IP, '127.0.0.1') segment.put_http_meta(http.X_FORWARDED_FOR, True) segment.put_http_meta(http.STATUS, 200) segment.put_http_meta(http.CONTENT_LENGTH, 0) segment.close() expected_segment_dict = { "id": segment.id, "name": "test", "start_time": segment.start_time, "in_progress": False, "http": { "request": { "url": "https://aws.amazon.com", "method": "get", "user_agent": "test", "client_ip": "127.0.0.1", "x_forwarded_for": True }, "response": { "status": 200, "content_length": 0 } }, "trace_id": segment.trace_id, "end_time": segment.end_time } actual_segment_dict = entity_to_dict(segment) assert expected_segment_dict == actual_segment_dict