blob: 3d06849b00a35ad212cae12a2341bead6b94429a [file] [log] [blame]
George Engelbrechtfe63c8c2019-08-31 22:51:29 -06001# -*- coding: utf-8 -*-
2# Copyright 2019 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Payload operations."""
7
8from __future__ import print_function
9
10from chromite.api import api_config
11from chromite.api import controller
12from chromite.api.controller import payload
13from chromite.api.gen.chromite.api import payload_pb2
14from chromite.api.gen.chromiumos import common_pb2
15from chromite.lib import cros_test_lib
16from chromite.lib.paygen import paygen_payload_lib
17
18
19class PayloadApiTests(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
20 """Unittests for SetBinhost."""
21
22 def setUp(self):
Alex Klein10b9fed2020-09-23 14:56:18 -060023 self.response = payload_pb2.GenerationResponse()
George Engelbrechtfe63c8c2019-08-31 22:51:29 -060024
25 src_build = payload_pb2.Build(version='1.0.0', bucket='test',
26 channel='test-channel', build_target=
27 common_pb2.BuildTarget(name='cave'))
28
29 src_image = payload_pb2.UnsignedImage(
30 build=src_build, image_type=6, milestone='R70')
31
32 tgt_build = payload_pb2.Build(version='2.0.0', bucket='test',
33 channel='test-channel', build_target=
34 common_pb2.BuildTarget(name='cave'))
35
36 tgt_image = payload_pb2.UnsignedImage(
37 build=tgt_build, image_type=6, milestone='R70')
38
Alex Klein10b9fed2020-09-23 14:56:18 -060039 self.req = payload_pb2.GenerationRequest(
Navil Perezf5482be2020-04-09 23:18:14 -060040 tgt_unsigned_image=tgt_image,
41 src_unsigned_image=src_image,
42 bucket='test-destination-bucket',
43 verify=True,
44 keyset='update_signer',
45 dryrun=False)
George Engelbrechtfe63c8c2019-08-31 22:51:29 -060046
Alex Klein10b9fed2020-09-23 14:56:18 -060047 self.result = payload_pb2.GenerationResponse()
George Engelbrechtfe63c8c2019-08-31 22:51:29 -060048
49 def testValidateOnly(self):
50 """Sanity check that a validate only call does not execute any logic."""
51
52 res = payload.GeneratePayload(self.req, self.result,
53 self.validate_only_config)
54 self.assertEqual(res, controller.RETURN_CODE_VALID_INPUT)
55
56 def testCallSucceeds(self):
Alex Klein10b9fed2020-09-23 14:56:18 -060057 """Check that a call is made successfully."""
George Engelbrechtfe63c8c2019-08-31 22:51:29 -060058 # Deep patch the paygen lib, this is a full run through service as well.
59 self.PatchObject(paygen_payload_lib, 'PaygenPayload')
60 res = payload.GeneratePayload(self.req, self.result, self.api_config)
61 self.assertEqual(res, controller.RETURN_CODE_SUCCESS)
Michael Mortensen85d38402019-12-12 09:50:29 -070062
63 def testMockError(self):
64 """Test mock error call does not execute any logic, returns error."""
65 patch = self.PatchObject(paygen_payload_lib, 'PaygenPayload')
66
67 res = payload.GeneratePayload(self.req, self.result,
68 self.mock_error_config)
69 patch.assert_not_called()
70 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, res)
71
72 def testMockCall(self):
73 """Test mock call does not execute any logic, returns success."""
74 patch = self.PatchObject(paygen_payload_lib, 'PaygenPayload')
75
76 res = payload.GeneratePayload(self.req, self.result,
77 self.mock_call_config)
78 patch.assert_not_called()
79 self.assertEqual(controller.RETURN_CODE_SUCCESS, res)