-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
106 additions
and
10 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
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
39 changes: 39 additions & 0 deletions
39
kobo/apps/organizations/tests/test_organization_users_api.py
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,39 @@ | ||
from django.contrib.auth.models import User | ||
from django.urls import reverse | ||
from model_bakery import baker | ||
|
||
from kpi.tests.kpi_test_case import BaseTestCase | ||
from kpi.urls.router_api_v2 import URL_NAMESPACE | ||
|
||
|
||
class OrganizationUserTestCase(BaseTestCase): | ||
fixtures = ['test_data'] | ||
URL_NAMESPACE = URL_NAMESPACE | ||
|
||
def setUp(self): | ||
self.user = User.objects.get(username='someuser') | ||
self.organization = baker.make( | ||
"organizations.Organization", id='org_abcd1234' | ||
) | ||
self.client.force_login(self.user) | ||
self.organization.add_user(self.user) | ||
self.url_list = reverse( | ||
self._get_endpoint('organization-users-list'), | ||
kwargs={"organization_id": self.organization.pk}, | ||
) | ||
|
||
def test_list(self): | ||
org_user = baker.make( | ||
"organizations.OrganizationUser", organization=self.organization | ||
) | ||
bad_org_user = baker.make("organizations.OrganizationUser") | ||
with self.assertNumQueries(3): | ||
res = self.client.get(self.url_list) | ||
self.assertContains(res, org_user.user_id) | ||
self.assertNotContains(res, bad_org_user.user_id) | ||
|
||
def test_create(self): | ||
data = {"is_admin": False, "email": "[email protected]"} | ||
with self.assertNumQueries(3): | ||
res = self.client.post(self.url_list, data) | ||
self.assertContains(res, data["email"], status_code=201) |
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,17 @@ | ||
from rest_framework import routers | ||
|
||
|
||
from .views import OrganizationViewSet, OrganizationUserViewSet | ||
|
||
|
||
router = routers.SimpleRouter() | ||
router.register( | ||
r'organizations', | ||
OrganizationViewSet, | ||
basename='organizations', | ||
) | ||
router.register( | ||
r'organizations/(?P<organization_id>[-\w]+)/users', | ||
OrganizationUserViewSet, | ||
basename='organization-users', | ||
) |
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