def test_parse_from_json_no_valid_boot_time(self): boot_json = { "board": "board", "job": "job", "kernel": "kernel", "defconfig": "defconfig", "lab_name": "lab_name", "git_branch": "branch", "dtb": "dtb", "boot_time": "foo", "build_environment": "build_environment" } errors = {} doc = bimport._parse_boot_from_json(boot_json, self.db, errors) self.assertIsNotNone(doc) self.assertEqual(doc.board, "board") self.assertEqual(doc.job, "job") self.assertEqual(doc.kernel, "kernel") self.assertEqual(doc.defconfig, "defconfig") self.assertEqual(doc.git_branch, "branch") self.assertEqual(doc.dtb, "dtb") self.assertEqual(doc.time, datetime.datetime(1970, 1, 1, 0, 0)) self.assertListEqual([400], errors.keys())
def test_parse_from_json_no_valid_boot_time(self): boot_json = { "board": "board", "job": "job", "kernel": "kernel", "defconfig": "defconfig", "lab_name": "lab_name", "git_branch": "branch", "dtb": "dtb", "boot_time": "foo", "build_environment": "build_environment" } errors = {} doc = bimport._parse_boot_from_json(boot_json, self.db, errors) self.assertIsNotNone(doc) self.assertEqual(doc.board, "board") self.assertEqual(doc.job, "job") self.assertEqual(doc.kernel, "kernel") self.assertEqual(doc.defconfig, "defconfig") self.assertEqual(doc.git_branch, "branch") self.assertEqual(doc.dtb, "dtb") self.assertEqual(doc.time, datetime.datetime(1970, 1, 1, 0, 0)) self.assertListEqual([400], errors.keys())
def test_parse_from_json_with_null(self): boot_json = {"board": "null"} errors = {} doc = bimport._parse_boot_from_json(boot_json, self.db, errors) self.assertIsNone(doc) self.assertListEqual([400], errors.keys())
def test_save_to_disk_dir_create_error(self, mock_mkdir): errors = {} base_path = tempfile.mkdtemp() json_obj = { "board": "board", "job": "job", "kernel": "kernel", "defconfig": "defconfig", "arch": "arm", "defconfig_full": "defconfig+FRAGMENT", "lab_name": "lab", "git_branch": "branch", "build_environment": "build_environment" } boot_doc = mboot.BootDocument("board", "job", "kernel", "defconfig", "lab", "branch", "build_environment", "defconfig+FRAGMENT", "arm") expected_path = os.path.join(base_path, "job", "branch", "kernel", "arm", "defconfig+FRAGMENT", "build_environment", "lab") expected_file = os.path.join(expected_path, "boot-board.json") exception = OSError("Error") exception.errno = errno.EIO mock_mkdir.side_effect = exception try: bimport.save_to_disk(boot_doc, json_obj, base_path, errors) self.assertFalse(os.path.exists(expected_path)) self.assertFalse(os.path.exists(expected_file)) self.assertListEqual([500], errors.keys()) finally: shutil.rmtree(base_path)
def test_save_to_disk_dir_create_error(self, mock_mkdir): errors = {} base_path = tempfile.mkdtemp() json_obj = { "board": "board", "job": "job", "kernel": "kernel", "defconfig": "defconfig", "arch": "arm", "defconfig_full": "defconfig+FRAGMENT", "lab_name": "lab", "git_branch": "branch", "build_environment": "build_environment" } boot_doc = mboot.BootDocument( "board", "job", "kernel", "defconfig", "lab", "branch", "build_environment", "defconfig+FRAGMENT", "arm") expected_path = os.path.join( base_path, "job", "branch", "kernel", "arm", "defconfig+FRAGMENT", "build_environment", "lab") expected_file = os.path.join(expected_path, "boot-board.json") exception = OSError("Error") exception.errno = errno.EIO mock_mkdir.side_effect = exception try: bimport.save_to_disk(boot_doc, json_obj, base_path, errors) self.assertFalse(os.path.exists(expected_path)) self.assertFalse(os.path.exists(expected_file)) self.assertListEqual([500], errors.keys()) finally: shutil.rmtree(base_path)
def test_parse_from_json_wrong_json(self, mock_null): boot_json = { "foo": "bar" } errors = {} doc = bimport._parse_boot_from_json(boot_json, self.db, errors) self.assertIsNone(doc) self.assertListEqual([400], errors.keys())
def test_parse_from_json_with_null(self): boot_json = { "board": "null" } errors = {} doc = bimport._parse_boot_from_json(boot_json, self.db, errors) self.assertIsNone(doc) self.assertListEqual([400], errors.keys())
def test_parse_from_json_wrong_boot_time_negative(self): boot_json = { "job": "job", "kernel": "kernel", "defconfig": "defconfig", "board": "board", "dtb": "dtb", "lab_name": "lab_name", "git_branch": "branch", "boot_time": -1500.0 } errors = {} doc = bimport._parse_boot_from_json(boot_json, self.db, errors) self.assertEqual(doc.board, "board") self.assertEqual(doc.job, "job") self.assertEqual(doc.kernel, "kernel") self.assertEqual(doc.defconfig, "defconfig") self.assertEqual(doc.dtb, "dtb") self.assertEqual(doc.time, datetime.datetime(1970, 1, 1, 0, 0)) self.assertListEqual([400], errors.keys())
def test_parse_from_json_wrong_boot_time_too_big_negative(self): boot_json = { "job": "job", "kernel": "kernel", "defconfig": "defconfig", "board": "board", "dtb": "dtb", "lab_name": "lab_name", "git_branch": "branch", "boot_time": -sys.maxint - 1, "build_environment": "build_environment" } errors = {} doc = bimport._parse_boot_from_json(boot_json, self.db, errors) self.assertEqual(doc.board, "board") self.assertEqual(doc.job, "job") self.assertEqual(doc.kernel, "kernel") self.assertEqual(doc.defconfig, "defconfig") self.assertEqual(doc.dtb, "dtb") self.assertEqual(doc.time, datetime.datetime(1970, 1, 1, 0, 0)) self.assertListEqual([400], errors.keys())
def test_parse_from_json_wrong_json(self, mock_null): boot_json = {"foo": "bar"} errors = {} doc = bimport._parse_boot_from_json(boot_json, self.db, errors) self.assertIsNone(doc) self.assertListEqual([400], errors.keys())