Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: client/libs/logdog/tests/streamname_test.py

Issue 2453273002: Update LogDog client library to generate URLs. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The LUCI Authors. All rights reserved. 2 # Copyright 2016 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 import os 6 import os
7 import sys 7 import sys
8 import unittest 8 import unittest
9 import StringIO 9 import StringIO
10 10
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 self.assertEqual(streamname.normalize(name, prefix='PFX'), normalized) 55 self.assertEqual(streamname.normalize(name, prefix='PFX'), normalized)
56 56
57 # Assert that an empty stream name with no prefix will raise a ValueError. 57 # Assert that an empty stream name with no prefix will raise a ValueError.
58 self.assertRaises(ValueError, streamname.normalize, '') 58 self.assertRaises(ValueError, streamname.normalize, '')
59 59
60 # Assert that a stream name with an invalid starting character and no prefix 60 # Assert that a stream name with an invalid starting character and no prefix
61 # will raise a ValueError. 61 # will raise a ValueError.
62 self.assertRaises(ValueError, streamname.normalize, '_invalid_start_char') 62 self.assertRaises(ValueError, streamname.normalize, '_invalid_start_char')
63 63
64 64
65 class StreamPathTestCase(unittest.TestCase):
66
67 def testParseValidPath(self):
68 for path in (
69 'foo/+/bar',
70 'foo/bar/+/baz',
71 ):
72 prefix, name = path.split('/+/')
73 parsed = streamname.StreamPath.parse(path)
74 self.assertEqual(
75 parsed,
76 streamname.StreamPath(prefix=prefix, name=name))
77 self.assertEqual(str(parsed), path)
78
79 def testParseInvalidValidPathRaisesValueError(self):
80 for path in (
81 '',
82 'foo/+',
83 'foo/+/',
84 '+/bar',
85 '/+/bar',
86 'foo/bar',
87 '!!!invalid!!!/+/bar',
88 'foo/+/!!!invalid!!!',
89 ):
90 with self.assertRaises(ValueError):
91 streamname.StreamPath.parse(path)
92
93 def testUrlQuote(self):
94 self.assertEqual(
95 streamname.StreamPath.make('foo', 'bar/baz').urlquote(),
96 'foo%2F%2B%2Fbar%2Fbaz')
97
98 def testLogDogViewerUrl(self):
99 for path, url in (
100 (streamname.StreamPath(prefix='foo', name='bar/baz'),
101 'https://example.appspot.com/v/?s=foo%2F%2B%2Fbar%2Fbaz'),
102
103 (streamname.StreamPath(prefix='foo', name='bar/**'),
104 'https://example.appspot.com/v/?s=foo%2F%2B%2Fbar%2F%2A%2A'),
105
106 (streamname.StreamPath(prefix='**', name='**'),
107 'https://example.appspot.com/v/?s=%2A%2A%2F%2B%2F%2A%2A'),
108 ):
109 self.assertEqual(
110 streamname.get_logdog_viewer_url('example.appspot.com', path),
111 url)
112
113 # Multiple streams.
114 self.assertEqual(
115 streamname.get_logdog_viewer_url('example.appspot.com',
116 streamname.StreamPath(prefix='foo', name='bar/baz'),
117 streamname.StreamPath(prefix='qux', name='**'),
118 ),
119 ('https://example.appspot.com/v/?s=foo%2F%2B%2Fbar%2Fbaz&'
120 's=qux%2F%2B%2F%2A%2A'))
121
122
65 if __name__ == '__main__': 123 if __name__ == '__main__':
66 unittest.main() 124 unittest.main()
OLDNEW
« client/libs/logdog/streamname.py ('K') | « client/libs/logdog/tests/stream_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698