Skip to content

Commit 338b082

Browse files
duzumakidopry
authored andcommitted
Add device poll change test
1 parent a832e6b commit 338b082

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test_device.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,39 @@ def test_device_flow_authorization_initiation(self):
100100
"device_code": "abc",
101101
"interval": 5,
102102
}
103+
104+
@mock.patch(
105+
"oauthlib.oauth2.rfc8628.endpoints.device_authorization.generate_token",
106+
lambda: "abc",
107+
)
108+
def test_device_polling_interval_can_be_changed(self):
109+
"""
110+
Tests the device polling rate(interval) can be changed to something other than the default
111+
of 5 seconds.
112+
"""
113+
114+
self.oauth2_settings.OAUTH_DEVICE_VERIFICATION_URI = "example.com/device"
115+
self.oauth2_settings.OAUTH_DEVICE_USER_CODE_GENERATOR = lambda: "xyz"
116+
117+
self.oauth2_settings.DEVICE_FLOW_INTERVAL = 10
118+
119+
request_data: dict[str, str] = {
120+
"client_id": self.application.client_id,
121+
}
122+
request_as_x_www_form_urlencoded: str = urlencode(request_data)
123+
124+
response: django.http.response.JsonResponse = self.client.post(
125+
reverse("oauth2_provider:device-authorization"),
126+
data=request_as_x_www_form_urlencoded,
127+
content_type="application/x-www-form-urlencoded",
128+
)
129+
130+
assert response.status_code == 200
131+
132+
assert response.json() == {
133+
"verification_uri": "example.com/device",
134+
"expires_in": 1800,
135+
"user_code": "xyz",
136+
"device_code": "abc",
137+
"interval": 10,
138+
}

0 commit comments

Comments
 (0)