Skip to content

Commit 951863f

Browse files
committed
Add device poll change test
1 parent c690361 commit 951863f

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
@@ -95,3 +95,39 @@ def test_device_flow_authorization_initiation(self):
9595
"device_code": "abc",
9696
"interval": 5,
9797
}
98+
99+
@mock.patch(
100+
"oauthlib.oauth2.rfc8628.endpoints.device_authorization.generate_token",
101+
lambda: "abc",
102+
)
103+
def test_device_polling_interval_can_be_changed(self):
104+
"""
105+
Tests the device polling rate(interval) can be changed to something other than the default
106+
of 5 seconds.
107+
"""
108+
109+
self.oauth2_settings.OAUTH_DEVICE_VERIFICATION_URI = "example.com/device"
110+
self.oauth2_settings.OAUTH_DEVICE_USER_CODE_GENERATOR = lambda: "xyz"
111+
112+
self.oauth2_settings.DEVICE_FLOW_INTERVAL = 10
113+
114+
request_data: dict[str, str] = {
115+
"client_id": self.application.client_id,
116+
}
117+
request_as_x_www_form_urlencoded: str = urlencode(request_data)
118+
119+
response: django.http.response.JsonResponse = self.client.post(
120+
reverse("oauth2_provider:device-authorization"),
121+
data=request_as_x_www_form_urlencoded,
122+
content_type="application/x-www-form-urlencoded",
123+
)
124+
125+
assert response.status_code == 200
126+
127+
assert response.json() == {
128+
"verification_uri": "example.com/device",
129+
"expires_in": 1800,
130+
"user_code": "xyz",
131+
"device_code": "abc",
132+
"interval": 10,
133+
}

0 commit comments

Comments
 (0)