|
10 | 10 | from django.core.exceptions import BadRequest |
11 | 11 | from django.http import JsonResponse |
12 | 12 | from django.utils import timezone |
| 13 | +from django.views.generic import View |
13 | 14 | from gidgethub import sansio |
14 | 15 | from gidgethub.abc import GitHubAPI |
15 | 16 | from model_bakery import baker |
|
21 | 22 | from django_github_app.views import AsyncWebhookView |
22 | 23 | from django_github_app.views import BaseWebhookView |
23 | 24 | from django_github_app.views import SyncWebhookView |
| 25 | +from django_github_app.views import get_webhook_views |
24 | 26 |
|
25 | 27 | pytestmark = pytest.mark.django_db |
26 | 28 |
|
@@ -303,3 +305,39 @@ def test_router_dispatch_unhandled_event( |
303 | 305 | response = view.post(request) |
304 | 306 |
|
305 | 307 | assert response.status_code == HTTPStatus.OK |
| 308 | + |
| 309 | + |
| 310 | +class TestProjectWebhookViews: |
| 311 | + def test_get_async(self, urlpatterns): |
| 312 | + with urlpatterns([AsyncWebhookView]): |
| 313 | + views = get_webhook_views() |
| 314 | + |
| 315 | + assert len(views) == 1 |
| 316 | + assert views[0] == AsyncWebhookView |
| 317 | + |
| 318 | + def test_get_sync(self, urlpatterns): |
| 319 | + with urlpatterns([SyncWebhookView]): |
| 320 | + views = get_webhook_views() |
| 321 | + |
| 322 | + assert len(views) == 1 |
| 323 | + assert views[0] == SyncWebhookView |
| 324 | + |
| 325 | + def test_get_both(self, urlpatterns): |
| 326 | + with urlpatterns([AsyncWebhookView, SyncWebhookView]): |
| 327 | + views = get_webhook_views() |
| 328 | + |
| 329 | + assert len(views) == 2 |
| 330 | + assert AsyncWebhookView in views |
| 331 | + assert SyncWebhookView in views |
| 332 | + |
| 333 | + def test_get_normal_view(self, urlpatterns): |
| 334 | + with urlpatterns([View]): |
| 335 | + views = get_webhook_views() |
| 336 | + |
| 337 | + assert len(views) == 0 |
| 338 | + |
| 339 | + def test_get_none(self, urlpatterns): |
| 340 | + with urlpatterns([]): |
| 341 | + views = get_webhook_views() |
| 342 | + |
| 343 | + assert len(views) == 0 |
0 commit comments