Example #1
0
 def setUp(self):
     self.asset = Asset(content={
         'survey': [
             {u'type':'text', u'name': 'q1',
                 u'label': 'Q1.',}
             ]
         })
 def setUp(self):
     self.asset = Asset(content={
         'survey': [
             {u'type':'text', u'name': 'q1',
                 u'label': 'Q1.',}
             ]
         })
Example #3
0
    def _validate_permission(self, codename, suffix=None):
        """
        Validates if `codename` can be assigned on `Asset`s.
        Search can be restricted to assignable codenames which end with `prefix`

        :param codename: str. See `Asset.ASSIGNABLE_PERMISSIONS
        :param suffix: str.
        :return: bool.
        """
        return (codename in Asset.get_assignable_permissions(with_partial=True)
                and (suffix is None or codename.endswith(suffix)))
Example #4
0
    def __init_implied_permissions(self):
        """
        Prepares `self.__implied_permissions` for serializing
        It will contain all implied permissions for the `Asset` class.

        :return: dict
        """

        self.__implied_permissions = {
            self.__asset_key:
            self.__get_hyperlinked_permissions(Asset.get_all_implied_perms()),
        }
Example #5
0
    def _get_user_permissions(self, asset: Asset, user: '******') -> list:
        """
        Overrides parent method to include partial permissions (which are
        specific to submissions)
        """
        user_permissions = super()._get_user_permissions(asset, user)

        if PERM_PARTIAL_SUBMISSIONS in user_permissions:
            # Merge partial permissions with permissions to find out if there
            # is a match within required permissions.
            # Restricted users will be narrowed down in MongoDB query.
            partial_perms = asset.get_partial_perms(user.id)
            if partial_perms:
                user_permissions = list(set(user_permissions + partial_perms))

        return user_permissions
Example #6
0
class CreateDeployment(TestCase):
    def setUp(self):
        self.asset = Asset(content={
            'survey': [
                {u'type':'text', u'name': 'q1',
                    u'label': 'Q1.',}
                ]
            })
    def test_invalid_backend_fails(self):
        self.asset.save()
        def _bad_deployment():
            self.asset.connect_deployment(backend='nonexistent')
        self.assertRaises(KeyError, _bad_deployment)

    def test_mock_deployment_inits(self):
        self.asset.save()
        _uid = self.asset.uid
        self.asset.connect_deployment(backend='mock')
        self.assertEqual(self.asset._deployment_data['backend'], 'mock')
class CreateDeployment(TestCase):
    def setUp(self):
        self.asset = Asset(content={
            'survey': [
                {u'type':'text', u'name': 'q1',
                    u'label': 'Q1.',}
                ]
            })
    def test_invalid_backend_fails(self):
        self.asset.save()
        def _bad_deployment():
            self.asset.connect_deployment(backend='nonexistent')
        self.assertRaises(KeyError, _bad_deployment)

    def test_mock_deployment_inits(self):
        self.asset.save()
        _uid = self.asset.uid
        self.asset.connect_deployment(backend='mock')
        self.assertEqual(self.asset._deployment_data['backend'], 'mock')