def test_blueprint_validate(): """Test validate blueprint.""" assert ( models.Blueprint( { "blueprint": { "name": "Hello", "domain": "automation", }, } ).validate() is None ) assert ( models.Blueprint( { "blueprint": { "name": "Hello", "domain": "automation", "homeassistant": {"min_version": "100000.0.0"}, }, } ).validate() == ["Requires at least Safegate Pro 100000.0.0"] )
def test_blueprint_model_init(): """Test constructor validation.""" with pytest.raises(errors.InvalidBlueprint): models.Blueprint({}) with pytest.raises(errors.InvalidBlueprint): models.Blueprint( {"blueprint": { "name": "Hello", "domain": "automation" }}, expected_domain="not-automation", ) with pytest.raises(errors.InvalidBlueprint): models.Blueprint({ "blueprint": { "name": "Hello", "domain": "automation", "input": { "something": None }, }, "trigger": { "platform": Input("non-existing") }, })
def mock_load_blueprint(self, path): if path != blueprint_path: assert False, f"Unexpected blueprint {path}" return orig_load(self, path) return models.Blueprint(yaml.load_yaml(data_path), expected_domain=self.domain, path=path)
def test_blueprint_update_metadata(): """Test update metadata.""" bp = models.Blueprint({ "blueprint": { "name": "Hello", "domain": "automation", }, }) bp.update_metadata(source_url="http://bla.com") assert bp.metadata["source_url"] == "http://bla.com"
def blueprint_1(): """Blueprint fixture.""" return models.Blueprint({ "blueprint": { "name": "Hello", "domain": "automation", "input": { "test-placeholder": None }, }, "example": Placeholder("test-placeholder"), })
def blueprint_1(): """Blueprint fixture.""" return models.Blueprint( { "blueprint": { "name": "Hello", "domain": "automation", "source_url": "https://github.com/balloob/home-assistant-config/blob/main/blueprints/automation/motion_light.yaml", "input": {"test-input": {"name": "Name", "description": "Description"}}, }, "example": Input("test-input"), } )
def test_default_blueprints(domain: str): """Validate a folder of blueprints.""" integration = importlib.import_module(f"homeassistant.components.{domain}") blueprint_folder = pathlib.Path( integration.__file__).parent / BLUEPRINT_FOLDER items = list(blueprint_folder.glob("*")) assert len(items) > 0, "Folder cannot be empty" for fil in items: LOGGER.info("Processing %s", fil) assert fil.name.endswith(".yaml") data = yaml.load_yaml(fil) models.Blueprint(data, expected_domain=domain)