From e113433ae029c962d57cf83c1f3b02d809566941 Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Mon, 24 Oct 2022 19:12:48 -0400 Subject: [PATCH 01/14] create metadata permissions --- django/bosscore/models.py | 12 +++++++++++ django/bosscore/permissions.py | 31 +++++++++++++++++++++++++++ django/bosscore/request.py | 2 +- django/mgmt/utils.py | 38 +++++++++++++++++++++++++++------- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/django/bosscore/models.py b/django/bosscore/models.py index 87171974..47cc16e5 100644 --- a/django/bosscore/models.py +++ b/django/bosscore/models.py @@ -101,6 +101,10 @@ class Meta: ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), + ('add_metadata', 'Can add metadata for the channel'), + ('read_metadata', 'Can read metadata for the channel'), + ('update_metadata', 'Can read metadata for the channel'), + ('delete_metadata', 'Can delete metadata for the channel') ) @@ -226,6 +230,10 @@ class Meta: ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), + ('add_metadata', 'Can add metadata for the channel'), + ('read_metadata', 'Can read metadata for the channel'), + ('update_metadata', 'Can read metadata for the channel'), + ('delete_metadata', 'Can delete metadata for the channel') ) def __str__(self): @@ -333,6 +341,10 @@ class Meta: ('add_volumetric_data', 'Can add volumetric data for the channel'), ('read_volumetric_data', 'Can read volumetric data for the channel'), ('delete_volumetric_data', 'Can delete volumetric data for the channel'), + ('add_metadata', 'Can add metadata for the channel'), + ('read_metadata', 'Can read metadata for the channel'), + ('update_metadata', 'Can read metadata for the channel'), + ('delete_metadata', 'Can delete metadata for the channel'), ) def add_source(self, source): diff --git a/django/bosscore/permissions.py b/django/bosscore/permissions.py index d61166d4..d57f3b99 100644 --- a/django/bosscore/permissions.py +++ b/django/bosscore/permissions.py @@ -203,6 +203,8 @@ def check_resource_permissions(user, obj, method_type): Returns: bool. True if the user has the permission on the resource + + # dev note: with the addition of metadata permissions this function is no longer used """ if method_type == 'GET': permission = 'read' @@ -247,6 +249,35 @@ def check_data_permissions(user, obj, method_type): else: return False + @staticmethod + def check_metadata_permissions(user, obj, method_type): + """ + Check user permissions for a metadata entry + Args: + user: User name + obj: resource + method_type: Method type specified in the post + + Returns: + bool. True if the user has the permission on the resource + + """ + if method_type == 'GET': + permission = 'read_metadata' + elif method_type == 'POST': + permission = 'add_metadata' + elif method_type == 'PUT': + permission = 'update_metadata' + elif method_type == 'DELETE': + permission = 'delete_metadata' + else: + raise BossError("Unable to get permissions for this request", ErrorCodes.INVALID_POST_ARGUMENT) + + if permission in get_perms(user, obj): + return True + else: + return False + @staticmethod def check_object_permissions(user, obj, method_type): """ diff --git a/django/bosscore/request.py b/django/bosscore/request.py index 0403155c..c75bb99d 100644 --- a/django/bosscore/request.py +++ b/django/bosscore/request.py @@ -808,7 +808,7 @@ def check_permissions(self): else: raise BossError("Error encountered while checking permissions for this request", ErrorCodes.UNABLE_TO_VALIDATE) - perm = BossPermissionManager.check_resource_permissions(self.user, obj, self.method) + perm = BossPermissionManager.check_metadata_permissions(self.user, obj, self.method) elif self.service == 'reserve': perm = BossPermissionManager.check_object_permissions(self.user, self.channel, self.method) diff --git a/django/mgmt/utils.py b/django/mgmt/utils.py index 2dec2bfb..62c38b3b 100644 --- a/django/mgmt/utils.py +++ b/django/mgmt/utils.py @@ -28,6 +28,11 @@ def gen_key(ps): add_v = [t,t,f] del_v = [t,t,t] + # read_metadata, add_metadata, update_metadata, delete_metadata + read_m = [t, f, f, f] + add_m = [t, t, f, f] + del_m = [t, t, t, t] + def make_selection(p,is_chan): chk = [ 'read' in p, @@ -44,15 +49,26 @@ def make_selection(p,is_chan): 'delete_volumetric_data' in p, ] + chk_m = [ + 'read_metadata' in p, + 'add_metadata' in p, + 'update_metadata' in p, + 'delete_metadata' in p + ] + perm = None if not is_chan: - if chk == read: + if chk == read and chk_m == read_m: perm = "read" - elif chk == write: + elif chk == read and chk_m == add_m: + perm = "read+addmeta" + elif chk == read and chk_m == del_m: + perm = "read+meta" + elif chk == write and chk_m == del_m: perm = "write" - elif chk == admin: + elif chk == admin and chk_m == del_m: perm = "admin" - elif chk == admin_d: + elif chk == admin_d and chk_m == del_m: perm = "admin+delete" else: perm = "Raw: " + ", ".join(p) @@ -97,13 +113,19 @@ def set_perms(request, form, collection=None, experiment=None, channel=None, gro perms = data['permissions'] if perms == "read": - perms = ['read'] + perms = ['read', 'read_metadata'] + elif perms == "read+addmeta": + perms = ['read', 'read_metadata', 'add_metadata'] + elif perms == "read+fullmeta": + perms = ['read', 'read_metadata', 'update_metadata', 'add_metadata', 'delete_metadata'] elif perms == "write": - perms = ['read', 'add', 'update'] + perms = ['read', 'add', 'update', 'read_metadata', 'update_metadata', 'add_metadata', 'delete_metadata'] elif perms == "admin": - perms = ['read', 'add', 'update', 'assign_group', 'remove_group'] + perms = ['read', 'add', 'update', 'assign_group', 'remove_group', + 'read_metadata', 'update_metadata', 'add_metadata', 'delete_metadata'] elif perms == "admin+delete": - perms = ['read', 'add', 'update', 'delete', 'assign_group', 'remove_group'] + perms = ['read', 'add', 'update', 'delete', 'assign_group', 'remove_group', + 'read_metadata', 'update_metadata', 'add_metadata', 'delete_metadata'] else: raise Exception("Unknown permissions: " + perms) From 235e1a6e356fe8587aa0931b5a150980042b21f0 Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Tue, 25 Oct 2022 11:14:01 -0400 Subject: [PATCH 02/14] add permission groups to channels --- django/mgmt/utils.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/django/mgmt/utils.py b/django/mgmt/utils.py index 62c38b3b..a5d764db 100644 --- a/django/mgmt/utils.py +++ b/django/mgmt/utils.py @@ -73,13 +73,17 @@ def make_selection(p,is_chan): else: perm = "Raw: " + ", ".join(p) else: - if chk == read and chk_v == read_v: + if chk == read and chk_m == read_m and chk_v == read_v: perm = "read" - elif chk == write and chk_v == add_v: + elif chk == read and chk_m == add_m and chk_v == read_v: + perm = "read+addmeta" + elif chk == read and chk_m == del_m and chk_v == read_v: + perm = "read+meta" + elif chk == write and chk_m == del_m and chk_v == add_v: perm = "write" - elif chk == admin and chk_v == add_v: # make sure admin has proper permissions + elif chk == admin and chk_m == del_m and chk_v == add_v: perm = "admin" - elif chk == admin_d and chk_v == del_v: + elif chk == admin_d and chk_m == del_m and chk_v == del_v: perm = "admin+delete" else: perm = "Raw: " + ", ".join(p) From 612b5320a0aca247efec58cfc51c3da7b90a63d5 Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Wed, 26 Oct 2022 15:32:31 -0400 Subject: [PATCH 03/14] updates mysql version for circleci --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 788a5314..7de5e0be 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -117,7 +117,7 @@ jobs: docker: - image: circleci/python:3.9 - - image: circleci/mysql:5.6.51-ram + - image: circleci/mysql:5.7.37-ram environment: MYSQL_ROOT_PASSWORD: MICrONS MYSQL_DATABASE: microns From 6572a0061b3840b28955e414eda497c5e9728e5c Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Mon, 31 Oct 2022 11:14:31 -0400 Subject: [PATCH 04/14] updates numpy requirement --- requirements.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d4553baa..b4c16500 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,9 @@ djangorestframework==3.11.2 drf-yasg==1.17.1 Markdown==3.3.4 mysqlclient==1.4.6 -numpy==1.18.1 +# Upgrade numpy to fix C-header issue +# https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp +numpy==1.23.4 wheel==0.24.0 uWSGI==2.0.19.1 From 7c5904347ae3690d07709f2809c7026a852eb9bd Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 6 Nov 2022 23:23:38 +0000 Subject: [PATCH 05/14] adds migration file --- .../migrations/0010_auto_20221106_2226.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 django/bosscore/migrations/0010_auto_20221106_2226.py diff --git a/django/bosscore/migrations/0010_auto_20221106_2226.py b/django/bosscore/migrations/0010_auto_20221106_2226.py new file mode 100644 index 00000000..cac9e770 --- /dev/null +++ b/django/bosscore/migrations/0010_auto_20221106_2226.py @@ -0,0 +1,35 @@ +# Generated by Django 2.2.18 on 2022-11-06 22:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bosscore', '0009_auto_20210517_2146'), + ] + + operations = [ + migrations.AlterModelOptions( + name='channel', + options={'default_permissions': (), 'permissions': (('read', 'Can view resource'), ('update', 'Can update resource'), ('delete', 'Can delete resource'), ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), ('add_volumetric_data', 'Can add volumetric data for the channel'), ('read_volumetric_data', 'Can read volumetric data for the channel'), ('delete_volumetric_data', 'Can delete volumetric data for the channel'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), ('update_metadata', 'Can read metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'))}, + ), + migrations.AlterModelOptions( + name='collection', + options={'default_permissions': (), 'managed': True, 'permissions': (('read', 'Can view resource'), ('update', 'Can update resource'), ('delete', 'Can delete resource'), ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), ('update_metadata', 'Can read metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'))}, + ), + migrations.AlterModelOptions( + name='experiment', + options={'default_permissions': (), 'permissions': (('read', 'Can view resource'), ('update', 'Can update resource'), ('delete', 'Can delete resource'), ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), ('update_metadata', 'Can read metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'))}, + ), + migrations.AlterField( + model_name='channel', + name='cv_path', + field=models.CharField(blank=True, max_length=2000, null=True), + ), + migrations.AlterField( + model_name='channel', + name='downsample_arn', + field=models.CharField(max_length=4096, null=True), + ), + ] From fdaaf464c3823d5132b82c3b2e7aaa957bb6380c Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Sun, 6 Nov 2022 18:24:57 -0500 Subject: [PATCH 06/14] fixes permissions on mgmt app --- django/bosscore/permissions.py | 14 ++++++++++++++ django/mgmt/forms.py | 2 +- django/mgmt/utils.py | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/django/bosscore/permissions.py b/django/bosscore/permissions.py index d57f3b99..0d16a3f8 100644 --- a/django/bosscore/permissions.py +++ b/django/bosscore/permissions.py @@ -75,6 +75,13 @@ def add_permissions_primary_group(user, obj): assign_perm('delete', user_primary_group, obj) assign_perm('assign_group', user_primary_group, obj) assign_perm('remove_group', user_primary_group, obj) + + # Add metadata permissions for primary user + assign_perm('read_metadata', user_primary_group, obj) + assign_perm('add_metadata', user_primary_group, obj) + assign_perm('update_metadata', user_primary_group, obj) + assign_perm('delete_metadata', user_primary_group, obj) + if ct.model == 'channel': assign_perm('add_volumetric_data', user_primary_group, obj) assign_perm('read_volumetric_data', user_primary_group, obj) @@ -182,6 +189,13 @@ def add_permissions_admin_group(obj): assign_perm('delete', admin_group, obj) assign_perm('assign_group', admin_group, obj) assign_perm('remove_group', admin_group, obj) + + # Add metadata permissions for admin user + assign_perm('read_metadata', admin_group, obj) + assign_perm('add_metadata', admin_group, obj) + assign_perm('update_metadata', admin_group, obj) + assign_perm('delete_metadata', admin_group, obj) + if ct.model == 'channel': assign_perm('add_volumetric_data', admin_group, obj) assign_perm('read_volumetric_data', admin_group, obj) diff --git a/django/mgmt/forms.py b/django/mgmt/forms.py index efba4052..06220c35 100644 --- a/django/mgmt/forms.py +++ b/django/mgmt/forms.py @@ -242,7 +242,7 @@ def disable_non_admin_fields(self): def PermField(): #perms = ['read', 'add', 'update', 'delete', 'assign_group', 'remove_group'] #return forms.MultipleChoiceField(choices=[(c,c) for c in perms]) - perms = ['read', 'write', 'admin', 'admin+delete'] + perms = ['read', 'read+addmeta', 'read+fullmeta', 'write', 'admin', 'admin+delete'] return forms.ChoiceField(choices=[(c,c) for c in perms]) class ResourcePermissionsForm(forms.Form): diff --git a/django/mgmt/utils.py b/django/mgmt/utils.py index a5d764db..955c03ca 100644 --- a/django/mgmt/utils.py +++ b/django/mgmt/utils.py @@ -63,7 +63,7 @@ def make_selection(p,is_chan): elif chk == read and chk_m == add_m: perm = "read+addmeta" elif chk == read and chk_m == del_m: - perm = "read+meta" + perm = "read+fullmeta" elif chk == write and chk_m == del_m: perm = "write" elif chk == admin and chk_m == del_m: @@ -78,7 +78,7 @@ def make_selection(p,is_chan): elif chk == read and chk_m == add_m and chk_v == read_v: perm = "read+addmeta" elif chk == read and chk_m == del_m and chk_v == read_v: - perm = "read+meta" + perm = "read+fullmeta" elif chk == write and chk_m == del_m and chk_v == add_v: perm = "write" elif chk == admin and chk_m == del_m and chk_v == add_v: From f140f3b724ca97028fd844e92445ba1a61c216e6 Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Tue, 22 Nov 2022 22:55:24 -0500 Subject: [PATCH 07/14] adds docstring, deletes unused method --- django/bosscore/models.py | 6 +++--- django/bosscore/permissions.py | 31 ------------------------------- django/mgmt/utils.py | 10 +++++++++- 3 files changed, 12 insertions(+), 35 deletions(-) diff --git a/django/bosscore/models.py b/django/bosscore/models.py index 47cc16e5..15b57b93 100644 --- a/django/bosscore/models.py +++ b/django/bosscore/models.py @@ -103,7 +103,7 @@ class Meta: ('remove_group', 'Can remove groups permissions for the resource'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), - ('update_metadata', 'Can read metadata for the channel'), + ('update_metadata', 'Can update metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel') ) @@ -232,7 +232,7 @@ class Meta: ('remove_group', 'Can remove groups permissions for the resource'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), - ('update_metadata', 'Can read metadata for the channel'), + ('update_metadata', 'Can update metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel') ) @@ -343,7 +343,7 @@ class Meta: ('delete_volumetric_data', 'Can delete volumetric data for the channel'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), - ('update_metadata', 'Can read metadata for the channel'), + ('update_metadata', 'Can update metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'), ) diff --git a/django/bosscore/permissions.py b/django/bosscore/permissions.py index 0d16a3f8..37cace98 100644 --- a/django/bosscore/permissions.py +++ b/django/bosscore/permissions.py @@ -205,37 +205,6 @@ def add_permissions_admin_group(obj): raise BossError("Cannot assign permissions to the admin group because the group does not exist", ErrorCodes.GROUP_NOT_FOUND) - @staticmethod - def check_resource_permissions(user, obj, method_type): - """ - Check user permissions for a resource object - Args: - user: User name - obj: Obj - method_type: Method type specified in the request - - Returns: - bool. True if the user has the permission on the resource - - - # dev note: with the addition of metadata permissions this function is no longer used - """ - if method_type == 'GET': - permission = 'read' - elif method_type == 'POST': - permission = 'add' - elif method_type == 'PUT': - permission = 'update' - elif method_type == 'DELETE': - permission = 'delete' - else: - raise BossError("Unable to get permissions for this request", ErrorCodes.INVALID_POST_ARGUMENT) - - if permission in get_perms(user, obj): - return True - else: - return False - @staticmethod def check_data_permissions(user, obj, method_type): """ diff --git a/django/mgmt/utils.py b/django/mgmt/utils.py index 955c03ca..103a8ba2 100644 --- a/django/mgmt/utils.py +++ b/django/mgmt/utils.py @@ -33,7 +33,15 @@ def gen_key(ps): add_m = [t, t, f, f] del_m = [t, t, t, t] - def make_selection(p,is_chan): + def make_selection(p, is_chan): + """Returns a permission group or raw permissions based on the raw + permissions from the requesting user's group. + + Args: + p (list): list of raw permissions from the requestor's group + is_chan (bool): True if the requested resource is a channel + """ + chk = [ 'read' in p, 'add' in p, From 4bdf046b946b4c620d3e6cddc8711a20654ceccd Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Mon, 12 Dec 2022 14:03:44 -0500 Subject: [PATCH 08/14] exclude coordinate frames from metadata perms --- django/bosscore/permissions.py | 18 ++++++++++-------- django/bosscore/test/setup_db.py | 7 +++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/django/bosscore/permissions.py b/django/bosscore/permissions.py index 37cace98..8f7ab032 100644 --- a/django/bosscore/permissions.py +++ b/django/bosscore/permissions.py @@ -77,10 +77,11 @@ def add_permissions_primary_group(user, obj): assign_perm('remove_group', user_primary_group, obj) # Add metadata permissions for primary user - assign_perm('read_metadata', user_primary_group, obj) - assign_perm('add_metadata', user_primary_group, obj) - assign_perm('update_metadata', user_primary_group, obj) - assign_perm('delete_metadata', user_primary_group, obj) + if ct.model != 'coordinateframe': + assign_perm('read_metadata', user_primary_group, obj) + assign_perm('add_metadata', user_primary_group, obj) + assign_perm('update_metadata', user_primary_group, obj) + assign_perm('delete_metadata', user_primary_group, obj) if ct.model == 'channel': assign_perm('add_volumetric_data', user_primary_group, obj) @@ -191,10 +192,11 @@ def add_permissions_admin_group(obj): assign_perm('remove_group', admin_group, obj) # Add metadata permissions for admin user - assign_perm('read_metadata', admin_group, obj) - assign_perm('add_metadata', admin_group, obj) - assign_perm('update_metadata', admin_group, obj) - assign_perm('delete_metadata', admin_group, obj) + if ct.model != 'coordinateframe': + assign_perm('read_metadata', admin_group, obj) + assign_perm('add_metadata', admin_group, obj) + assign_perm('update_metadata', admin_group, obj) + assign_perm('delete_metadata', admin_group, obj) if ct.model == 'channel': assign_perm('add_volumetric_data', admin_group, obj) diff --git a/django/bosscore/test/setup_db.py b/django/bosscore/test/setup_db.py index 63cef3e5..7ec63b85 100644 --- a/django/bosscore/test/setup_db.py +++ b/django/bosscore/test/setup_db.py @@ -266,6 +266,13 @@ def add_permissions(group, obj): assign_perm('delete', user_primary_group, obj) assign_perm('assign_group', user_primary_group, obj) assign_perm('remove_group', user_primary_group, obj) + + if ct.model != 'coordinateframe': + assign_perm('read_metadata', user_primary_group, obj) + assign_perm('add_metadata', user_primary_group, obj) + assign_perm('update_metadata', user_primary_group, obj) + assign_perm('delete_metadata', user_primary_group, obj) + if ct.model == 'channel': assign_perm('add_volumetric_data', user_primary_group, obj) assign_perm('read_volumetric_data', user_primary_group, obj) From 78ffffd482783c12a76cfb6ab7e9e703d9511a73 Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Tue, 31 Jan 2023 13:47:41 -0500 Subject: [PATCH 09/14] update migration file --- django/bosscore/migrations/0010_auto_20221106_2226.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/django/bosscore/migrations/0010_auto_20221106_2226.py b/django/bosscore/migrations/0010_auto_20221106_2226.py index cac9e770..1c5ece73 100644 --- a/django/bosscore/migrations/0010_auto_20221106_2226.py +++ b/django/bosscore/migrations/0010_auto_20221106_2226.py @@ -12,15 +12,15 @@ class Migration(migrations.Migration): operations = [ migrations.AlterModelOptions( name='channel', - options={'default_permissions': (), 'permissions': (('read', 'Can view resource'), ('update', 'Can update resource'), ('delete', 'Can delete resource'), ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), ('add_volumetric_data', 'Can add volumetric data for the channel'), ('read_volumetric_data', 'Can read volumetric data for the channel'), ('delete_volumetric_data', 'Can delete volumetric data for the channel'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), ('update_metadata', 'Can read metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'))}, + options={'default_permissions': (), 'permissions': (('read', 'Can view resource'), ('update', 'Can update resource'), ('delete', 'Can delete resource'), ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), ('add_volumetric_data', 'Can add volumetric data for the channel'), ('read_volumetric_data', 'Can read volumetric data for the channel'), ('delete_volumetric_data', 'Can delete volumetric data for the channel'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), ('update_metadata', 'Can update metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'))}, ), migrations.AlterModelOptions( name='collection', - options={'default_permissions': (), 'managed': True, 'permissions': (('read', 'Can view resource'), ('update', 'Can update resource'), ('delete', 'Can delete resource'), ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), ('update_metadata', 'Can read metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'))}, + options={'default_permissions': (), 'managed': True, 'permissions': (('read', 'Can view resource'), ('update', 'Can update resource'), ('delete', 'Can delete resource'), ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), ('update_metadata', 'Can update metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'))}, ), migrations.AlterModelOptions( name='experiment', - options={'default_permissions': (), 'permissions': (('read', 'Can view resource'), ('update', 'Can update resource'), ('delete', 'Can delete resource'), ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), ('update_metadata', 'Can read metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'))}, + options={'default_permissions': (), 'permissions': (('read', 'Can view resource'), ('update', 'Can update resource'), ('delete', 'Can delete resource'), ('add', 'Can add resources '), ('assign_group', 'Can assign groups permissions for the resource'), ('remove_group', 'Can remove groups permissions for the resource'), ('add_metadata', 'Can add metadata for the channel'), ('read_metadata', 'Can read metadata for the channel'), ('update_metadata', 'Can update metadata for the channel'), ('delete_metadata', 'Can delete metadata for the channel'))}, ), migrations.AlterField( model_name='channel', From 0e21916c3357f3c20feffaf4f11a6ec2f96f331d Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Mon, 13 Feb 2023 13:58:17 -0500 Subject: [PATCH 10/14] fix public group post --- django/bosscore/views/views_permission.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django/bosscore/views/views_permission.py b/django/bosscore/views/views_permission.py index 7713cb23..22d2b11e 100644 --- a/django/bosscore/views/views_permission.py +++ b/django/bosscore/views/views_permission.py @@ -242,7 +242,7 @@ def post(self, request): try: # public group can only have read permission - if group_name == PUBLIC_GRP and not (set(perm_list).issubset({'read', 'read_volumetric_data'})): + if group_name == PUBLIC_GRP and not (set(perm_list).issubset({'read', 'read_volumetric_data', 'read_metadata'})): return BossHTTPError("The public group can only have read permissions", ErrorCodes.INVALID_POST_ARGUMENT) @@ -299,7 +299,7 @@ def patch(self, request): try: # public group can only have read permission - if group_name == PUBLIC_GRP and (len(perm_list) != 1 or perm_list[0] != 'read'): + if group_name == PUBLIC_GRP and (set(perm_list).issubset({'read', 'read_volumetric_data', 'read_metadata'})): return BossHTTPError("The public group can only have read permissions", ErrorCodes.INVALID_POST_ARGUMENT) # If the user is not a member or maintainer of the group, they cannot patch permissions From 3eeb031e32c5e64c833ea7142e12ff452bf50240 Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Thu, 16 Feb 2023 11:44:39 -0500 Subject: [PATCH 11/14] forgot the not --- django/bosscore/views/views_permission.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/bosscore/views/views_permission.py b/django/bosscore/views/views_permission.py index 22d2b11e..de9f58be 100644 --- a/django/bosscore/views/views_permission.py +++ b/django/bosscore/views/views_permission.py @@ -299,7 +299,7 @@ def patch(self, request): try: # public group can only have read permission - if group_name == PUBLIC_GRP and (set(perm_list).issubset({'read', 'read_volumetric_data', 'read_metadata'})): + if group_name == PUBLIC_GRP and not (set(perm_list).issubset({'read', 'read_volumetric_data', 'read_metadata'})): return BossHTTPError("The public group can only have read permissions", ErrorCodes.INVALID_POST_ARGUMENT) # If the user is not a member or maintainer of the group, they cannot patch permissions From 34c7046c9e9989c5579452efc4c696ffe62b4ecc Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Thu, 23 Feb 2023 10:57:18 -0500 Subject: [PATCH 12/14] fix int-tests --- .../test/int_test_ingest_manager.py | 33 +++++++++++-------- django/bossmeta/test/int_test_meta_views.py | 15 ++++----- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/django/bossingest/test/int_test_ingest_manager.py b/django/bossingest/test/int_test_ingest_manager.py index 9fac272e..e60e740d 100644 --- a/django/bossingest/test/int_test_ingest_manager.py +++ b/django/bossingest/test/int_test_ingest_manager.py @@ -95,19 +95,24 @@ def test_setup_ingest(self): class TestIntegrationBossIngestManager(BossIntegrationIngestManagerTestMixin, APITestCase): - def setUp(self): - # Randomize queue names. - NDQueue.test_mode = True - - # Get the config_data - self.user = User.objects.create_superuser(username='testuser1', email='test@test.com', password='testuser') - config_data = SetupTests().get_ingest_config_data_dict() - self.example_config_data = config_data - dbsetup = SetupTestDB() - dbsetup.set_user(self.user) - dbsetup.insert_ingest_test_data() - - def tearDown(self): - NDQueue.test_mode = False + def setUp(self): + # Log in user + self.client.force_login(self.user) + + # Randomize queue names. + NDQueue.test_mode = True + + # Get the config_data + self.example_config_data = SetupTests().get_ingest_config_data_dict() + + @classmethod + def setUpTestData(cls): + dbsetup = SetupTestDB() + cls.user = dbsetup.create_super_user(username='testuser1') + dbsetup.set_user(cls.user) + dbsetup.insert_ingest_test_data() + + def tearDown(self): + NDQueue.test_mode = False diff --git a/django/bossmeta/test/int_test_meta_views.py b/django/bossmeta/test/int_test_meta_views.py index 0df2171f..2e146634 100644 --- a/django/bossmeta/test/int_test_meta_views.py +++ b/django/bossmeta/test/int_test_meta_views.py @@ -38,18 +38,17 @@ class BossCoreMetaServiceViewIntegrationTests(MetaServiceViewTestsMixin, APITest Uses Vault and AWS's DynamoDB (as opposed to a local DynamoDB). """ user = None - + def setUp(self): - dbsetup = SetupTestDB() - dbsetup.create_super_user() - self.user = User.objects.create_superuser(username='testuser', email='test@test.com', password='testuser') - dbsetup.set_user(self.user) - self.client.force_login(self.user) - dbsetup.insert_test_data() - + @classmethod def setUpTestData(cls): + dbsetup = SetupTestDB() + cls.user = dbsetup.create_super_user(username='test_user') + dbsetup.set_user(cls.user) + dbsetup.insert_test_data() + # Load table info cfgfile = open('bosscore/dynamo_schema.json', 'r') tblcfg = json.load(cfgfile) From 05f76fd16cc77529f513c66bda45f8d288a19ef5 Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Thu, 23 Feb 2023 16:16:20 -0500 Subject: [PATCH 13/14] fix int test issue --- django/bosscore/test/setup_db.py | 58 ++++++++++--------- .../bossingest/test/int_test_ingest_views.py | 4 +- django/bossmeta/test/int_test_meta_views.py | 2 +- .../test/int_test_cutout_view_cloudvolume.py | 55 +++++++++--------- 4 files changed, 62 insertions(+), 57 deletions(-) diff --git a/django/bosscore/test/setup_db.py b/django/bosscore/test/setup_db.py index 7ec63b85..dfdedf13 100644 --- a/django/bosscore/test/setup_db.py +++ b/django/bosscore/test/setup_db.py @@ -142,13 +142,13 @@ def insert_test_data(self): self.add_coordinate_frame('cf1', 'Description for cf1', 0, 1000, 0, 1000, 0, 1000, 4, 4, 4) - self.add_experiment('col1', EXP1, 'cf1', NUM_HIERARCHY_LEVELS, 10, 1) - self.add_experiment('col1', EXP22, 'cf1', NUM_HIERARCHY_LEVELS, 500, 1) + self.add_experiment('col1', EXP1, 'cf1', 10, 500, 1) + self.add_experiment('col1', EXP22, 'cf1', NUM_HIERARCHY_LEVELS, 10, 1) self.add_experiment('col1', EXP_BASE_RES, 'cf1', NUM_HIERARCHY_LEVELS, 10, 1) self.add_experiment(COLL_NOT_PUBLIC, EXP_NOT_PUBLIC, 'cf1', NUM_HIERARCHY_LEVELS, 1, 1, public=False) self.add_channel('col1', EXP1, 'channel1', 0, 0, 'uint8', 'image') - self.add_channel('col1', EXP1, 'channel2', 0, 0, 'uint8', 'image') + self.add_channel('col1', EXP1, 'channel2', 0, 0, 'uint16', 'image') self.add_channel('col1', EXP1, 'channel3', 0, 0, 'uint64', 'annotation', ['channel1']) self.add_channel('col1', EXP_BASE_RES, CHAN_BASE_RES, 0, BASE_RESOLUTION, 'uint8', 'image') self.add_channel('col1', EXP1, 'layer1', 0, 0, 'uint64', 'annotation', ['channel1']) @@ -192,24 +192,24 @@ def insert_cloudvolume_test_data(self): """ Test data for cloudvolume integration. """ - self.add_collection('col1', 'Description for collection1') - self.add_coordinate_frame('cf1', 'Description for cf1', 0, 100000, 0, 100000, 0, 100000, 4, 4, 4) - self.add_experiment('col1', 'exp1', 'cf1', 10, 500, 1) + self.add_collection('col1-cvdb', 'Description for collection1') + self.add_coordinate_frame('cf1-cvdb', 'Description for cf1', 0, 100000, 0, 100000, 0, 100000, 4, 4, 4) + self.add_experiment('col1-cvdb', 'exp1', 'cf1-cvdb', 10, 500, 1) # Dev Note: Prepopulated cloudvolume layer for uint8 data located at this cloudpath - self.add_channel('col1', 'exp1', 'chan1', 0, 0, 'uint8', 'image', + self.add_channel('col1-cvdb', 'exp1', 'chan1', 0, 0, 'uint8', 'image', storage_type='cloudvol', bucket=CLOUD_VOL_BUCKET, cv_path=CVPATH_CHAN1) # Dev Note: Prepopulated cloudvolume layer for uint16 data located at this cloudpath - self.add_channel('col1', 'exp1', 'chan2', 0, 0, 'uint16', 'image', + self.add_channel('col1-cvdb', 'exp1', 'chan2', 0, 0, 'uint16', 'image', storage_type='cloudvol', bucket=CLOUD_VOL_BUCKET, cv_path=CVPATH_CHAN2) # Dev Note: Prepopulated cloudvolume layer for uint16 data located at this cloudpath - self.add_channel('col1', 'exp1', 'anno1', 0, 0, 'uint64', 'annotation', + self.add_channel('col1-cvdb', 'exp1', 'anno1', 0, 0, 'uint64', 'annotation', storage_type='cloudvol', bucket=CLOUD_VOL_BUCKET, cv_path=CVPATH_ANNO1) @@ -217,8 +217,8 @@ def insert_cloudvolume_test_data(self): def insert_ingest_test_data(self): self.add_collection('my_col_1', 'Description for collection1') - self.add_coordinate_frame('cf1', 'Description for cf1', 0, 100000, 0, 100000, 0, 100000, 4, 4, 4) - self.add_experiment('my_col_1', 'my_exp_1', 'cf1', 10, 500, 1) + self.add_coordinate_frame('cf2-ingest', 'cf2-ingest', 0, 100000, 0, 100000, 0, 100000, 4, 4, 4) + self.add_experiment('my_col_1', 'my_exp_1', 'cf2-ingest', 10, 500, 1) self.add_channel('my_col_1', 'my_exp_1', 'my_ch_1', 0, 0, 'uint8', 'image') def insert_iso_data(self): @@ -293,12 +293,13 @@ def add_collection(self, collection_name, description, public=False): Collection """ - col = Collection.objects.create(name=collection_name, description=description, creator=self.user, public=public) + col, created = Collection.objects.get_or_create(name=collection_name, description=description, creator=self.user, public=public) # Add a lookup key lkup_key = str(col.pk) bs_key = col.name - BossLookup.objects.create(lookup_key=lkup_key, boss_key=bs_key, collection_name=col.name) + if created: + BossLookup.objects.create(lookup_key=lkup_key, boss_key=bs_key, collection_name=col.name) # Give permissions to the users primary group primary_group = self.user.username + '-primary' @@ -327,7 +328,7 @@ def add_coordinate_frame(self, coordinate_frame, description, x_start, x_stop, y Coordinate Frame """ - cf = CoordinateFrame.objects.create(name=coordinate_frame, description=description, + cf, created = CoordinateFrame.objects.get_or_create(name=coordinate_frame, description=description, x_start=x_start, x_stop=x_stop, y_start=y_start, y_stop=y_stop, z_start=z_start, z_stop=z_stop, x_voxel_size=x_voxel_size, y_voxel_size=y_voxel_size, @@ -356,15 +357,16 @@ def add_experiment(self, collection_name, experiment_name, coordinate_name, num_ """ col = Collection.objects.get(name=collection_name) cf = CoordinateFrame.objects.get(name=coordinate_name) - exp = Experiment.objects.create(name=experiment_name, collection=col, coord_frame=cf, + exp, created = Experiment.objects.get_or_create(name=experiment_name, collection=col, coord_frame=cf, num_hierarchy_levels=num_hierarchy_levels, hierarchy_method=hierarchy_method, num_time_samples=num_time_samples, time_step=time_step, creator=self.user, public=public) - lkup_key = str(col.pk) + '&' + str(exp.pk) - bs_key = col.name + '&' + str(exp.name) - BossLookup.objects.create(lookup_key=lkup_key, boss_key=bs_key, collection_name=col.name, - experiment_name=exp.name) + if created: + lkup_key = str(col.pk) + '&' + str(exp.pk) + bs_key = col.name + '&' + str(exp.name) + BossLookup.objects.create(lookup_key=lkup_key, boss_key=bs_key, collection_name=col.name, + experiment_name=exp.name) # Give permissions to the users primary group primary_group = self.user.username + '-primary' @@ -404,7 +406,7 @@ def add_channel(self, collection_name, experiment_name, channel_name, col = Collection.objects.get(name=collection_name) exp = Experiment.objects.get(name=experiment_name, collection=col) - channel = Channel.objects.create(name=channel_name, experiment=exp, + channel, created = Channel.objects.get_or_create(name=channel_name, experiment=exp, default_time_sample=default_time_sample, base_resolution=base_resolution, type=channel_type, datatype=datatype, creator=self.user, public=public, storage_type=storage_type, bucket=bucket, cv_path=cv_path) @@ -419,11 +421,12 @@ def add_channel(self, collection_name, experiment_name, channel_name, # Set lookup key. base_lkup_key = str(col.pk) + '&' + str(exp.pk) + '&' + str(channel.pk) base_bs_key = col.name + '&' + exp.name + '&' + channel.name - BossLookup.objects.create(lookup_key=base_lkup_key, boss_key=base_bs_key, - collection_name=col.name, - experiment_name=exp.name, - channel_name=channel.name - ) + if created: + BossLookup.objects.create(lookup_key=base_lkup_key, boss_key=base_bs_key, + collection_name=col.name, + experiment_name=exp.name, + channel_name=channel.name + ) # Give permissions to the users primary group primary_group = self.user.username + '-primary' @@ -440,10 +443,11 @@ class DjangoSetupLayer(AWSSetupLayer): @classmethod def setUp(cls): # Create a user in django - cls.superuser = cls.django_setup_helper.create_super_user() - cls.user = cls.django_setup_helper.create_user('testuser') + cls.superuser = cls.django_setup_helper.create_super_user('django-superuser') + cls.user = cls.django_setup_helper.create_user('django-testuser') cls.django_setup_helper.add_role('resource-manager') cls.django_setup_helper.set_user(cls.user) # Populate django models DB cls.django_setup_helper.insert_spatialdb_test_data() + cls.django_setup_helper.insert_cloudvolume_test_data() \ No newline at end of file diff --git a/django/bossingest/test/int_test_ingest_views.py b/django/bossingest/test/int_test_ingest_views.py index 16a253bc..77c87b3b 100644 --- a/django/bossingest/test/int_test_ingest_views.py +++ b/django/bossingest/test/int_test_ingest_views.py @@ -353,8 +353,8 @@ class TestIntegrationBossIngestView(BossIngestViewTestMixin, APITestCase): def setUpTestData(cls): # Set the environment variable for the tests dbsetup = SetupTestDB() - cls.superuser = dbsetup.create_super_user() - cls.user = dbsetup.create_user('testuser') + cls.superuser = dbsetup.create_super_user('ingest-superuser') + cls.user = dbsetup.create_user('ingest-testuser') dbsetup.set_user(cls.user) dbsetup.insert_ingest_test_data() diff --git a/django/bossmeta/test/int_test_meta_views.py b/django/bossmeta/test/int_test_meta_views.py index 2e146634..1c42d153 100644 --- a/django/bossmeta/test/int_test_meta_views.py +++ b/django/bossmeta/test/int_test_meta_views.py @@ -45,7 +45,7 @@ def setUp(self): @classmethod def setUpTestData(cls): dbsetup = SetupTestDB() - cls.user = dbsetup.create_super_user(username='test_user') + cls.user = dbsetup.create_super_user(username='meta-superuser') dbsetup.set_user(cls.user) dbsetup.insert_test_data() diff --git a/django/bossspatialdb/test/int_test_cutout_view_cloudvolume.py b/django/bossspatialdb/test/int_test_cutout_view_cloudvolume.py index 5db01fa9..6e4b1562 100644 --- a/django/bossspatialdb/test/int_test_cutout_view_cloudvolume.py +++ b/django/bossspatialdb/test/int_test_cutout_view_cloudvolume.py @@ -21,7 +21,7 @@ from bossspatialdb.views import Cutout -from bosscore.test.setup_db import SetupTestDB +from bosscore.test.setup_db import DjangoSetupLayer from bosscore.error import BossError import numpy as np @@ -50,14 +50,14 @@ def test_channel_uint8_cuboid_aligned(self): # Create Request to get data you posted factory = APIRequestFactory() - request = factory.get('/' + version + '/cutout/col1/exp1/chan1/0/0:128/0:128/0:16/', + request = factory.get('/' + version + '/cutout/col1-cvdb/exp1/chan1/0/0:128/0:128/0:16/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request - response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='chan1', + response = Cutout.as_view()(request, collection='col1-cvdb', experiment='exp1', channel='chan1', resolution='0', x_range='0:128', y_range='0:128', z_range='0:16', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -80,14 +80,14 @@ def test_channel_uint8_cuboid_aligned_offset(self): # Create Request to get data you posted factory = APIRequestFactory() - request = factory.get('/' + version + '/cutout/col1/exp1/chan1/0/128:256/256:384/16:32/', + request = factory.get('/' + version + '/cutout/col1-cvdb/exp1/chan1/0/128:256/256:384/16:32/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request - response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='chan1', + response = Cutout.as_view()(request, collection='col1-cvdb', experiment='exp1', channel='chan1', resolution='0', x_range='128:256', y_range='256:384', z_range='16:32', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -111,14 +111,14 @@ def test_channel_uint8_cuboid_unaligned_offset(self): # Create Request to get data you posted factory = APIRequestFactory() - request = factory.get('/' + version + '/cutout/col1/exp1/chan1/0/140:692/256:384/7:31/', + request = factory.get('/' + version + '/cutout/col1-cvdb/exp1/chan1/0/140:692/256:384/7:31/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request - response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='chan1', + response = Cutout.as_view()(request, collection='col1-cvdb', experiment='exp1', channel='chan1', resolution='0', x_range='140:692', y_range='256:384', z_range='7:31', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -141,14 +141,14 @@ def test_channel_uint16_cuboid_aligned(self): # Create Request to get data you posted factory = APIRequestFactory() - request = factory.get('/' + version + '/cutout/col1/exp1/chan2/0/0:128/0:128/0:16/', + request = factory.get('/' + version + '/cutout/col1-cvdb/exp1/chan2/0/0:128/0:128/0:16/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request - response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='chan2', + response = Cutout.as_view()(request, collection='col1-cvdb', experiment='exp1', channel='chan2', resolution='0', x_range='0:128', y_range='0:128', z_range='0:16', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -170,14 +170,14 @@ def test_channel_uint16_cuboid_aligned_offset(self): # Create Request to get data you posted factory = APIRequestFactory() - request = factory.get('/' + version + '/cutout/col1/exp1/chan2/0/128:256/256:384/16:32/', + request = factory.get('/' + version + '/cutout/col1-cvdb/exp1/chan2/0/128:256/256:384/16:32/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request - response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='chan2', + response = Cutout.as_view()(request, collection='col1-cvdb', experiment='exp1', channel='chan2', resolution='0', x_range='128:256', y_range='256:384', z_range='16:32', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -200,14 +200,14 @@ def test_channel_uint16_cuboid_unaligned_offset(self): # Create Request to get data you posted factory = APIRequestFactory() - request = factory.get('/' + version + '/cutout/col1/exp1/chan2/0/140:692/256:384/7:31/', + request = factory.get('/' + version + '/cutout/col1-cvdb/exp1/chan2/0/140:692/256:384/7:31/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request - response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='chan2', + response = Cutout.as_view()(request, collection='col1-cvdb', experiment='exp1', channel='chan2', resolution='0', x_range='140:692', y_range='256:384', z_range='7:31', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -231,14 +231,14 @@ def test_channel_uint64_cuboid_aligned(self): # Create Request to get data you posted factory = APIRequestFactory() - request = factory.get('/' + version + '/cutout/col1/exp1/anno1/0/0:128/0:128/0:16/', + request = factory.get('/' + version + '/cutout/col1-cvdb/exp1/anno1/0/0:128/0:128/0:16/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request - response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='anno1', + response = Cutout.as_view()(request, collection='col1-cvdb', experiment='exp1', channel='anno1', resolution='0', x_range='0:128', y_range='0:128', z_range='0:16', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -261,14 +261,14 @@ def test_channel_uint64_cuboid_aligned_offset(self): # Create Request to get data you posted factory = APIRequestFactory() - request = factory.get('/' + version + '/cutout/col1/exp1/anno1/0/128:256/256:384/16:32/', + request = factory.get('/' + version + '/cutout/col1-cvdb/exp1/anno1/0/128:256/256:384/16:32/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request - response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='anno1', + response = Cutout.as_view()(request, collection='col1-cvdb', experiment='exp1', channel='anno1', resolution='0', x_range='128:256', y_range='256:384', z_range='16:32', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -291,14 +291,14 @@ def test_channel_uint64_cuboid_unaligned_offset(self): # Create Request to get data you posted factory = APIRequestFactory() - request = factory.get('/' + version + '/cutout/col1/exp1/anno1/0/140:692/256:384/7:31/', + request = factory.get('/' + version + '/cutout/col1-cvdb/exp1/anno1/0/140:692/256:384/7:31/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request - response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='anno1', + response = Cutout.as_view()(request, collection='col1-cvdb', experiment='exp1', channel='anno1', resolution='0', x_range='140:692', y_range='256:384', z_range='7:31', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -312,17 +312,18 @@ def test_channel_uint64_cuboid_unaligned_offset(self): np.testing.assert_array_equal(data_mat, offset_mat) class TestCutoutCloudVolumeInterfaceView(CutoutInterfaceViewCloudVolumeMixin, APITestCase): - + layer = DjangoSetupLayer + user = None + + def setUp(self): + """ Copy params from the Layer setUpClass + """ + # Setup config + self.user = self.layer.user + @classmethod def setUpClass(cls): """ Set everything up for testing """ - # Create a user - cls.dbsetup = SetupTestDB() - cls.user = cls.dbsetup.create_user('testuser') - - # Populate DB - cls.dbsetup.insert_cloudvolume_test_data() - # Set up external cloudvolume instance # TODO: Fails if cloudvolume not already set up. Make method that creates new cloudvolume. cls.vol_uint8 = CloudVolume(f"s3://{TEST_BUCKET}/col1/exp1/chan1", use_https=True) From fd95f5091d1e9b839490109e52e5f00ae3d45c78 Mon Sep 17 00:00:00 2001 From: Daniel Xenes Date: Thu, 23 Feb 2023 16:39:04 -0500 Subject: [PATCH 14/14] move cv resources to setup method --- .../test/int_test_cutout_view_cloudvolume.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/django/bossspatialdb/test/int_test_cutout_view_cloudvolume.py b/django/bossspatialdb/test/int_test_cutout_view_cloudvolume.py index 6e4b1562..f05dca72 100644 --- a/django/bossspatialdb/test/int_test_cutout_view_cloudvolume.py +++ b/django/bossspatialdb/test/int_test_cutout_view_cloudvolume.py @@ -320,16 +320,6 @@ def setUp(self): """ # Setup config self.user = self.layer.user - - @classmethod - def setUpClass(cls): - """ Set everything up for testing """ - # Set up external cloudvolume instance - # TODO: Fails if cloudvolume not already set up. Make method that creates new cloudvolume. - cls.vol_uint8 = CloudVolume(f"s3://{TEST_BUCKET}/col1/exp1/chan1", use_https=True) - cls.vol_uint16 = CloudVolume(f"s3://{TEST_BUCKET}/col1/exp1/chan2", use_https=True) - cls.vol_uint64 = CloudVolume(f"s3://{TEST_BUCKET}/col1/exp1/anno1", use_https=True) - - @classmethod - def tearDownClass(cls): - pass \ No newline at end of file + self.vol_uint8 = CloudVolume(f"s3://{TEST_BUCKET}/col1/exp1/chan1", use_https=True) + self.vol_uint16 = CloudVolume(f"s3://{TEST_BUCKET}/col1/exp1/chan2", use_https=True) + self.vol_uint64 = CloudVolume(f"s3://{TEST_BUCKET}/col1/exp1/anno1", use_https=True)