Browse Source

feat(api-docs): Add tests for Organization endpoints (#21033)

* feat(api-docs): Add tests for Organization endpoints
Colleen O'Rourke 4 years ago
parent
commit
587a7bd937

+ 1 - 1
src/sentry/api/urls.py

@@ -971,7 +971,7 @@ urlpatterns = [
                 url(
                     r"^(?P<organization_slug>[^\/]+)/projects-count/$",
                     OrganizationProjectsCountEndpoint.as_view(),
-                    name="sentry-api-0-organization-projects",
+                    name="sentry-api-0-organization-projects-count",
                 ),
                 url(
                     r"^(?P<organization_slug>[^\/]+)/sent-first-event/$",

+ 35 - 0
tests/apidocs/endpoints/organizations/test-event-id-lookup.py

@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+
+from tests.apidocs.util import APIDocsTestCase
+from sentry.testutils.helpers.datetime import before_now, iso_format
+
+
+class OrganizationEventIDLookupDocs(APIDocsTestCase):
+    def setUp(self):
+        organization = self.create_organization()
+        project = self.create_project(name="foo", organization=organization, teams=[])
+        event = self.store_event(
+            data={
+                "event_id": "a" * 32,
+                "message": "oh no",
+                "timestamp": iso_format(before_now(seconds=1)),
+            },
+            project_id=project.id,
+        )
+        self.url = reverse(
+            "sentry-api-0-event-id-lookup",
+            kwargs={"organization_slug": organization.slug, "event_id": event.event_id},
+        )
+
+        self.login_as(user=self.user)
+
+    def test_get(self):
+        response = self.client.get(self.url)
+        request = RequestFactory().get(self.url)
+
+        self.validate_schema(request, response)

+ 32 - 0
tests/apidocs/endpoints/organizations/test-org-details.py

@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+
+from tests.apidocs.util import APIDocsTestCase
+
+
+class OrganizationDetailsDocs(APIDocsTestCase):
+    def setUp(self):
+        organization = self.create_organization()
+
+        self.url = reverse(
+            "sentry-api-0-organization-details", kwargs={"organization_slug": organization.slug},
+        )
+
+        self.login_as(user=self.user)
+
+    def test_get(self):
+        response = self.client.get(self.url)
+        request = RequestFactory().get(self.url)
+
+        self.validate_schema(request, response)
+
+    def test_put(self):
+        data = {"name": "foo"}
+        response = self.client.put(self.url, data)
+        request = RequestFactory().put(self.url, data)
+
+        self.validate_schema(request, response)

+ 23 - 0
tests/apidocs/endpoints/organizations/test-org-index.py

@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+
+from tests.apidocs.util import APIDocsTestCase
+
+
+class OrganizationIndexDocs(APIDocsTestCase):
+    def setUp(self):
+        self.create_organization()
+
+        self.url = reverse("sentry-api-0-organizations",)
+
+        self.login_as(user=self.user)
+
+    def test_get(self):
+        response = self.client.get(self.url)
+        request = RequestFactory().get(self.url)
+
+        self.validate_schema(request, response)

+ 27 - 0
tests/apidocs/endpoints/organizations/test-org-projects.py

@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+
+from tests.apidocs.util import APIDocsTestCase
+
+
+class OrganizationProjectsDocs(APIDocsTestCase):
+    def setUp(self):
+        organization = self.create_organization()
+        self.create_project(name="foo", organization=organization, teams=[])
+        self.create_project(name="bar", organization=organization, teams=[])
+
+        self.url = reverse(
+            "sentry-api-0-organization-projects", kwargs={"organization_slug": organization.slug},
+        )
+
+        self.login_as(user=self.user)
+
+    def test_get(self):
+        response = self.client.get(self.url)
+        request = RequestFactory().get(self.url)
+
+        self.validate_schema(request, response)

+ 28 - 0
tests/apidocs/endpoints/organizations/test-org-repos.py

@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+
+from tests.apidocs.util import APIDocsTestCase
+
+
+class OrganizationReposDocs(APIDocsTestCase):
+    def setUp(self):
+        organization = self.create_organization()
+        project = self.create_project(name="foo", organization=organization, teams=[])
+        self.create_repo(project=project, name="getsentry/sentry")
+
+        self.url = reverse(
+            "sentry-api-0-organization-repositories",
+            kwargs={"organization_slug": organization.slug},
+        )
+
+        self.login_as(user=self.user)
+
+    def test_get(self):
+        response = self.client.get(self.url)
+        request = RequestFactory().get(self.url)
+
+        self.validate_schema(request, response)

+ 43 - 0
tests/apidocs/endpoints/organizations/test-org-stats.py

@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+
+from tests.apidocs.util import APIDocsTestCase
+from sentry.testutils.helpers.datetime import before_now, iso_format
+
+
+class OrganizationStatsDocs(APIDocsTestCase):
+    def setUp(self):
+        organization = self.create_organization()
+        project = self.create_project(name="foo", organization=organization, teams=[])
+        self.store_event(
+            data={
+                "event_id": "a" * 32,
+                "message": "oh no",
+                "timestamp": iso_format(before_now(seconds=1)),
+            },
+            project_id=project.id,
+        )
+        self.store_event(
+            data={
+                "event_id": "b" * 32,
+                "message": "uh oh",
+                "timestamp": iso_format(before_now(seconds=1)),
+            },
+            project_id=project.id,
+        )
+
+        self.url = reverse(
+            "sentry-api-0-organization-stats", kwargs={"organization_slug": organization.slug},
+        )
+
+        self.login_as(user=self.user)
+
+    def test_get(self):
+        response = self.client.get(self.url)
+        request = RequestFactory().get(self.url)
+
+        self.validate_schema(request, response)

+ 26 - 0
tests/apidocs/endpoints/organizations/test-org-users.py

@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+
+from tests.apidocs.util import APIDocsTestCase
+
+
+class OrganizationUsersDocs(APIDocsTestCase):
+    def setUp(self):
+        organization = self.create_organization()
+        self.create_user(email="colleen@sentry.io")
+
+        self.url = reverse(
+            "sentry-api-0-organization-users", kwargs={"organization_slug": organization.slug},
+        )
+
+        self.login_as(user=self.user)
+
+    def test_get(self):
+        response = self.client.get(self.url)
+        request = RequestFactory().get(self.url)
+
+        self.validate_schema(request, response)

+ 30 - 0
tests/apidocs/endpoints/organizations/test-repo-commits.py

@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+
+from tests.apidocs.util import APIDocsTestCase
+
+
+class OrganizationRepoCommitsDocs(APIDocsTestCase):
+    def setUp(self):
+        organization = self.create_organization()
+        project = self.create_project(name="foo", organization=organization, teams=[])
+        repo = self.create_repo(project=project, name="getsentry/sentry")
+        release = self.create_release(project=project)
+        self.create_commit(project=project, repo=repo, release=release)
+
+        self.url = reverse(
+            "sentry-api-0-organization-repository-commits",
+            kwargs={"organization_slug": organization.slug, "repo_id": repo.id},
+        )
+
+        self.login_as(user=self.user)
+
+    def test_get(self):
+        response = self.client.get(self.url)
+        request = RequestFactory().get(self.url)
+
+        self.validate_schema(request, response)

+ 35 - 0
tests/apidocs/endpoints/organizations/test-shortid.py

@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from django.core.urlresolvers import reverse
+from django.test.client import RequestFactory
+
+from tests.apidocs.util import APIDocsTestCase
+from sentry.testutils.helpers.datetime import before_now, iso_format
+
+
+class OrganizationShortIDDocs(APIDocsTestCase):
+    def setUp(self):
+        organization = self.create_organization()
+        project = self.create_project(name="foo", organization=organization, teams=[])
+        event = self.store_event(
+            data={
+                "event_id": "a" * 32,
+                "message": "oh no",
+                "timestamp": iso_format(before_now(seconds=1)),
+            },
+            project_id=project.id,
+        )
+        self.url = reverse(
+            "sentry-api-0-short-id-lookup",
+            kwargs={"organization_slug": organization.slug, "short_id": event.group.short_id},
+        )
+
+        self.login_as(user=self.user)
+
+    def test_get(self):
+        response = self.client.get(self.url)
+        request = RequestFactory().get(self.url)
+
+        self.validate_schema(request, response)