def test_unauthorized(self): """It should return a "Permission Denied" error. """ resource = self.factory(workspace=self.workspace, object_permissions_enabled=True) did = helpers.to_global_id('DatastoreType', resource.pk) oid = helpers.to_global_id('UserType', self.users['MEMBER'].pk) privileges = [ 'view_datastore', 'change_datastore_metadata', 'change_datastore_settings', 'change_datastore_connection', 'delete_datastore', ] response = self.execute(variables={ 'id': did, 'objectId': oid, 'privileges': privileges, }) self.assertPermissionDenied(response) self.assertInstanceDoesNotExist( audit.Activity, verb='updated access privileges to', **serializers.get_audit_kwargs(resource), )
def test_disabled_with_object_permissions(self): """It should permanently delete the datastore. """ resource = self.factory(workspace=self.workspace, object_permissions_enabled=True) globalid = helpers.to_global_id('DatastoreType', resource.pk) resource.assign_perm(self.user, 'change_datastore_access') response = self.execute(variables={'id': globalid}) response = response['data'][self.operation] self.assertEqual(response, { 'isEnabled': False, 'errors': None, }) self.assertInstanceUpdated( instance=resource, object_permissions_enabled=False, ) self.assertInstanceCreated( audit.Activity, verb='disabled limited access to', **serializers.get_audit_kwargs(resource), )
def test_valid_with_user_object_permission(self): """It should update permissions on an object. """ resource = self.factory(workspace=self.workspace, object_permissions_enabled=True) resource.assign_perm(self.user, 'change_datastore_access') did = helpers.to_global_id('DatastoreType', resource.pk) oid = helpers.to_global_id('UserType', self.users['OWNER'].pk) privileges = [ 'view_datastore', 'change_datastore_metadata', 'change_datastore_settings', 'change_datastore_connection', 'delete_datastore', ] response = self.execute(variables={'id': did, 'objectId': oid, 'privileges': privileges}) response = response['data'][self.operation] self.assertOk(response) for privilege in privileges: self.assertTrue(self.users['OWNER'].has_perm(privilege, resource)) self.assertInstanceCreated( audit.Activity, verb='updated access privileges to', **serializers.get_audit_kwargs(resource), )
def test_valid_with_group_object_permission(self): """It should update permissions on an object. """ group = factories.GroupFactory(workspace_id=self.workspace.id) group.user_set.add(self.users['MEMBER']) resource = self.factory(workspace=self.workspace, object_permissions_enabled=True) resource.assign_perm(group, 'change_datastore_access') did = helpers.to_global_id('DatastoreType', resource.pk) oid = helpers.to_global_id('GroupType', group.pk) privileges = [ 'view_datastore', 'change_datastore', 'change_datastore_access', ] response = self.execute(variables={'id': did, 'objectId': oid, 'privileges': privileges}) response = response['data'][self.operation] self.assertOk(response) for privilege in privileges: self.assertTrue(self.users['MEMBER'].has_perm(privilege, resource)) self.assertInstanceCreated( audit.Activity, verb='updated access privileges to', **serializers.get_audit_kwargs(resource), )
def execute_success_test_case(self): """It should permanently updates the datastore. """ variables = { 'id': self.global_id, 'name': 'Data Warehouse', } response = self.execute(variables=variables) response = response['data'][self.operation] self.assertEqual(response, { 'datastore': { 'id': self.global_id, 'name': variables['name'], 'tags': self.resource_kwargs['tags'], }, 'errors': None, }) self.assertInstanceUpdated(self.resource, name=variables['name']) self.assertInstanceCreated( audit.Activity, verb='updated', **serializers.get_audit_kwargs(self.resource), )
def execute_success_test_case(self): """It should update the column. """ variables = { 'id': self.global_id, 'shortDesc': 'Hello, is it me you are looking for?', 'readme': 'Something else random', } response = self.execute(variables=variables) response = response['data'][self.operation] self.assertEqual(response, { 'column': { 'id': self.global_id, 'name': 'accounts', 'shortDesc': variables['shortDesc'], 'readme': variables['readme'], }, 'errors': None, }) self.assertInstanceUpdated( instance=self.resource, short_desc=variables['shortDesc'], ) self.assertInstanceCreated( audit.Activity, verb='updated', **serializers.get_audit_kwargs(self.resource), )
def test_unauthorized(self): """It should return a "Permission Denied" error. """ resource = self.factory(workspace=self.workspace, object_permissions_enabled=False) globalid = helpers.to_global_id('DatastoreType', resource.pk) response = self.execute(variables={'id': globalid}) self.assertPermissionDenied(response) self.assertInstanceDoesNotExist( audit.Activity, verb='enabled limited access to', **serializers.get_audit_kwargs(resource), )
def execute_success_test_case(self, resource): """It should update the datastore. """ globalid = helpers.to_global_id('DatastoreType', resource.pk) d_customfield = self.workspace.custom_fields.filter( content_type__model="datastore", ).first() t_customfield = self.workspace.custom_fields.filter( content_type__model="table", ).first() variables = { 'id': globalid, 'disabledDatastoreProperties': [ d_customfield.pk, ], 'disabledTableProperties': [ t_customfield.pk, ], } response = self.execute(variables=variables) response = response['data'][self.operation] self.assertEqual(response, { 'datastore': { 'id': globalid, 'disabledDatastoreProperties': variables['disabledDatastoreProperties'], 'disabledTableProperties': variables['disabledTableProperties'], }, 'errors': None, }) self.assertInstanceUpdated( resource, disabled_datastore_properties=variables['disabledDatastoreProperties'], disable_table_properties=variables['disabledTableProperties'], ) self.assertInstanceCreated( audit.Activity, verb='updated allowed properties', **serializers.get_audit_kwargs(resource), )
def execute_success_test_case(self): """It should permanently updates the datastore. """ variables = { 'id': self.global_id, 'port': 5432, 'username': '******' } response = self.execute(variables=variables) response = response['data'][self.operation] self.assertEqual(response, { 'datastore': { 'id': self.global_id, 'jdbcConnection': { 'engine': self.resource.engine, 'host': self.resource_kwargs['host'], 'username': variables['username'], 'database': self.resource_kwargs['database'], 'port': variables['port'], }, 'sshConfig': { 'isEnabled': self.resource.ssh_enabled, 'host': self.resource.ssh_host, 'user': self.resource.ssh_user, 'port': self.resource.ssh_port, } }, 'errors': None, }) self.assertInstanceUpdated( instance=self.resource, username=variables['username'], port=variables['port'], ) self.assertInstanceCreated( audit.Activity, verb='updated', **serializers.get_audit_kwargs(self.resource), )
def test_invalid(self): """It should update the datastore. """ variables = { 'id': self.global_id, 'port': -4000, 'host': '', 'username': ''.join(['a' for i in range(512)]), } response = self.execute(variables=variables) response = response['data'][self.operation] self.assertEqual(response, { 'datastore': None, 'errors': [ { 'resource': 'Datastore', 'field': 'username', 'code': 'max_length', }, { 'resource': 'Datastore', 'field': 'port', 'code': 'min_value', }, ] }) self.assertInstanceNotUpdated( instance=self.resource, host=variables['host'], username=variables['username'], port=variables['port'], ) self.assertInstanceDoesNotExist( audit.Activity, verb='updated', **serializers.get_audit_kwargs(self.resource), )