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 def testAddDevice(self): 64 """test AddDevice.""" 65 test_report = report.Report("create") 66 test_report.AddDevice("instance_1", "127.0.0.1", 6520, 6444) 67 expected = { 68 "devices": [{ 69 "instance_name": "instance_1", 70 "ip": "127.0.0.1:6520", 71 "adb_port": 6520, 72 "vnc_port": 6444 73 }] 74 } 75 self.assertEqual(test_report.data, expected) 76 77 def testAddDeviceBootFailure(self): 78 """test AddDeviceBootFailure.""" 79 test_report = report.Report("create") 80 test_report.AddDeviceBootFailure("instance_1", "127.0.0.1", 6520, 6444, 81 "some errors") 82 expected = { 83 "devices_failing_boot": [{ 84 "instance_name": "instance_1", 85 "ip": "127.0.0.1:6520", 86 "adb_port": 6520, 87 "vnc_port": 6444 88 }] 89 } 90 self.assertEqual(test_report.data, expected) 91 self.assertEqual(test_report.errors, ["some errors"]) 92 93 94if __name__ == "__main__": 95 unittest.main() 96