def test_validate_ota_image_simple_valid(): image = OTAImage() image.subelements = [ create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_EBL_IMAGE), ] assert validators.validate_ota_image(image) == ValidationResult.VALID
def test_validate_ota_image_mixed_valid(): image = OTAImage() image.subelements = [ create_subelement(ElementTagId.UPGRADE_IMAGE, b"unknown1"), create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_EBL_IMAGE), ] assert validators.validate_ota_image(image) == ValidationResult.UNKNOWN
def test_validate_ota_image_invalid(): image = OTAImage() image.subelements = [ create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_EBL_IMAGE[:-1]), ] with pytest.raises(ValidationError): validators.validate_ota_image(image)
def test_validate_ota_image_complex_valid(): image = OTAImage() image.subelements = [ create_subelement(ElementTagId.ECDSA_SIGNATURE, b"asd"), create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_EBL_IMAGE), create_subelement(ElementTagId.UPGRADE_IMAGE, VALID_GBL_IMAGE), create_subelement(ElementTagId.ECDSA_SIGNING_CERTIFICATE, b"foo"), ] assert validators.validate_ota_image(image) == ValidationResult.VALID
def test_check_invalid(): image = OTAImage() with mock.patch("zigpy.ota.validators.validate_ota_image") as m: m.side_effect = [ValidationResult.VALID] assert not validators.check_invalid(image) with mock.patch("zigpy.ota.validators.validate_ota_image") as m: m.side_effect = [ValidationResult.UNKNOWN] assert not validators.check_invalid(image) with mock.patch("zigpy.ota.validators.validate_ota_image") as m: m.side_effect = [ValidationError("error")] assert validators.check_invalid(image)
def test_validate_ota_image_empty(): image = OTAImage() assert validators.validate_ota_image(image) == ValidationResult.UNKNOWN
def test_validate_ota_image_empty(): image = OTAImage() image.subelements = [] assert validators.validate_ota_image(image) == ValidationResult.UNKNOWN