Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions qiita_pet/handlers/study_handlers/listing_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ def _build_study_info(user, search_type, study_proc=None, proc_samples=None):
build_samples = True

# get list of studies for table
user_study_set = user.user_studies.union(user.shared_studies)
if search_type == 'user':
user_study_set = user.user_studies.union(user.shared_studies)
if user.level == 'admin':
user_study_set = (user_study_set |
Study.get_by_status('sandbox') |
Study.get_by_status('private'))
study_set = user_study_set - Study.get_by_status('public')
Study.get_by_status('private') -
Study.get_by_status('public'))
study_set = user_study_set
elif search_type == 'public':
study_set = Study.get_by_status('public')
study_set = Study.get_by_status('public') - user_study_set
else:
raise ValueError('Not a valid search type')
if study_proc is not None:
Expand Down
27 changes: 27 additions & 0 deletions qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,36 @@ def setUp(self):
self.exp = [self.single_exp]

def test_build_study_info(self):
for a in Study(1).artifacts():
a.visibility = 'private'

obs = _build_study_info(User('test@foo.bar'), 'user')
self.assertEqual(obs, self.exp)

obs = _build_study_info(User('test@foo.bar'), 'public')
self.assertEqual(obs, [])

obs = _build_study_info(User('demo@microbio.me'), 'public')
self.assertEqual(obs, [])

# make all the artifacts public - (1) the only study in the tests,
for a in Study(1).artifacts():
a.visibility = 'public'
self.exp[0]['status'] = 'public'

obs = _build_study_info(User('test@foo.bar'), 'user')
self.assertEqual(obs, self.exp)

obs = _build_study_info(User('test@foo.bar'), 'public')
self.assertEqual(obs, [])

obs = _build_study_info(User('demo@microbio.me'), 'public')
self.assertEqual(obs, self.exp)

# return to it's private status
for a in Study(1).artifacts():
a.visibility = 'private'

def test_build_study_info_erros(self):
with self.assertRaises(IncompetentQiitaDeveloperError):
_build_study_info(User('test@foo.bar'), 'user', study_proc={})
Expand Down