コード例 #1
0
async def test_session():
    async with aiohttp.ClientSession() as session:
        device = GitHubDevice("xxxxx", "", session)
        assert device.session == session

    async with GitHubDevice("xxxxx") as github:
        assert github.session is not None
コード例 #2
0
    async def async_step_device(self, _user_input):
        """Handle device steps"""
        async def _wait_for_activation(_=None):
            self.activation = await self.device.async_device_activation()
            self.hass.async_create_task(
                self.hass.config_entries.flow.async_configure(
                    flow_id=self.flow_id))

        if not self.activation:
            if not self.device:
                self.device = GitHubDevice(
                    CLIENT_ID,
                    session=aiohttp_client.async_get_clientsession(self.hass),
                )
            async_call_later(self.hass, 1, _wait_for_activation)
            try:
                device_data = await self.device.async_register_device()
                return self.async_show_progress(
                    step_id="device",
                    progress_action="wait_for_device",
                    description_placeholders={
                        "url": OAUTH_USER_LOGIN,
                        "code": device_data.user_code,
                    },
                )
            except AIOGitHubAPIException as exception:
                _LOGGER.error(exception)
                return self.async_abort(reason="github")

        return self.async_show_progress_done(next_step_id="device_done")
コード例 #3
0
async def test_no_device_code(github_device: GitHubDevice,
                              asyncio_sleep: AsyncMock):
    with pytest.raises(AIOGitHubAPIException,
                       match="User took too long to enter key"):
        github_device._expires = datetime.timestamp(datetime.now())
        await github_device.async_device_activation()
        assert asyncio_sleep.call_count == 1
        assert asyncio_sleep.call_args[0][0] == 5
コード例 #4
0
async def test_no_user_response(github_device: GitHubDevice):
    device = await github_device.async_register_device()
    assert device.user_code == "WDJB-MJHT"

    with pytest.raises(AIOGitHubAPIException,
                       match="User took too long to enter key"):
        github_device._expires = datetime.timestamp(datetime.now())
        await github_device.async_device_activation()
コード例 #5
0
    async def _show_device_form(self):
        """Device flow"""
        self.device = GitHubDevice(
            "395a8e669c5de9f7c6e8",
            session=aiohttp_client.async_get_clientsession(self.hass),
        )
        device_data = await self.device.async_register_device()

        return self.async_show_form(
            step_id="device",
            errors=self._errors,
            description_placeholders={
                "url": OAUTH_USER_LOGIN,
                "code": device_data.user_code,
            },
        )
コード例 #6
0
async def test_no_user_response(aresponses, github_device: GitHubDevice):
    aresponses.add(
        "github.com",
        "/login/device/code",
        "post",
        aresponses.Response(
            text=load_fixture("device_code.json"),
            status=200,
            headers=NOT_RATELIMITED,
        ),
    )
    device = await github_device.async_register_device()
    assert device.user_code == "WDJB-MJHT"

    with pytest.raises(AIOGitHubAPIException, match="User took too long to enter key"):
        github_device._expires = datetime.timestamp(datetime.now())
        await github_device.async_device_activation()
コード例 #7
0
ファイル: conftest.py プロジェクト: DeadSecs32/aiogithubapi
async def github_device():
    """Fixture to provide a GitHub Devlice object."""
    async with GitHubDevice(CLIENT_ID) as github_device_obj:
        yield github_device_obj
コード例 #8
0
async def test_session():
    async with aiohttp.ClientSession() as session:
        device = GitHubDevice("xxxxx", "", session)
        assert device.session == session
コード例 #9
0
ファイル: conftest.py プロジェクト: ludeeus/aiogithubapi
async def github_device(client_session):
    """Fixture to provide a GitHub Devlice object."""
    async with GitHubDevice(CLIENT_ID,
                            session=client_session) as github_device_obj:
        yield github_device_obj