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

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

Issue 2622303003: Allows a user to create_health_reports. (Closed)
Patch Set: added check that table name was unique Created 3 years, 11 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
« no previous file with comments | « dashboard/dashboard/create_health_report.py ('k') | dashboard/dashboard/dispatcher.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import webapp2
6 import webtest
7
8 from google.appengine.ext import ndb
9 from google.appengine.api import users
10
11 from dashboard import create_health_report
12 from dashboard.common import testing_common
13 from dashboard.common import xsrf
14 from dashboard.models import table_config
15 from dashboard.models import graph_data
16
17
18 # Sample table config that contains all the required fields.
19 _SAMPLE_TABLE_CONFIG = {
20 'tableName': 'my_sample_config',
21 'tableBots': 'ChromiumPerf/win\nChromiumPerf/linux',
22 'tableTests': 'my_test_suite/my_test\nmy_test_suite/my_other_test',
23 'tableLayout': '{ "system_health.memory_mobile/foreground/ashmem":'
24 '["Foreground", "Ashmem"]}',
25 }
26
27 class CreateHealthReportTest(testing_common.TestCase):
28
29 def setUp(self):
30 super(CreateHealthReportTest, self).setUp()
31 app = webapp2.WSGIApplication([(
32 '/create_health_report',
33 create_health_report.CreateHealthReportHandler)])
34 self.testapp = webtest.TestApp(app)
35 testing_common.SetSheriffDomains(['chromium.org'])
36 testing_common.SetIsInternalUser('internal@chromium.org', True)
37 self.SetCurrentUser('internal@chromium.org', is_admin=True)
38
39 def tearDown(self):
40 super(CreateHealthReportTest, self).tearDown()
41 self.UnsetCurrentUser()
42
43 def _AddInternalBotsToDataStore(self):
44 """Adds sample bot/master pairs."""
45 master_key = ndb.Key('Master', 'ChromiumPerf')
46 graph_data.Bot(
47 id='win', parent=master_key, internal_only=True).put()
48 graph_data.Bot(
49 id='linux', parent=master_key, internal_only=True).put()
50
51 def _AddMixedBotsToDataStore(self):
52 """Adds sample bot/master pairs."""
53 master_key = ndb.Key('Master', 'ChromiumPerf')
54 graph_data.Bot(
55 id='win', parent=master_key, internal_only=False).put()
56 graph_data.Bot(
57 id='linux', parent=master_key, internal_only=True).put()
58
59 def _AddPublicBotsToDataStore(self):
60 """Adds sample bot/master pairs."""
61 master_key = ndb.Key('Master', 'ChromiumPerf')
62 graph_data.Bot(
63 id='win', parent=master_key, internal_only=False).put()
64 graph_data.Bot(
65 id='linux', parent=master_key, internal_only=False).put()
66
67 def testPost_NoXSRFToken_Returns403Error(self):
68 self.testapp.post('/create_health_report', {
69 }, status=403)
sullivan 2017/01/13 22:48:56 Please also check nothing got added to the datasto
70
71 def testPost_GetXsrfToken(self):
72 response = self.testapp.post('/create_health_report', {
73 'getToken': 'true',
74 })
75 self.assertIn(xsrf.GenerateToken(users.get_current_user()), response)
76
77 def testGet_ShowPage(self):
78 response = self.testapp.get('/create_health_report')
79 self.assertIn('create-health-report-page', response)
80
81 def testPost_ExternalUserReturnsNotLoggedIn(self):
82 self.UnsetCurrentUser()
83 response = self.testapp.post('/create_health_report', {})
84 self.assertIn('User not logged in.', response)
85
86 def testPost_ValidData(self):
87 self._AddInternalBotsToDataStore()
88 _SAMPLE_TABLE_CONFIG['xsrf_token'] = xsrf.GenerateToken(
89 users.get_current_user())
90 response = self.testapp.post('/create_health_report',
91 _SAMPLE_TABLE_CONFIG)
92 self.assertIn('my_sample_config', response)
93 table_entity = ndb.Key('TableConfig', 'my_sample_config').get()
94 self.assertTrue(table_entity.internal_only)
95 self.assertEqual('internal@chromium.org', table_entity.username)
96 self.assertEqual(
97 ['my_test_suite/my_test', 'my_test_suite/my_other_test'],
98 table_entity.tests)
99 master_key = ndb.Key('Master', 'ChromiumPerf')
100 win_bot = graph_data.Bot(
101 id='win', parent=master_key, internal_only=False).key
102 linux_bot = graph_data.Bot(
103 id='linux', parent=master_key, internal_only=False).key
104 bots = [win_bot, linux_bot]
105 self.assertEqual(bots, table_entity.bots)
106 self.assertEqual(
107 '{ "system_health.memory_mobile/foreground/ashmem":'
108 '["Foreground", "Ashmem"]}', table_entity.table_layout)
109
110 def testPost_EmptyForm(self):
111 response = self.testapp.post('/create_health_report', {
112 'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
113 })
114 self.assertIn('Please fill out the form entirely.', response)
115 query = table_config.TableConfig.query()
116 table_values = query.fetch()
117 self.assertEqual(len(table_values), 0)
118
119 def testPost_TwoPostsSameNameReturnsError(self):
120 self._AddInternalBotsToDataStore()
121 _SAMPLE_TABLE_CONFIG['xsrf_token'] = xsrf.GenerateToken(
122 users.get_current_user())
123 self.testapp.post('/create_health_report',
124 _SAMPLE_TABLE_CONFIG)
125 response = self.testapp.post('/create_health_report',
126 _SAMPLE_TABLE_CONFIG)
127 self.assertIn('my_sample_config already exists.', response)
128
129 def testPost_InvalidBots(self):
130 self._AddInternalBotsToDataStore()
131 response = self.testapp.post('/create_health_report', {
132 'tableName': 'myName',
133 'tableBots': 'garbage/moarGarbage',
134 'tableTests': 'someTests',
135 'tableLayout': '{A layout}',
136 'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
137 })
138 self.assertIn('Invalid Master/Bot: garbage/moarGarbage', response)
139 query = table_config.TableConfig.query()
140 table_values = query.fetch()
141 self.assertEqual(len(table_values), 0)
142
143 def testPost_InternalOnlyAndPublicBots(self):
144 self._AddMixedBotsToDataStore()
145 _SAMPLE_TABLE_CONFIG['xsrf_token'] = xsrf.GenerateToken(
146 users.get_current_user())
147 self.testapp.post('/create_health_report',
148 _SAMPLE_TABLE_CONFIG)
149 table_entity = ndb.Key('TableConfig', 'my_sample_config').get()
150 self.assertTrue(table_entity.internal_only)
151
152 def testPost_PublicOnlyBots(self):
153 self._AddPublicBotsToDataStore()
154 _SAMPLE_TABLE_CONFIG['xsrf_token'] = xsrf.GenerateToken(
155 users.get_current_user())
156 self.testapp.post('/create_health_report',
157 _SAMPLE_TABLE_CONFIG)
158 table_entity = ndb.Key('TableConfig', 'my_sample_config').get()
159 self.assertFalse(table_entity.internal_only)
160
161 def testPost_ValidBotsBadLayout(self):
162 self._AddPublicBotsToDataStore()
163 response = self.testapp.post('/create_health_report', {
164 'tableName': 'myName',
165 'tableBots': 'ChromiumPerf/linux',
166 'tableTests': 'someTests',
167 'tableLayout': 'garbage',
168 'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
169 })
170 self.assertIn('Invalid JSON for table layout', response)
171 query = table_config.TableConfig.query()
172 table_values = query.fetch()
173 self.assertEqual(len(table_values), 0)
OLDNEW
« no previous file with comments | « dashboard/dashboard/create_health_report.py ('k') | dashboard/dashboard/dispatcher.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698