Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem testing HA custom component with uses oauth2 #180

Open
jwillemsen opened this issue Mar 15, 2024 · 0 comments
Open

Problem testing HA custom component with uses oauth2 #180

jwillemsen opened this issue Mar 15, 2024 · 0 comments

Comments

@jwillemsen
Copy link
Contributor

I am trying to setup tests for a custom component which uses oauth2 authorization. When researching how to test a custom component I found this project and I found some oauth2 scaffolding scripts which are part of HA.

The HA scaffolding generated test code for oauth2 works for a core component, but when trying this as part of a custom component it fails with the error below. I have added a conftest.py but that didn't resolve. As it works within the core HA test directory I think this project does something which breaks it.

In order to analyze this I have isolated everything in a small test repo, see https://github.com/jwillemsen/haoauth2_test.

hass = <homeassistant.core.HomeAssistant object at 0x7f4b2e933280>

    @pytest.fixture
    async def setup_credentials(hass: HomeAssistant) -> None:
        """Fixture to setup credentials."""
        assert await async_setup_component(hass, "application_credentials", {})
>       await async_import_client_credential(
            hass,
            DOMAIN,
            ClientCredential(CLIENT_ID, CLIENT_SECRET),
        )

tests/test_config_flow.py:29: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.10/site-packages/homeassistant/components/application_credentials/__init__.py:185: in async_import_client_credential
    await storage_collection.async_import_item(item)
/usr/lib/python3.10/site-packages/homeassistant/components/application_credentials/__init__.py:125: in async_import_item
    await self.async_create_item(info)
/usr/lib/python3.10/site-packages/homeassistant/helpers/collection.py:310: in async_create_item
    validated_data = await self._process_create_data(data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <homeassistant.components.application_credentials.ApplicationCredentialsStorageCollection object at 0x7f4b2e94eaa0>, data = {'auth_domain': 'daikin_onecta', 'client_id': '1234', 'client_secret': '5678', 'domain': 'daikin_onecta', ...}

    async def _process_create_data(self, data: dict[str, str]) -> dict[str, str]:
        """Validate the config is valid."""
        result = self.CREATE_SCHEMA(data)
        domain = result[CONF_DOMAIN]
        if not await _get_platform(self.hass, domain):
>           raise ValueError(f"No application_credentials platform for {domain}")
E           ValueError: No application_credentials platform for daikin_onecta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant