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 3# found in the LICENSE file. 4 5import json 6import unittest 7 8import webapp2 9import webtest 10 11from dashboard import short_uri 12from dashboard import testing_common 13 14 15class ShortUriTest(testing_common.TestCase): 16 17 def setUp(self): 18 super(ShortUriTest, self).setUp() 19 app = webapp2.WSGIApplication( 20 [('/short_uri', 21 short_uri.ShortUriHandler)]) 22 self.testapp = webtest.TestApp(app) 23 24 def testPostAndGet(self): 25 sample_page_state = { 26 'charts': [['Chromium/win/sunspider/total', 'important']] 27 } 28 29 response = self.testapp.post( 30 '/short_uri', {'page_state': json.dumps(sample_page_state)}) 31 page_state_id = json.loads(response.body)['sid'] 32 self.assertIsNotNone(page_state_id) 33 34 response = self.testapp.get('/short_uri', {'sid': page_state_id}) 35 page_state = json.loads(response.body) 36 self.assertEqual(sample_page_state, page_state) 37 38 def testGet_InvalidSID(self): 39 self.testapp.get('/short_uri', {'sid': '123xyz'}, status=400) 40 41 def testGet_NoSID(self): 42 self.testapp.get('/short_uri', status=400) 43 44 def testPost_NoPageState(self): 45 self.testapp.post('/short_uri', status=400) 46 47 48if __name__ == '__main__': 49 unittest.main() 50