George Engelbrecht | fe63c8c | 2019-08-31 22:51:29 -0600 | [diff] [blame] | 1 | # -*- 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 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | from chromite.api import api_config |
| 11 | from chromite.api import controller |
| 12 | from chromite.api.controller import payload |
| 13 | from chromite.api.gen.chromite.api import payload_pb2 |
| 14 | from chromite.api.gen.chromiumos import common_pb2 |
| 15 | from chromite.lib import cros_test_lib |
| 16 | from chromite.lib.paygen import paygen_payload_lib |
| 17 | |
| 18 | |
| 19 | class PayloadApiTests(cros_test_lib.MockTestCase, api_config.ApiConfigMixin): |
| 20 | """Unittests for SetBinhost.""" |
| 21 | |
| 22 | def setUp(self): |
| 23 | self.response = payload_pb2.PayloadGenerationResult() |
| 24 | |
| 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 | |
| 39 | self.req = payload_pb2.PayloadGenerationRequest( |
| 40 | tgt_unsigned_image=tgt_image, src_unsigned_image=src_image, |
| 41 | bucket='test-destination-bucket', verify=True, keyset='update_signer') |
| 42 | |
| 43 | self.result = payload_pb2.PayloadGenerationResult() |
| 44 | |
| 45 | def testValidateOnly(self): |
| 46 | """Sanity check that a validate only call does not execute any logic.""" |
| 47 | |
| 48 | res = payload.GeneratePayload(self.req, self.result, |
| 49 | self.validate_only_config) |
| 50 | self.assertEqual(res, controller.RETURN_CODE_VALID_INPUT) |
| 51 | |
| 52 | def testCallSucceeds(self): |
| 53 | """Check that a call is made succesfully.""" |
| 54 | # Deep patch the paygen lib, this is a full run through service as well. |
| 55 | self.PatchObject(paygen_payload_lib, 'PaygenPayload') |
| 56 | res = payload.GeneratePayload(self.req, self.result, self.api_config) |
| 57 | self.assertEqual(res, controller.RETURN_CODE_SUCCESS) |