OLD | NEW |
(Empty) | |
| 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 |
| 5 from google.appengine.ext import ndb |
| 6 from testing_utils import testing |
| 7 |
| 8 from proto import project_config_pb2 |
| 9 import protoutil |
| 10 |
| 11 |
| 12 class JsonpbTest(testing.AppengineTestCase): |
| 13 def test_unmarshal_dict(self): |
| 14 msg = project_config_pb2.Swarming() |
| 15 data = { |
| 16 'common_dimensions': ['a:a', 'b:b'], |
| 17 'common_execution_timeout_secs': 600, |
| 18 'common_recipe': { |
| 19 'name': 'trybot', |
| 20 }, |
| 21 'builders': [ |
| 22 {'name': 'debug'}, |
| 23 {'name': 'release'}, |
| 24 ], |
| 25 } |
| 26 protoutil.merge_dict(data, msg) |
| 27 self.assertEqual(msg.common_dimensions, ['a:a', 'b:b']) |
| 28 self.assertEqual(msg.common_execution_timeout_secs, 600) |
| 29 self.assertEqual(len(msg.builders), 2) |
| 30 self.assertEqual(msg.builders[0].name, 'debug') |
| 31 |
| 32 msg = project_config_pb2.Swarming() |
| 33 with self.assertRaises(TypeError): |
| 34 protoutil.merge_dict([], msg) |
| 35 |
| 36 with self.assertRaises(TypeError): |
| 37 protoutil.merge_dict({'no_such_field': 0}, msg) |
| 38 |
| 39 with self.assertRaises(TypeError): |
| 40 protoutil.merge_dict({'common_dimensions': 0}, msg) |
OLD | NEW |