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

Side by Side Diff: dashboard/dashboard/update_test_suites_test.py

Issue 2350113002: Add request-level caching for privileged queries. (Closed)
Patch Set: Fix unit tests Created 4 years, 3 months 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 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import unittest
6 6
7 import webapp2 7 import webapp2
8 import webtest 8 import webtest
9 9
10 from google.appengine.ext import ndb 10 from google.appengine.ext import ndb
(...skipping 10 matching lines...) Expand all
21 21
22 def setUp(self): 22 def setUp(self):
23 super(ListTestSuitesTest, self).setUp() 23 super(ListTestSuitesTest, self).setUp()
24 app = webapp2.WSGIApplication( 24 app = webapp2.WSGIApplication(
25 [('/update_test_suites', 25 [('/update_test_suites',
26 update_test_suites.UpdateTestSuitesHandler)]) 26 update_test_suites.UpdateTestSuitesHandler)])
27 self.testapp = webtest.TestApp(app) 27 self.testapp = webtest.TestApp(app)
28 datastore_hooks.InstallHooks() 28 datastore_hooks.InstallHooks()
29 testing_common.SetIsInternalUser('internal@chromium.org', True) 29 testing_common.SetIsInternalUser('internal@chromium.org', True)
30 self.UnsetCurrentUser() 30 self.UnsetCurrentUser()
31 self.PatchDatastoreHooksRequest()
31 32
32 def testFetchCachedTestSuites_NotEmpty(self): 33 def testFetchCachedTestSuites_NotEmpty(self):
33 # If the cache is set, then whatever's there is returned. 34 # If the cache is set, then whatever's there is returned.
34 key = update_test_suites._NamespaceKey( 35 key = update_test_suites._NamespaceKey(
35 update_test_suites._LIST_SUITES_CACHE_KEY) 36 update_test_suites._LIST_SUITES_CACHE_KEY)
36 stored_object.Set(key, {'foo': 'bar'}) 37 stored_object.Set(key, {'foo': 'bar'})
37 self.assertEqual( 38 self.assertEqual(
38 {'foo': 'bar'}, 39 {'foo': 'bar'},
39 update_test_suites.FetchCachedTestSuites()) 40 update_test_suites.FetchCachedTestSuites())
40 41
(...skipping 19 matching lines...) Expand all
60 'deeply': { 61 'deeply': {
61 'subtest': {} 62 'subtest': {}
62 } 63 }
63 }, 64 },
64 'very_very': {} 65 'very_very': {}
65 } 66 }
66 }, 67 },
67 }) 68 })
68 69
69 def testPost_ForcesCacheUpdate(self): 70 def testPost_ForcesCacheUpdate(self):
71 request = webapp2.get_request()
72 request.registry['privileged_cached'] = False
sullivan 2016/09/19 21:40:27 This seems to have been the only unit test affecte
70 key = update_test_suites._NamespaceKey( 73 key = update_test_suites._NamespaceKey(
71 update_test_suites._LIST_SUITES_CACHE_KEY) 74 update_test_suites._LIST_SUITES_CACHE_KEY)
72 stored_object.Set(key, {'foo': 'bar'}) 75 stored_object.Set(key, {'foo': 'bar'})
73 self.assertEqual( 76 self.assertEqual(
74 {'foo': 'bar'}, 77 {'foo': 'bar'},
75 update_test_suites.FetchCachedTestSuites()) 78 update_test_suites.FetchCachedTestSuites())
76 self._AddSampleData() 79 self._AddSampleData()
77 # Because there is something cached, the cache is 80 # Because there is something cached, the cache is
78 # not automatically updated when new data is added. 81 # not automatically updated when new data is added.
79 self.assertEqual( 82 self.assertEqual(
80 {'foo': 'bar'}, 83 {'foo': 'bar'},
81 update_test_suites.FetchCachedTestSuites()) 84 update_test_suites.FetchCachedTestSuites())
82 85
83 # Making a request to /udate_test_suites forces an update. 86 # Making a request to /udate_test_suites forces an update.
84 self.testapp.post('/update_test_suites') 87 self.testapp.post('/update_test_suites')
85 self.assertEqual( 88 self.assertEqual(
86 { 89 {
87 'dromaeo': { 90 'dromaeo': {
88 'mas': {'Chromium': {'mac': False, 'win7': False}}, 91 'mas': {'Chromium': {'mac': False, 'win7': False}},
89 }, 92 },
90 'scrolling': { 93 'scrolling': {
91 'mas': {'Chromium': {'mac': False, 'win7': False}}, 94 'mas': {'Chromium': {'mac': False, 'win7': False}},
92 }, 95 },
93 'really': { 96 'really': {
94 'mas': {'Chromium': {'mac': False, 'win7': False}}, 97 'mas': {'Chromium': {'mac': False, 'win7': False}},
95 }, 98 },
96 }, 99 },
97 update_test_suites.FetchCachedTestSuites()) 100 update_test_suites.FetchCachedTestSuites())
101 del request.registry['privileged_cached']
benjhayden 2016/09/19 22:14:53 Is this needed?
sullivan 2016/09/20 02:19:32 Done.
98 102
99 def testPost_InternalOnly(self): 103 def testPost_InternalOnly(self):
100 self.SetCurrentUser('internal@chromium.org') 104 self.SetCurrentUser('internal@chromium.org')
101 self._AddSampleData() 105 self._AddSampleData()
102 master_key = ndb.Key('Master', 'Chromium') 106 master_key = ndb.Key('Master', 'Chromium')
103 graph_data.Bot( 107 graph_data.Bot(
104 id='internal_mac', parent=master_key, internal_only=True).put() 108 id='internal_mac', parent=master_key, internal_only=True).put()
105 graph_data.TestMetadata( 109 graph_data.TestMetadata(
106 id='Chromium/internal_mac/internal_test', internal_only=True).put() 110 id='Chromium/internal_mac/internal_test', internal_only=True).put()
107 111
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 test.description = 'Foo.' 258 test.description = 'Foo.'
255 test.put() 259 test.put()
256 suites.append(test) 260 suites.append(test)
257 self.assertEqual( 261 self.assertEqual(
258 {'dromaeo': 'Foo.'}, 262 {'dromaeo': 'Foo.'},
259 update_test_suites._CreateSuiteDescriptionDict(suites)) 263 update_test_suites._CreateSuiteDescriptionDict(suites))
260 264
261 265
262 if __name__ == '__main__': 266 if __name__ == '__main__':
263 unittest.main() 267 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698