1#!/usr/bin/env python 2# 3# Copyright 2016 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17"""Tests for acloud.public.report.""" 18 19import unittest 20from acloud.public import report 21 22 23class ReportTest(unittest.TestCase): 24 """Test Report class.""" 25 26 def testAddData(self): 27 """test AddData.""" 28 test_report = report.Report("create") 29 test_report.AddData("devices", {"instance_name": "instance_1"}) 30 test_report.AddData("devices", {"instance_name": "instance_2"}) 31 expected = { 32 "devices": [{ 33 "instance_name": "instance_1" 34 }, { 35 "instance_name": "instance_2" 36 }] 37 } 38 self.assertEqual(test_report.data, expected) 39 40 def testAddError(self): 41 """test AddError.""" 42 test_report = report.Report("create") 43 test_report.errors.append("some errors") 44 test_report.errors.append("some errors") 45 self.assertEqual(test_report.errors, ["some errors", "some errors"]) 46 47 def testSetStatus(self): 48 """test SetStatus.""" 49 test_report = report.Report("create") 50 test_report.SetStatus(report.Status.SUCCESS) 51 self.assertEqual(test_report.status, "SUCCESS") 52 53 test_report.SetStatus(report.Status.FAIL) 54 self.assertEqual(test_report.status, "FAIL") 55 56 test_report.SetStatus(report.Status.BOOT_FAIL) 57 self.assertEqual(test_report.status, "BOOT_FAIL") 58 59 # Test that more severe status won't get overriden. 60 test_report.SetStatus(report.Status.FAIL) 61 self.assertEqual(test_report.status, "BOOT_FAIL") 62 63 64if __name__ == "__main__": 65 unittest.main() 66