Skip to content

Commit

Permalink
Merge pull request #1682 from tseaver/logging-system_tests-log_w_meta…
Browse files Browse the repository at this point in the history
…data

Add system tests for logging w/ insert_id/severty/http_request metdata.
  • Loading branch information
tseaver committed Mar 30, 2016
2 parents 7ae4fd5 + 95f6a67 commit 451fec9
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions system_tests/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ def test_log_text(self):
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].payload, TEXT_PAYLOAD)

def test_log_text_w_metadata(self):
TEXT_PAYLOAD = 'System test: test_log_text'
INSERT_ID = 'INSERTID'
SEVERITY = 'INFO'
METHOD = 'POST'
URI = 'https://api.example.com/endpoint'
STATUS = '500'
REQUEST = {
'requestMethod': METHOD,
'requestUrl': URI,
'status': STATUS,
}
logger = Config.CLIENT.logger(self._logger_name())
self.to_delete.append(logger)
logger.log_text(TEXT_PAYLOAD, insert_id=INSERT_ID, severity=SEVERITY,
http_request=REQUEST)
time.sleep(2)
entries, _ = logger.list_entries()
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].payload, TEXT_PAYLOAD)
self.assertEqual(entries[0].insert_id, INSERT_ID)
self.assertEqual(entries[0].severity, SEVERITY)
request = entries[0].http_request
self.assertEqual(request['requestMethod'], METHOD)
self.assertEqual(request['requestUrl'], URI)
self.assertEqual(request['status'], int(STATUS))

def test_log_struct(self):
JSON_PAYLOAD = {
'message': 'System test: test_log_struct',
Expand All @@ -81,6 +108,36 @@ def test_log_struct(self):
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].payload, JSON_PAYLOAD)

def test_log_struct_w_metadata(self):
JSON_PAYLOAD = {
'message': 'System test: test_log_struct',
'weather': 'partly cloudy',
}
INSERT_ID = 'INSERTID'
SEVERITY = 'INFO'
METHOD = 'POST'
URI = 'https://api.example.com/endpoint'
STATUS = '500'
REQUEST = {
'requestMethod': METHOD,
'requestUrl': URI,
'status': STATUS,
}
logger = Config.CLIENT.logger(self._logger_name())
self.to_delete.append(logger)
logger.log_struct(JSON_PAYLOAD, insert_id=INSERT_ID, severity=SEVERITY,
http_request=REQUEST)
time.sleep(2)
entries, _ = logger.list_entries()
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].payload, JSON_PAYLOAD)
self.assertEqual(entries[0].insert_id, INSERT_ID)
self.assertEqual(entries[0].severity, SEVERITY)
request = entries[0].http_request
self.assertEqual(request['requestMethod'], METHOD)
self.assertEqual(request['requestUrl'], URI)
self.assertEqual(request['status'], int(STATUS))

def test_create_metric(self):
metric = Config.CLIENT.metric(
DEFAULT_METRIC_NAME, DEFAULT_FILTER, DEFAULT_DESCRIPTION)
Expand Down

0 comments on commit 451fec9

Please sign in to comment.