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: tools/deep_memory_profiler/visualizer/app_unittest.py

Issue 23781012: Upload file to app engine and generate public url for dmprof visualizer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review problems Created 7 years, 2 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
(Empty)
1 # Copyright 2013 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 json
6 import unittest
7
8 from google.appengine.api import files
9 from google.appengine.ext import ndb
10 from google.appengine.ext import testbed
11 from google.appengine.ext.blobstore import BlobInfo
12
13 import services
14
15
16 class ServicesTest(unittest.TestCase):
17 @staticmethod
18 def CreateBlob(path):
19 # Initialize blob dictionary to return.
20 blob = {}
21
22 # Read sample file.
23 blob['json_str'] = open(path, 'r').read()
24
25 # Create file in blobstore according to sample file.
26 file_name = files.blobstore.create(mime_type='text/plain')
27 with files.open(file_name, 'a') as f:
28 f.write(blob['json_str'])
29 files.finalize(file_name)
30
31 # Get BlobInfo of sample file.
32 blob['blob_info'] = BlobInfo.get(files.blobstore.get_blob_key(file_name))
33
34 return blob
35
36 def setUp(self):
37 self.testbed = testbed.Testbed()
38 self.testbed.activate()
39 self.testbed.init_all_stubs()
40
41 # Read sample file.
42 self.correct_blob = ServicesTest.CreateBlob('testdata/sample.json')
43 self.error_blob = ServicesTest.CreateBlob('testdata/error_sample.json')
44
45 def tearDown(self):
46 self.testbed.deactivate()
47
48 def testProfiler(self):
49 correct_blob = self.correct_blob
50 # Call services function to create Profiler entity.
51 run_id = services.CreateProfiler(correct_blob['blob_info'])
52
53 # Test GetProfiler
54 self.assertEqual(services.GetProfiler(run_id), correct_blob['json_str'])
55
56 # Create Profiler entity with the same file again and check uniqueness.
57 services.CreateProfiler(correct_blob['blob_info'])
58 self.assertEqual(services.Profiler.query().count(), 1)
59
60 def testTemplate(self):
61 correct_blob = self.correct_blob
62 # Call services function to create template entities.
63 services.CreateTemplates(correct_blob['blob_info'])
64
65 # Test templates being stored in database correctly.
66 json_obj = json.loads(correct_blob['json_str'])
67 for content in json_obj['templates'].values():
68 template_entity = ndb.Key('Template', json.dumps(content)).get()
69 self.assertEqual(template_entity.content, content)
70
71 # Create template entities with the same file again and check uniqueness.
72 services.CreateTemplates(correct_blob['blob_info'])
73 self.assertEqual(services.Template.query().count(), 2)
74
75 def testErrorBlob(self):
76 error_blob = self.error_blob
77 # Test None when default template not indicated or found in templates.
78 dflt_tmpl = services.CreateTemplates(error_blob['blob_info'])
79 self.assertIsNone(dflt_tmpl)
OLDNEW
« no previous file with comments | « tools/deep_memory_profiler/visualizer/app.py ('k') | tools/deep_memory_profiler/visualizer/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698