-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jkmarx/groups api v2 #3265
Merged
Merged
Jkmarx/groups api v2 #3265
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
380e510
Add group v2 api.
jkmarx f7cd97e
Update group api for client.
jkmarx 40f9b0b
Add owner info to data_set api.
jkmarx 3c77cf8
Add user_perms to data_set v2 api.
jkmarx ca1eca6
Fix unit tests and formatting.
jkmarx b157414
Add api unit tests.
jkmarx e2983f4
Resolve merge conflicts.
jkmarx 8ac4b3f
Refactor per style guide and remove unused lookup field.
jkmarx af1d299
Minor styling fixes.
jkmarx File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -35,8 +35,9 @@ | |
from .serializers import DataSetSerializer, UserSerializer | ||
|
||
from .views import (AnalysesViewSet, DataSetsViewSet, EventViewSet, | ||
ObtainAuthTokenValidSession, SiteProfileViewSet, | ||
UserProfileViewSet, WorkflowViewSet, user) | ||
GroupViewSet, ObtainAuthTokenValidSession, | ||
SiteProfileViewSet, UserProfileViewSet, WorkflowViewSet, | ||
user) | ||
|
||
cache = memcache.Client(["127.0.0.1:11211"]) | ||
|
||
|
@@ -305,6 +306,36 @@ def test_get_data_set_returns_file_count(self): | |
self.assertEqual(get_ds_response.data.get('file_count'), | ||
self.data_set.get_file_count()) | ||
|
||
def test_get_data_set_returns_owner(self): | ||
get_request = self.factory.get(urljoin(self.url_root, | ||
self.data_set.uuid)) | ||
get_request.user = self.user | ||
get_ds_response = self.get_ds_view(get_request, self.data_set.uuid) | ||
self.assertEqual( | ||
get_ds_response.data.get('owner').get('profile').get('uuid'), | ||
self.user.profile.uuid | ||
) | ||
|
||
def test_get_data_set_returns_user_perms_for_owner(self): | ||
get_request = self.factory.get(urljoin(self.url_root, | ||
self.data_set.uuid)) | ||
get_request.user = self.user | ||
get_ds_response = self.get_ds_view(get_request, self.data_set.uuid) | ||
response_perms = get_ds_response.data.get('user_perms') | ||
self.assertEqual(True, response_perms.get('change')) | ||
self.assertEqual(True, response_perms.get('read')) | ||
self.assertEqual(True, response_perms.get('read_meta')) | ||
|
||
def test_get_public_data_set_returns_user_perms_for_anon(self): | ||
self.data_set.share(ExtendedGroup.objects.public_group()) | ||
get_request = self.factory.get(urljoin(self.url_root, | ||
self.data_set.uuid)) | ||
get_ds_response = self.get_ds_view(get_request, self.data_set.uuid) | ||
response_perms = get_ds_response.data.get('user_perms') | ||
self.assertEqual(False, response_perms.get('change')) | ||
self.assertEqual(True, response_perms.get('read')) | ||
self.assertEqual(True, response_perms.get('read_meta')) | ||
|
||
def test_dataset_delete_successful(self): | ||
delete_view = DataSetsViewSet.as_view({'delete': 'destroy'}) | ||
self.assertEqual(DataSet.objects.all().count(), 4) | ||
|
@@ -816,6 +847,91 @@ def test_is_owner_reflects_actual_owner_with_admin_requester(self): | |
self.assertFalse(data_set["is_owner"]) | ||
|
||
|
||
class GroupApiV2Tests(APIV2TestCase): | ||
def setUp(self): | ||
super(GroupApiV2Tests, self).setUp( | ||
api_base_name="groups/", | ||
view=GroupViewSet.as_view({'get': 'list'}) | ||
) | ||
self.data_set = create_dataset_with_necessary_models(user=self.user) | ||
self.group = ExtendedGroup.objects.create(name="Test Group") | ||
self.group_2 = ExtendedGroup.objects.create(name="Test Group 2") | ||
self.group.user_set.add(self.user) | ||
self.group_2.user_set.add(self.user) | ||
self.data_set.share(self.group) | ||
self.data_set.share(self.group_2) | ||
|
||
def test_get_groups_with_ds_uuid_returns_401_for_anon(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd expand |
||
get_request = self.factory.get(self.url_root, | ||
{'dataSetUuid': self.data_set.uuid}) | ||
get_response = self.view(get_request) | ||
self.assertEqual(get_response.status_code, 401) | ||
|
||
def test_get_groups_invalid_ds_uuid_returns_404(self): | ||
get_request = self.factory.get(self.url_root, | ||
{'dataSetUuid': 'xxx2'}) | ||
get_response = self.view(get_request) | ||
self.assertEqual(get_response.status_code, 404) | ||
|
||
def test_get_groups_with_ds_uuid_returns_correct_groups(self): | ||
get_request = self.factory.get(self.url_root, | ||
{'dataSetUuid': self.data_set.uuid}) | ||
get_request.user = self.user | ||
get_response = self.view(get_request) | ||
self.assertEqual(len(get_response.data), 2) | ||
group_uuid_list = [self.group.uuid, self.group_2.uuid] | ||
self.assertIn(get_response.data[0].get('uuid'), group_uuid_list) | ||
self.assertIn(get_response.data[1].get('uuid'), group_uuid_list) | ||
|
||
def test_get_groups_with_ds_uuid_returns_public_group(self): | ||
public_group = ExtendedGroup.objects.public_group() | ||
self.data_set.share(public_group) | ||
get_request = self.factory.get(self.url_root, | ||
{'dataSetUuid': self.data_set.uuid}) | ||
get_request.user = self.user | ||
get_response = self.view(get_request) | ||
self.assertEqual(len(get_response.data), 3) | ||
group_uuid_list = [get_response.data[0].get('id'), | ||
get_response.data[1].get('id'), | ||
get_response.data[2].get('id')] | ||
self.assertIn(public_group.id, group_uuid_list) | ||
|
||
def test_get_groups_with_ds_uuid_has_name_field(self): | ||
self.data_set.unshare(self.group_2) | ||
get_request = self.factory.get(self.url_root, | ||
{'dataSetUuid': self.data_set.uuid}) | ||
get_request.user = self.user | ||
get_response = self.view(get_request) | ||
self.assertEqual(self.group.name, get_response.data[0].get('name')) | ||
|
||
def test_get_groups_with_ds_uuid_has_id_field(self): | ||
self.data_set.unshare(self.group_2) | ||
get_request = self.factory.get(self.url_root, | ||
{'dataSetUuid': self.data_set.uuid}) | ||
get_request.user = self.user | ||
get_response = self.view(get_request) | ||
self.assertEqual(self.group.id, get_response.data[0].get('id')) | ||
|
||
def test_get_groups_with_ds_uuid_has_uuid(self): | ||
self.data_set.unshare(self.group_2) | ||
get_request = self.factory.get(self.url_root, | ||
{'dataSetUuid': self.data_set.uuid}) | ||
get_request.user = self.user | ||
get_response = self.view(get_request) | ||
self.assertEqual(self.group.uuid, get_response.data[0].get('uuid')) | ||
|
||
def test_get_groups_with_ds_uuid_has_correct_perms_field(self): | ||
self.data_set.unshare(self.group_2) | ||
get_request = self.factory.get(self.url_root, | ||
{'dataSetUuid': self.data_set.uuid}) | ||
get_request.user = self.user | ||
get_response = self.view(get_request) | ||
response_perms = get_response.data[0].get('perms') | ||
self.assertEqual(False, response_perms.get('change')) | ||
self.assertEqual(True, response_perms.get('read')) | ||
self.assertEqual(True, response_perms.get('read_meta')) | ||
|
||
|
||
class AnalysisApiV2Tests(APIV2TestCase): | ||
|
||
def setUp(self): | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
'use strict'; | ||
/** | ||
* Group V2 Service | ||
* @namespace groupV2Service | ||
* @desc Service to query groups API with a data set uuid | ||
* @memberOf refineryApp | ||
*/ | ||
(function () { | ||
'use strict'; | ||
|
||
function GroupFactory ($resource, settings) { | ||
return $resource( | ||
settings.appRoot + settings.refineryApi + '/groups/:uuid/', | ||
{ | ||
uuid: '@uuid', | ||
format: 'json' | ||
}, | ||
{ | ||
query: { | ||
method: 'GET', | ||
isArray: false | ||
angular | ||
.module('refineryApp') | ||
.factory('groupService', groupService); | ||
|
||
groupService.$inject = ['$resource', 'settings']; | ||
|
||
function groupService ($resource, settings) { | ||
var groups = $resource( | ||
settings.appRoot + settings.refineryApiV2 + '/groups/', | ||
{}, | ||
{ | ||
query: { | ||
method: 'GET', | ||
isArray: true, | ||
} | ||
} | ||
} | ||
); | ||
} | ||
); | ||
|
||
angular | ||
.module('refineryApp') | ||
.factory('groupService', ['$resource', 'settings', GroupFactory]); | ||
return groups; | ||
} | ||
})(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two could fit on one line?