Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 57fed8a

Browse filesBrowse files
committed
Merge pull request #1609 from tseaver/logging-system_test-logger_log
Add system test for 'logger.log_text' and 'logger.log_struct'.
2 parents 466409e + d7062b0 commit 57fed8a
Copy full SHA for 57fed8a

File tree

Expand file treeCollapse file tree

2 files changed

+74
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+74
-0
lines changed

‎system_tests/logging_.py

Copy file name to clipboard
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import time
16+
17+
import unittest2
18+
19+
from gcloud import _helpers
20+
from gcloud.environment_vars import TESTS_PROJECT
21+
from gcloud import logging
22+
23+
24+
DEFAULT_LOGGER_NAME = 'system-tests-%d' % (1000 * time.time(),)
25+
26+
27+
class Config(object):
28+
"""Run-time configuration to be modified at set-up.
29+
30+
This is a mutable stand-in to allow test set-up to modify
31+
global state.
32+
"""
33+
CLIENT = None
34+
35+
36+
def setUpModule():
37+
_helpers.PROJECT = TESTS_PROJECT
38+
Config.CLIENT = logging.Client()
39+
40+
41+
class TestLogging(unittest2.TestCase):
42+
43+
def setUp(self):
44+
self.to_delete = []
45+
46+
def tearDown(self):
47+
for doomed in self.to_delete:
48+
doomed.delete()
49+
50+
def test_log_text(self):
51+
TEXT_PAYLOAD = 'System test: test_log_text'
52+
logger = Config.CLIENT.logger(DEFAULT_LOGGER_NAME)
53+
self.to_delete.append(logger)
54+
logger.log_text(TEXT_PAYLOAD)
55+
time.sleep(2)
56+
entries, _ = logger.list_entries()
57+
self.assertEqual(len(entries), 1)
58+
self.assertEqual(entries[0].payload, TEXT_PAYLOAD)
59+
60+
def test_log_struct(self):
61+
JSON_PAYLOAD = {
62+
'message': 'System test: test_log_struct',
63+
'weather': 'partly cloudy',
64+
}
65+
logger = Config.CLIENT.logger(DEFAULT_LOGGER_NAME)
66+
self.to_delete.append(logger)
67+
logger.log_struct(JSON_PAYLOAD)
68+
time.sleep(2)
69+
entries, _ = logger.list_entries()
70+
self.assertEqual(len(entries), 1)
71+
self.assertEqual(entries[0].payload, JSON_PAYLOAD)

‎system_tests/run_system_test.py

Copy file name to clipboardExpand all lines: system_tests/run_system_test.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import bigtable
2323
import bigtable_happybase
2424
import datastore
25+
import logging_
2526
import pubsub
2627
import storage
2728
import system_test_utils
@@ -34,6 +35,7 @@
3435
'bigquery': ['project', 'credentials'],
3536
'bigtable': ['project', 'credentials'],
3637
'bigtable-happybase': ['project', 'credentials'],
38+
'logging': ['project', 'credentials'],
3739
}
3840
TEST_MODULES = {
3941
'datastore': datastore,
@@ -42,6 +44,7 @@
4244
'bigquery': bigquery,
4345
'bigtable': bigtable,
4446
'bigtable-happybase': bigtable_happybase,
47+
'logging': logging_,
4548
}
4649

4750

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.