OLD | NEW |
---|---|
(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 services | |
6 import unittest | |
7 | |
8 from google.appengine.api import files | |
9 from google.appengine.ext import testbed | |
10 from google.appengine.ext.blobstore import BlobInfo | |
11 | |
12 | |
13 class ServicesTest(unittest.TestCase): | |
14 def setUp(self): | |
15 self.testbed = testbed.Testbed() | |
16 self.testbed.activate() | |
17 self.testbed.init_all_stubs() | |
18 | |
19 # Read sample file. | |
20 self.json_str = open('testdata/sample.json', 'r').read() | |
21 | |
22 # Create file in blobstore according to sample file. | |
23 file_name = files.blobstore.create(mime_type='text/plain') | |
24 with files.open(file_name, 'a') as f: | |
25 f.write(self.json_str) | |
26 files.finalize(file_name) | |
27 | |
28 # Get BlobInfo of sample file. | |
29 self.blob_info = BlobInfo.get(files.blobstore.get_blob_key(file_name)) | |
30 | |
31 def tearDown(self): | |
32 self.testbed.deactivate() | |
33 | |
34 def testProfiler(self): | |
35 # Call services function to create Profiler entity. | |
36 run_id = services.CreateProfiler(self.blob_info) | |
37 | |
38 # Test GetProfiler | |
39 self.assertEqual(services.GetProfiler(run_id), self.json_str) | |
40 | |
41 # Create Profiler entity with the same file again and check uniqueness. | |
42 services.CreateProfiler(self.blob_info) | |
43 self.assertEqual(services.Profiler.query().count(), 1) | |
44 | |
45 def testTemplate(self): | |
46 # Call services function to create template entities. | |
47 services.CreateTemplates(self.blob_info) | |
48 self.assertEqual(services.Template.query().count(), 2) | |
sullivan
2013/09/20 13:59:51
Might want to do some testing of the content of th
junjianx
2013/09/24 05:53:53
Done.
| |
OLD | NEW |