-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2647 from onaio/update-organization-serializer
Add email field to the organization serializer
- Loading branch information
Showing
5 changed files
with
68 additions
and
8 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 |
---|---|---|
|
@@ -201,6 +201,7 @@ def _org_create(self, org_data=None): | |
response = view(request) | ||
self.assertEqual(response.status_code, 200) | ||
data = { | ||
"email": "[email protected]", | ||
"org": "denoinc", | ||
"name": "Dennis", | ||
"city": "Denoville", | ||
|
@@ -224,6 +225,7 @@ def _org_create(self, org_data=None): | |
data["url"] = f"http://testserver/api/v1/orgs/{data['org']}" | ||
data["user"] = f"http://testserver/api/v1/users/{data['org']}" | ||
data["creator"] = "http://testserver/api/v1/users/bob" | ||
data.pop("email") | ||
self.assertDictContainsSubset(data, response.data) | ||
# pylint: disable=attribute-defined-outside-init | ||
self.company_data = response.data | ||
|
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
from builtins import str as text | ||
from unittest.mock import patch | ||
|
||
from django.contrib.auth.models import User, timezone | ||
from django.contrib.auth.models import User, timezone, AnonymousUser | ||
from django.core.cache import cache | ||
from django.test.utils import override_settings | ||
|
||
|
@@ -89,6 +89,7 @@ def test_orgs_list(self): | |
self.assertNotEqual(response.get("Cache-Control"), None) | ||
self.assertEqual(response.status_code, 200) | ||
del self.company_data["metadata"] | ||
del self.company_data["email"] | ||
self.assertEqual(response.data, [self.company_data]) | ||
|
||
# inactive organization | ||
|
@@ -113,6 +114,7 @@ def test_orgs_list_for_authenticated_user(self): | |
self.assertNotEqual(response.get("Cache-Control"), None) | ||
self.assertEqual(response.status_code, 200) | ||
del self.company_data["metadata"] | ||
del self.company_data["email"] | ||
self.assertEqual(response.data, [self.company_data]) | ||
|
||
def test_orgs_list_shared_with_user(self): | ||
|
@@ -194,6 +196,8 @@ def test_orgs_get_not_creator(self): | |
response = view(request, user="denoinc") | ||
self.assertNotEqual(response.get("Cache-Control"), None) | ||
self.assertEqual(response.status_code, 200) | ||
del self.company_data['email'] | ||
del self.company_data['metadata'] | ||
self.assertEqual(response.data, self.company_data) | ||
self.assertIn("users", list(response.data)) | ||
for user in response.data["users"]: | ||
|
@@ -207,6 +211,8 @@ def test_orgs_get_anon(self): | |
response = view(request, user="denoinc") | ||
self.assertNotEqual(response.get("Cache-Control"), None) | ||
self.assertEqual(response.status_code, 200) | ||
del self.company_data["email"] | ||
del self.company_data['metadata'] | ||
self.assertEqual(response.data, self.company_data) | ||
self.assertIn("users", list(response.data)) | ||
for user in response.data["users"]: | ||
|
@@ -216,12 +222,14 @@ def test_orgs_get_anon(self): | |
def test_orgs_create(self): | ||
self._org_create() | ||
self.assertTrue(self.organization.user.is_active) | ||
self.assertEqual(self.organization.user.email, "[email protected]") | ||
|
||
def test_orgs_create_without_name(self): | ||
data = { | ||
"org": "denoinc", | ||
"city": "Denoville", | ||
"country": "US", | ||
"email": "[email protected]", | ||
"home_page": "deno.com", | ||
"twitter": "denoinc", | ||
"description": "", | ||
|
@@ -235,6 +243,29 @@ def test_orgs_create_without_name(self): | |
response = self.view(request) | ||
self.assertEqual(response.data, {"name": ["This field is required."]}) | ||
|
||
def test_org_create_and_fetch_by_admin_user(self): | ||
org_email = "[email protected]" | ||
data = { | ||
"name": "denoinc", | ||
"org": "denoinc", | ||
"city": "Denoville", | ||
"country": "US", | ||
"home_page": "deno.com", | ||
"twitter": "denoinc", | ||
"email": org_email, | ||
"description": "", | ||
"address": "", | ||
"phonenumber": "", | ||
"require_auth": False, | ||
} | ||
request = self.factory.post( | ||
"/", data=json.dumps(data), content_type="application/json" | ||
) | ||
request.user = self.user | ||
response = self.view(request) | ||
self.assertEqual(response.status_code, 201) | ||
self.assertEqual(response.data['email'], org_email) | ||
|
||
def test_org_create_with_anonymous_user(self): | ||
data = { | ||
"name": "denoinc", | ||
|
@@ -389,6 +420,7 @@ def test_member_sees_orgs_added_to(self): | |
} | ||
) | ||
del expected_data["metadata"] | ||
del expected_data['email'] | ||
|
||
request = self.factory.get("/", **self.extra) | ||
response = view(request) | ||
|
@@ -420,6 +452,8 @@ def test_role_for_org_non_owner(self): | |
request = self.factory.get("/", **self.extra) | ||
response = view(request, user="denoinc") | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue('email' in response.data) | ||
self.assertEqual(response.data['email'], '[email protected]') | ||
self.assertIn("users", list(response.data)) | ||
|
||
for user in response.data["users"]: | ||
|
@@ -432,6 +466,21 @@ def test_role_for_org_non_owner(self): | |
) | ||
self.assertEqual(role, expected_role) | ||
|
||
# getting profile as a member | ||
request = self.factory.get("/", **self.extra) | ||
request.user = User.objects.get(username="aboy") | ||
response = view(request, user="denoinc") | ||
self.assertEqual(response.status_code, 200) | ||
|
||
# get profile as a anonymous user | ||
request = self.factory.get("/", **self.extra) | ||
request.user = AnonymousUser() | ||
request.headers = None | ||
request.META['HTTP_AUTHORIZATION'] = "" | ||
response = view(request, user="denoinc") | ||
self.assertEqual(response.status_code, 200) | ||
self.assertFalse('email' in response.data) | ||
|
||
def test_add_members_to_org_with_anonymous_user(self): | ||
self._org_create() | ||
view = OrganizationProfileViewSet.as_view({"post": "members"}) | ||
|
@@ -561,6 +610,7 @@ def test_orgs_create_with_mixed_case(self): | |
"home_page": "deno.com", | ||
"twitter": "denoinc", | ||
"description": "", | ||
"email": "[email protected]", | ||
"address": "", | ||
"phonenumber": "", | ||
"require_auth": False, | ||
|
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