Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
fd8c36d9
Unverified
Commit
fd8c36d9
authored
11 months ago
by
Erik Montnemery
Committed by
GitHub
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
User eager task in github config flow (#117066)
parent
dc1aba0a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/github/config_flow.py
+1
-3
1 addition, 3 deletions
homeassistant/components/github/config_flow.py
tests/components/github/test_config_flow.py
+29
-12
29 additions, 12 deletions
tests/components/github/test_config_flow.py
with
30 additions
and
15 deletions
homeassistant/components/github/config_flow.py
+
1
−
3
View file @
fd8c36d9
...
...
@@ -148,9 +148,7 @@ class GitHubConfigFlow(ConfigFlow, domain=DOMAIN):
return
self
.
async_abort
(
reason
=
"
could_not_register
"
)
if
self
.
login_task
is
None
:
self
.
login_task
=
self
.
hass
.
async_create_task
(
_wait_for_login
(),
eager_start
=
False
)
self
.
login_task
=
self
.
hass
.
async_create_task
(
_wait_for_login
())
if
self
.
login_task
.
done
():
if
self
.
login_task
.
exception
():
...
...
This diff is collapsed.
Click to expand it.
tests/components/github/test_config_flow.py
+
29
−
12
View file @
fd8c36d9
...
...
@@ -3,6 +3,7 @@
from
unittest.mock
import
AsyncMock
,
MagicMock
,
patch
from
aiogithubapi
import
GitHubException
from
freezegun.api
import
FrozenDateTimeFactory
import
pytest
from
homeassistant
import
config_entries
...
...
@@ -26,6 +27,7 @@ async def test_full_user_flow_implementation(
hass
:
HomeAssistant
,
mock_setup_entry
:
None
,
aioclient_mock
:
AiohttpClientMocker
,
freezer
:
FrozenDateTimeFactory
,
)
->
None
:
"""
Test the full manual user flow from start to finish.
"""
aioclient_mock
.
post
(
...
...
@@ -39,18 +41,10 @@ async def test_full_user_flow_implementation(
},
headers
=
{
"
Content-Type
"
:
"
application/json
"
},
)
# User has not yet entered the code
aioclient_mock
.
post
(
"
https://github.com/login/oauth/access_token
"
,
json
=
{
CONF_ACCESS_TOKEN
:
MOCK_ACCESS_TOKEN
,
"
token_type
"
:
"
bearer
"
,
"
scope
"
:
""
,
},
headers
=
{
"
Content-Type
"
:
"
application/json
"
},
)
aioclient_mock
.
get
(
"
https://api.github.com/user/starred
"
,
json
=
[{
"
full_name
"
:
"
home-assistant/core
"
},
{
"
full_name
"
:
"
esphome/esphome
"
}],
json
=
{
"
error
"
:
"
authorization_pending
"
},
headers
=
{
"
Content-Type
"
:
"
application/json
"
},
)
...
...
@@ -62,8 +56,20 @@ async def test_full_user_flow_implementation(
assert
result
[
"
step_id
"
]
==
"
device
"
assert
result
[
"
type
"
]
is
FlowResultType
.
SHOW_PROGRESS
# Wait for the task to start before configuring
# User enters the code
aioclient_mock
.
clear_requests
()
aioclient_mock
.
post
(
"
https://github.com/login/oauth/access_token
"
,
json
=
{
CONF_ACCESS_TOKEN
:
MOCK_ACCESS_TOKEN
,
"
token_type
"
:
"
bearer
"
,
"
scope
"
:
""
,
},
headers
=
{
"
Content-Type
"
:
"
application/json
"
},
)
freezer
.
tick
(
10
)
await
hass
.
async_block_till_done
()
result
=
await
hass
.
config_entries
.
flow
.
async_configure
(
result
[
"
flow_id
"
])
result
=
await
hass
.
config_entries
.
flow
.
async_configure
(
...
...
@@ -101,6 +107,7 @@ async def test_flow_with_registration_failure(
async
def
test_flow_with_activation_failure
(
hass
:
HomeAssistant
,
aioclient_mock
:
AiohttpClientMocker
,
freezer
:
FrozenDateTimeFactory
,
)
->
None
:
"""
Test flow with activation failure of the device.
"""
aioclient_mock
.
post
(
...
...
@@ -114,9 +121,11 @@ async def test_flow_with_activation_failure(
},
headers
=
{
"
Content-Type
"
:
"
application/json
"
},
)
# User has not yet entered the code
aioclient_mock
.
post
(
"
https://github.com/login/oauth/access_token
"
,
exc
=
GitHubException
(
"
Activation failed
"
),
json
=
{
"
error
"
:
"
authorization_pending
"
},
headers
=
{
"
Content-Type
"
:
"
application/json
"
},
)
result
=
await
hass
.
config_entries
.
flow
.
async_init
(
DOMAIN
,
...
...
@@ -124,6 +133,14 @@ async def test_flow_with_activation_failure(
)
assert
result
[
"
step_id
"
]
==
"
device
"
assert
result
[
"
type
"
]
is
FlowResultType
.
SHOW_PROGRESS
# Activation fails
aioclient_mock
.
clear_requests
()
aioclient_mock
.
post
(
"
https://github.com/login/oauth/access_token
"
,
exc
=
GitHubException
(
"
Activation failed
"
),
)
freezer
.
tick
(
10
)
await
hass
.
async_block_till_done
()
result
=
await
hass
.
config_entries
.
flow
.
async_configure
(
result
[
"
flow_id
"
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment