-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add namespace versioning to api * Update tests to care about versions * Ensure version is available when reversing urls
- Loading branch information
Showing
11 changed files
with
100 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.urls import include, path | ||
|
||
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView | ||
|
||
from argus.auth.views import ObtainNewAuthToken | ||
|
||
openapi_urls = [ | ||
path("", SpectacularAPIView.as_view(api_version="v1"), name="schema-v1"), | ||
path("swagger-ui/", SpectacularSwaggerView.as_view(url_name="v1:openapi:schema-v1"), name="swagger-ui-v1"), | ||
] | ||
|
||
tokenauth_urls = [ | ||
path("", ObtainNewAuthToken.as_view(), name="api-token-auth"), | ||
] | ||
|
||
urlpatterns = [ | ||
path("schema/", include((openapi_urls, "openapi"))), | ||
path("auth/", include("argus.auth.urls")), | ||
path("incidents/", include("argus.incident.urls")), | ||
path("notificationprofiles/", include("argus.notificationprofile.urls")), | ||
path("token-auth/", include(tokenauth_urls)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.urls import include, path | ||
|
||
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView | ||
|
||
from argus.auth.views import ObtainNewAuthToken | ||
|
||
openapi_urls = [ | ||
path("", SpectacularAPIView.as_view(api_version="v2"), name="schema"), | ||
path("swagger-ui/", SpectacularSwaggerView.as_view(url_name="v2:openapi:schema"), name="swagger-ui"), | ||
] | ||
|
||
tokenauth_urls = [ | ||
path("", ObtainNewAuthToken.as_view(), name="api-token-auth"), | ||
] | ||
|
||
urlpatterns = [ | ||
path("schema/", include((openapi_urls, "openapi"))), | ||
path("auth/", include("argus.auth.urls")), | ||
path("incidents/", include("argus.incident.urls")), | ||
path("notificationprofiles/", include("argus.notificationprofile.urls")), | ||
path("token-auth/", include((tokenauth_urls, "auth"))), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase, RequestFactory | ||
from django.utils import timezone | ||
from django.utils.timezone import is_aware, make_aware | ||
|
||
from rest_framework import serializers, versioning | ||
|
||
from argus.auth.factories import SourceUserFactory | ||
from argus.incident.factories import * | ||
from argus.incident.models import Event | ||
from argus.incident.views import EventViewSet | ||
from argus.util.testing import disconnect_signals, connect_signals | ||
|
||
|
||
class EventViewSetTestCase(TestCase): | ||
def setUp(self): | ||
disconnect_signals() | ||
source_type = SourceSystemTypeFactory() | ||
source_user = SourceUserFactory() | ||
self.source = SourceSystemFactory(type=source_type, user=source_user) | ||
|
||
def tearDown(self): | ||
connect_signals() | ||
|
||
def test_validate_event_type_for_incident_acknowledge_raises_validation_error(self): | ||
incident = IncidentFactory(source=self.source) | ||
viewfactory = RequestFactory() | ||
request = viewfactory.get(f"/api/v1/incidents/{incident.pk}/events/") | ||
request.versioning_scheme = versioning.NamespaceVersioning() | ||
request.version = "v1" | ||
view = EventViewSet() | ||
view.request = request | ||
with self.assertRaises(serializers.ValidationError): | ||
view.validate_event_type_for_incident(Event.Type.ACKNOWLEDGE, incident) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters