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

Unified 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: Add default_template attribute validation Created 7 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 side-by-side diff with in-line comments
Download patch
Index: tools/deep_memory_profiler/visualizer/app_unittest.py
diff --git a/tools/deep_memory_profiler/visualizer/app_unittest.py b/tools/deep_memory_profiler/visualizer/app_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..b2f76cd0e0bdbcd6a1ec000629cae42fa7ff4f4c
--- /dev/null
+++ b/tools/deep_memory_profiler/visualizer/app_unittest.py
@@ -0,0 +1,78 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import json
+import services
Dai Mikurube (NOT FULLTIME) 2013/09/24 07:22:11 Better to split standard libraries and your librar
junjianx 2013/09/24 08:11:21 Done.
+import unittest
+
+from google.appengine.api import files
+from google.appengine.ext import ndb
+from google.appengine.ext import testbed
+from google.appengine.ext.blobstore import BlobInfo
+
+
+class ServicesTest(unittest.TestCase):
+ @staticmethod
+ def CreateBlob(path):
+ # Initialize blob dictionary to return.
+ blob = {}
+
+ # Read sample file.
+ blob['json_str'] = open(path, 'r').read()
+
+ # Create file in blobstore according to sample file.
+ file_name = files.blobstore.create(mime_type='text/plain')
+ with files.open(file_name, 'a') as f:
+ f.write(blob['json_str'])
+ files.finalize(file_name)
+
+ # Get BlobInfo of sample file.
+ blob['blob_info'] = BlobInfo.get(files.blobstore.get_blob_key(file_name))
+
+ return blob
+
+ def setUp(self):
+ self.testbed = testbed.Testbed()
+ self.testbed.activate()
+ self.testbed.init_all_stubs()
+
+ # Read sample file.
+ self.correct_blob = ServicesTest.CreateBlob('testdata/sample.json')
+ self.error_blob = ServicesTest.CreateBlob('testdata/error_sample.json')
+
+ def tearDown(self):
+ self.testbed.deactivate()
+
+ def testProfiler(self):
+ correct_blob = self.correct_blob
+ # Call services function to create Profiler entity.
+ run_id = services.CreateProfiler(correct_blob['blob_info'])
+
+ # Test GetProfiler
+ self.assertEqual(services.GetProfiler(run_id), correct_blob['json_str'])
+
+ # Create Profiler entity with the same file again and check uniqueness.
+ services.CreateProfiler(correct_blob['blob_info'])
+ self.assertEqual(services.Profiler.query().count(), 1)
+
+ def testTemplate(self):
+ correct_blob = self.correct_blob
+ # Call services function to create template entities.
+ services.CreateTemplates(correct_blob['blob_info'])
+
+ # Test templates being stored in database correctly.
+ json_obj = json.loads(correct_blob['json_str'])
+ for content in json_obj['templates'].values():
+ template_entity = ndb.Key('Template', json.dumps(content)).get()
+ self.assertEqual(template_entity.content, content)
+
+ # Create template entities with the same file again and check uniqueness.
+ services.CreateTemplates(correct_blob['blob_info'])
+ self.assertEqual(services.Template.query().count(), 2)
+
+ def testErrorBlob(self):
+ error_blob = self.error_blob
+ # Test None when default template not indicated or found in templates.
+ dflt_tmpl = services.CreateTemplates(error_blob['blob_info'])
+ self.assertIsNone(dflt_tmpl)

Powered by Google App Engine
This is Rietveld 408576698