本文整理汇总了Python中treemap.audit.Role类的典型用法代码示例。如果您正苦于以下问题:Python Role类的具体用法?Python Role怎么用?Python Role使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Role类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.instance = make_instance()
self.instance.config['advanced_search_fields'] = {}
self.instance.save()
self.role = Role(name='role', instance=self.instance, rep_thresh=0)
self.role.save()
self.observer = make_observer_user(self.instance)
self.udf_role = Role(name='udf', instance=self.instance, rep_thresh=0)
self.udf_role.save()
self.template_dir = tempfile.mkdtemp()
self.template_file_path = os.path.join(self.template_dir,
"field_template.html")
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type='Plot',
datatype=json.dumps({'type': 'choice',
'choices': ["a", "b", "c"]}),
iscollection=False,
name='Test choice')
udf_perm, __ = FieldPermission.objects.get_or_create(
model_name='Plot', field_name='udf:Test choice',
permission_level=FieldPermission.READ_ONLY,
role=self.role, instance=self.instance)
udf_perm.save()
udf_write_perm, __ = FieldPermission.objects.get_or_create(
model_name='Plot', field_name='udf:Test choice',
permission_level=FieldPermission.WRITE_DIRECTLY,
role=self.udf_role, instance=self.instance)
udf_write_perm.save()
开发者ID:JoshIUSBStudent,项目名称:otm-core,代码行数:34,代码来源:test_templatetags.py
示例2: test_invites_updated
def test_invites_updated(self):
email = "[email protected]"
invite = InstanceInvitation(email=email,
instance=self.instance,
created_by=self.user4,
role=self.instance.default_role)
invite.save()
new_role = Role(name='Ambassador', instance=self.instance,
rep_thresh=0)
new_role.save()
body = {'invites':
{invite.pk:
{'role': new_role.pk}}}
update_user_roles(
make_request(method='POST',
body=json.dumps(body),
user=self.commander),
self.instance)
# requery invite
invite = InstanceInvitation.objects.get(pk=invite.pk)
self.assertEqual(invite.role, new_role)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:25,代码来源:test_roles.py
示例3: FieldPermMgmtTest
class FieldPermMgmtTest(OTMTestCase):
def setUp(self):
self.instance = make_instance()
self.commander = make_commander_user(self.instance)
self.new_role = Role(name='Ambassador', instance=self.instance,
rep_thresh=0)
self.new_role.save()
self.factory = RequestFactory()
def assertInvalidFPRaises(self, **kwargs):
fp = FieldPermission(**kwargs)
fp.role = self.instance.default_role
fp.instance = self.instance
self.assertRaises(ValidationError, fp.save)
def test_invalid_model_does_not_exist_unit(self):
self.assertInvalidFPRaises(model_name='Gethen', field_name='readonly')
def test_invalid_model_does_not_authorizable_unit(self):
self.assertInvalidFPRaises(model_name='FieldPermission',
field_name='role')
def test_invalid_field_name_unit(self):
self.assertInvalidFPRaises(model_name='Tree', field_name='model_name')
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:26,代码来源:test_audit.py
示例4: _user_can_do
def _user_can_do(self, user, action):
role = user.get_role(self.get_instance())
Clz = self.map_feature.__class__
if callable(getattr(self.map_feature, 'cast_to_subtype', None)):
Clz = self.map_feature.cast_to_subtype().__class__
codename = Role.permission_codename(Clz, action, photo=True)
return role.has_permission(codename, Model=MapFeaturePhoto)
开发者ID:,项目名称:,代码行数:7,代码来源:
示例5: setUp
def setUp(self):
self.instance = make_instance()
self.commander = make_commander_user(self.instance)
self.new_role = Role(name='Ambassador', instance=self.instance,
rep_thresh=0)
self.new_role.save()
self.factory = RequestFactory()
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:9,代码来源:test_audit.py
示例6: setUp
def setUp(self):
self.instance = make_instance()
self.instance.save()
self.role = Role(name="role", instance=self.instance, rep_thresh=0)
self.role.save()
self.observer = make_observer_user(self.instance)
self.udf_role = Role(name="udf", instance=self.instance, rep_thresh=0)
self.udf_role.save()
self.template_dir = tempfile.mkdtemp()
self.template_file_path = os.path.join(self.template_dir, "field_template.html")
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type="Plot",
datatype=json.dumps({"type": "choice", "choices": ["a", "b", "c"]}),
iscollection=False,
name="Test choice",
)
udf_perm, __ = FieldPermission.objects.get_or_create(
model_name="Plot",
field_name="udf:Test choice",
permission_level=FieldPermission.READ_ONLY,
role=self.role,
instance=self.instance,
)
udf_perm.save()
udf_write_perm, __ = FieldPermission.objects.get_or_create(
model_name="Plot",
field_name="udf:Test choice",
permission_level=FieldPermission.WRITE_DIRECTLY,
role=self.udf_role,
instance=self.instance,
)
udf_write_perm.save()
开发者ID:RobinIsTheBird,项目名称:otm-core,代码行数:38,代码来源:test_templatetags.py
示例7: test_user_roles_updated
def test_user_roles_updated(self):
iuser = InstanceUser(user=self.user2, instance=self.instance,
role=self.instance.default_role)
iuser.save_with_user(self.commander)
new_role = Role(name='Ambassador', instance=self.instance,
rep_thresh=0)
new_role.save()
body = {'users':
{iuser.pk:
{'role': new_role.pk, 'admin': False}}}
update_user_roles(
make_request(method='POST',
body=json.dumps(body),
user=self.commander),
self.instance)
#requery iuser
iuser = InstanceUser.objects.get(pk=iuser.pk)
self.assertEqual(iuser.role, new_role)
self.assertEqual(iuser.admin, False)
body = {'users':
{iuser.pk: {'role': new_role.pk, 'admin': True}}}
update_user_roles(
make_request(method='POST',
body=json.dumps(body),
user=self.commander),
self.instance)
#requery iuser
iuser = InstanceUser.objects.get(pk=iuser.pk)
self.assertEqual(iuser.role, new_role)
self.assertEqual(iuser.admin, True)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:37,代码来源:test_roles.py
示例8: setUp
def setUp(self):
self.instance = make_instance(name="Test Instance")
self.species = Species(
instance=self.instance,
common_name="Test Common Name",
genus="Test Genus",
cultivar="Test Cultivar",
species="Test Species",
)
self.species.save_base()
self.user = make_user(username="commander", password="pw")
self.plot = Plot(geom=Point(0, 0), instance=self.instance, address_street="123 Main Street")
self.plot.save_base()
self.tree = Tree(plot=self.plot, instance=self.instance)
self.tree.save_base()
self.boundary = make_simple_boundary("Test Boundary")
self.role = Role(instance=self.instance, name="Test Role", rep_thresh=2)
self.role.save()
self.field_permission = FieldPermission(
model_name="Tree",
field_name="readonly",
permission_level=FieldPermission.READ_ONLY,
role=self.role,
instance=self.instance,
)
self.field_permission.save_base()
self.audit = Audit(
action=Audit.Type.Update,
model="Tree",
field="readonly",
model_id=1,
user=self.user,
previous_value=True,
current_value=False,
)
self.audit.save_base()
self.reputation_metric = ReputationMetric(instance=self.instance, model_name="Tree", action="Test Action")
self.reputation_metric.save_base()
开发者ID:heath,项目名称:OTM2,代码行数:49,代码来源:models.py
示例9: ModelPermMgmtTest
class ModelPermMgmtTest(OTMTestCase):
def setUp(self):
self.instance = make_instance()
self.commander = make_commander_user(self.instance)
self.new_role = Role(name='Ambassador', instance=self.instance,
rep_thresh=0)
self.new_role.save()
self.factory = RequestFactory()
self.RolePermissionModel = Role.instance_permissions.through
def request_updates(self, perm_specs):
updates = {self.new_role.pk: {'fields': {}, 'models': perm_specs}}
request = make_request(method='PUT', body=json.dumps(updates))
roles_update(request, self.instance)
def assert_assignment(self, permission, role, is_assigned=True):
assignment = self.RolePermissionModel.objects.filter(
role=role, permission=permission)
self.assertEqual(assignment.exists(), is_assigned)
def test_instance_assignment(self):
permission = make_permission('do_all_the_things', Instance)
self.request_updates({'Instance.do_all_the_things': True})
self.assert_assignment(permission, self.new_role)
def test_model_assignment(self):
self.instance.add_map_feature_types(['Bioswale'])
permissions = [
'Plot.add_plot',
'Plot.delete_plot',
'Tree.add_tree',
'Tree.delete_tree',
'TreePhoto.add_treephoto',
'TreePhoto.delete_treephoto',
'Bioswale.add_bioswale',
'Bioswale.delete_bioswale',
'MapFeaturePhoto.add_bioswalephoto',
'MapFeaturePhoto.delete_bioswalephoto']
self.request_updates(
dict(zip(permissions, [True] * len(permissions))))
for existing in permissions:
__, codename = dotted_split(existing, 2, maxsplit=1)
permission = Permission.objects.get(codename=codename)
self.assert_assignment(permission, self.new_role)
def test_unassignment(self):
instance_permission = make_permission('do_all_the_things', Instance)
add_plot_permission = Permission.objects.get(codename='add_plot')
self.assertIsNotNone(instance_permission)
self.assertIsNotNone(add_plot_permission)
self.RolePermissionModel.objects.bulk_create([
self.RolePermissionModel(
role=self.new_role, permission=instance_permission),
self.RolePermissionModel(
role=self.new_role, permission=add_plot_permission)])
self.assertEqual(
self.RolePermissionModel.objects.filter(
role=self.new_role).count(), 2)
self.request_updates({
'Instance.do_all_the_things': False,
'Plot.add_plot': False})
self.assertEqual(
self.RolePermissionModel.objects.filter(
role=self.new_role).count(), 0)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:75,代码来源:test_roles.py
示例10: ModelUnicodeTests
class ModelUnicodeTests(OTMTestCase):
def setUp(self):
self.instance = make_instance(name='Test Instance')
self.species = Species(instance=self.instance,
common_name='Test Common Name',
genus='Test Genus',
cultivar='Test Cultivar',
species='Test Species')
self.species.save_base()
self.user = make_user(username='commander', password='pw')
self.plot = Plot(geom=Point(1, 1), instance=self.instance,
address_street="123 Main Street")
self.plot.save_base()
self.tree = Tree(plot=self.plot, instance=self.instance)
self.tree.save_base()
self.boundary = make_simple_boundary("Test Boundary")
self.role = Role(instance=self.instance, name='Test Role',
rep_thresh=2)
self.role.save()
self.field_permission = FieldPermission(
model_name="Tree",
field_name="readonly",
permission_level=FieldPermission.READ_ONLY,
role=self.role,
instance=self.instance)
self.field_permission.save_base()
self.audit = Audit(action=Audit.Type.Update,
model="Tree",
field="readonly",
model_id=1,
user=self.user,
previous_value=True,
current_value=False)
self.audit.save_base()
self.reputation_metric = ReputationMetric(instance=self.instance,
model_name="Tree",
action="Test Action")
self.reputation_metric.save_base()
def test_instance_model(self):
self.assertEqual(unicode(self.instance), "Test Instance")
def test_species_model(self):
self.assertEqual(
unicode(self.species),
"Test Common Name [Test Genus Test Species 'Test Cultivar']")
def test_user_model(self):
self.assertEqual(unicode(self.user), 'commander')
def test_plot_model(self):
self.assertEqual(unicode(self.plot),
'Plot (1.0, 1.0) 123 Main Street')
def test_tree_model(self):
self.assertEqual(unicode(self.tree), '')
def test_boundary_model(self):
self.assertEqual(unicode(self.boundary), 'Test Boundary')
def test_role_model(self):
self.assertEqual(unicode(self.role), 'Test Role (%s)' % self.role.pk)
def test_field_permission_model(self):
self.assertEqual(unicode(self.field_permission),
'Tree.readonly - Test Role (%s) - Read Only'
% self.role.pk)
def test_audit_model(self):
self.assertEqual(
unicode(self.audit),
'pk=%s - action=Update - Tree.readonly:(1) - True => False'
% self.audit.pk)
def test_reputation_metric_model(self):
self.assertEqual(unicode(self.reputation_metric),
'Test Instance - Tree - Test Action')
开发者ID:jwalgran,项目名称:otm-core,代码行数:89,代码来源:test_models.py
示例11: FieldPermMgmtTest
class FieldPermMgmtTest(OTMTestCase):
def setUp(self):
self.instance = make_instance()
self.commander = make_commander_user(self.instance)
self.new_role = Role(name='Ambassador', instance=self.instance,
rep_thresh=0)
self.new_role.save()
self.factory = RequestFactory()
def make_updates(self, role_id, field_json):
return {
role_id: {
'fields': field_json,
'models': {}
}
}
def test_updates(self):
# TODO: For now, don't use '2', which is pending
updates = self.make_updates(
self.new_role.pk, {'Tree.diameter': 3})
json_updates = json.dumps(updates)
request = make_request(method='PUT', body=json_updates)
roles_update(request, self.instance)
#requery new_role
self.new_role = Role.objects.get(pk=self.new_role.pk)
self.assertEqual(1,
FieldPermission.objects.filter(
model_name='Tree',
field_name='diameter',
instance=self.instance,
role=self.new_role,
permission_level=3).count())
def test_no_updates(self):
updates = {}
json_updates = json.dumps(updates)
request = make_request(method='PUT', body=json_updates)
roles_update(request, self.instance)
def assertUpdatesRaisesValidation(self, updates):
json_updates = json.dumps(updates)
request = make_request(method='PUT', body=json_updates)
self.assertRaises(ValidationError, roles_update,
request, self.instance)
def test_invalid_model_does_not_exist_integration(self):
updates = self.make_updates(
self.new_role.pk, {'Gethen.model_name': 2})
self.assertUpdatesRaisesValidation(updates)
def test_invalid_model_not_authorizable_integration(self):
updates = self.make_updates(
self.new_role.pk, {'FieldPermission.model_name': 2})
self.assertUpdatesRaisesValidation(updates)
def test_invalid_field_name_integration(self):
updates = self.make_updates(
self.new_role.pk, {'Tree.model_name': 2})
self.assertUpdatesRaisesValidation(updates)
def test_invalid_role_id_integration(self):
updates = self.make_updates(
100, {'Tree.readonly': 2})
self.assertUpdatesRaisesValidation(updates)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:72,代码来源:test_roles.py
示例12: UserCanReadTagTest
class UserCanReadTagTest(TestCase):
def setUp(self):
self.instance = make_instance()
self.user = make_user(username="user", password="user")
self.role = Role(name="role", instance=self.instance, rep_thresh=0)
self.role.save()
self.user_perm, _ = FieldPermission.objects.get_or_create(
model_name="Plot",
field_name="width",
permission_level=FieldPermission.NONE,
role=self.role,
instance=self.instance,
)
iuser = InstanceUser(instance=self.instance, user=self.user, role=self.role)
iuser.save_with_user(self.user)
inst_role = Role(name="inst def role", instance=self.instance, rep_thresh=0)
inst_role.save()
self.inst_perm, _ = FieldPermission.objects.get_or_create(
model_name="Plot",
field_name="width",
permission_level=FieldPermission.NONE,
role=inst_role,
instance=self.instance,
)
self.instance.default_role = inst_role
self.instance.save()
self.plot = Plot(instance=self.instance)
basic_template = Template(
"""
{% load auth_extras %}
{% usercanread plot "width" as w %}
plot width {{ w }}
{% endusercanread %}
"""
)
def _render_basic_template_with_vars(self, user, plot):
return UserCanReadTagTest.basic_template.render(Context({"request": {"user": user}, "plot": plot})).strip()
def test_works_with_empty_user_no_perm(self):
self.assertEqual(self._render_basic_template_with_vars(None, self.plot), "")
def test_works_with_empty_user_with_perm(self):
perms = [FieldPermission.READ_ONLY, FieldPermission.WRITE_WITH_AUDIT, FieldPermission.WRITE_DIRECTLY]
self.plot.width = 9
for plevel in perms:
self.inst_perm.permission_level = plevel
self.inst_perm.save()
self.assertEqual(self._render_basic_template_with_vars(None, self.plot), "plot width 9")
def test_works_with_user_with_role_no_perm(self):
self.assertEqual(self._render_basic_template_with_vars(self.user, self.plot), "")
def test_works_with_user_with_role_with_perm(self):
perms = [FieldPermission.READ_ONLY, FieldPermission.WRITE_WITH_AUDIT, FieldPermission.WRITE_DIRECTLY]
self.plot.width = 9
for plevel in perms:
self.user_perm.permission_level = plevel
self.user_perm.save()
self.assertEqual(self._render_basic_template_with_vars(self.user, self.plot), "plot width 9")
def test_works_with_udf(self):
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type="Plot",
datatype=json.dumps({"type": "choice", "choices": ["a", "b", "c"]}),
iscollection=False,
name="Test choice",
)
udf_perm, _ = FieldPermission.objects.get_or_create(
model_name="Plot",
field_name="udf:Test choice",
permission_level=FieldPermission.NONE,
role=self.role,
instance=self.instance,
)
udf_perm.save()
plot = self.plot
plot.udfs["Test choice"] = "b"
def render():
return (
Template(
#.........这里部分代码省略.........
开发者ID:heath,项目名称:OTM2,代码行数:101,代码来源:templatetags.py
示例13: InlineFieldTagTests
class InlineFieldTagTests(TestCase):
def setUp(self):
self.instance = make_instance()
self.instance.config["advanced_search_fields"] = {}
self.instance.save()
self.role = Role(name="role", instance=self.instance, rep_thresh=0)
self.role.save()
self.observer = make_observer_user(self.instance)
self.udf_role = Role(name="udf", instance=self.instance, rep_thresh=0)
self.udf_role.save()
self.template_dir = tempfile.mkdtemp()
self.template_file_path = os.path.join(self.template_dir, "field_template.html")
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type="Plot",
datatype=json.dumps({"type": "choice", "choices": ["a", "b", "c"]}),
iscollection=False,
name="Test choice",
)
udf_perm, _ = FieldPermission.objects.get_or_create(
model_name="Plot",
field_name="udf:Test choice",
permission_level=FieldPermission.READ_ONLY,
role=self.role,
instance=self.instance,
)
udf_perm.save()
udf_write_perm, _ = FieldPermission.objects.get_or_create(
model_name="Plot",
field_name="udf:Test choice",
permission_level=FieldPermission.WRITE_DIRECTLY,
role=self.udf_role,
instance=self.instance,
)
udf_write_perm.save()
def tearDown(self):
rmtree(self.template_dir)
def _form_template_with_request_user_for(self, identifier):
field_name = '"' + identifier + '"'
template_text = (
"""{% load form_extras %}"""
+ """{% field "Test Field" from """
+ field_name
+ """ for request.user withtemplate "field_template.html" %}"""
)
return Template(template_text)
def _form_template_for(self, identifier):
field_name = '"' + identifier + '"'
template_text = (
"""{% load form_extras %}"""
+ """{% field "Test Field" from """
+ field_name
+ """ withtemplate "field_template.html" %}"""
)
return Template(template_text)
def _form_template_labelless_with_request_user_for(self, identifier):
field_name = '"' + identifier + '"'
template_text = (
"""{% load form_extras %}"""
+ """{% field from """
+ field_name
+ """ for request.user withtemplate "field_template.html" %}"""
)
return Template(template_text)
def _form_template_labelless_for(self, identifier):
field_name = '"' + identifier + '"'
template_text = (
"""{% load form_extras %}"""
+ """{% field from """
+ field_name
+ """ withtemplate "field_template.html" %}"""
)
return Template(template_text)
def _form_template_create(self, identifier):
field_name = '"' + identifier + '"'
template_text = (
"""{% load form_extras %}"""
+ """{% create from """
+ field_name
+ """ in request.instance"""
+ """ withtemplate "field_template.html" %}"""
)
return Template(template_text)
def _form_template_search(self):
template_text = (
"""{% load form_extras %}"""
+ """{% search from search_json"""
+ """ for request.user in request.instance """
#.........这里部分代码省略.........
开发者ID:heath,项目名称:OTM2,代码行数:101,代码来源:templatetags.py
示例14: InlineFieldTagTests
class InlineFieldTagTests(OTMTestCase):
def setUp(self):
self.instance = make_instance()
self.instance.config['advanced_search_fields'] = {}
self.instance.save()
self.role = Role(name='role', instance=self.instance, rep_thresh=0)
self.role.save()
self.observer = make_observer_user(self.instance)
self.udf_role = Role(name='udf', instance=self.instance, rep_thresh=0)
self.udf_role.save()
self.template_dir = tempfile.mkdtemp()
self.template_file_path = os.path.join(self.template_dir,
"field_template.html")
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type='Plot',
datatype=json.dumps({'type': 'choice',
'choices': ["a", "b", "c"]}),
iscollection=False,
name='Test choice')
udf_perm, __ = FieldPermission.objects.get_or_create(
model_name='Plot', field_name='udf:Test choice',
permission_level=FieldPermission.READ_ONLY,
role=self.role, instance=self.instance)
udf_perm.save()
udf_write_perm, __ = FieldPermission.objects.get_or_create(
model_name='Plot', field_name='udf:Test choice',
permission_level=FieldPermission.WRITE_DIRECTLY,
role=self.udf_role, instance=self.instance)
udf_write_perm.save()
def tearDown(self):
rmtree(self.template_dir)
def _form_template_with_request_user_for(self, identifier):
field_name = '"' + identifier + '"'
template_text = """{% load form_extras %}""" +\
"""{% field "Test Field" from """ + field_name +\
""" for request.user withtemplate "field_template.html" %}"""
return Template(template_text)
def _form_template_for(self, identifier):
field_name = '"' + identifier + '"'
template_text = """{% load form_extras %}""" +\
"""{% field "Test Field" from """ + field_name +\
""" withtemplate "field_template.html" %}"""
return Template(template_text)
def _form_template_labelless_with_request_user_for(self, identifier):
field_name = '"' + identifier + '"'
template_text = """{% load form_extras %}""" +\
"""{% field from """ + field_name +\
""" for request.user withtemplate "field_template.html" %}"""
return Template(template_text)
def _form_template_labelless_for(self, identifier):
field_name = '"' + identifier + '"'
template_text = """{% load form_extras %}""" +\
"""{% field from """ + field_name +\
""" withtemplate "field_template.html" %}"""
return Template(template_text)
def _form_template_create(self, identifier):
field_name = '"' + identifier + '"'
template_text = """{% load form_extras %}""" +\
"""{% create from """ + field_name +\
""" in request.instance""" +\
""" withtemplate "field_template.html" %}"""
return Template(template_text)
def _form_template_search(self):
template_text = """{% load form_extras %}""" +\
"""{% search from search_json""" +\
""" for request.user in request.instance """ +\
""" withtemplate "field_template.html" %}"""
return Template(template_text)
def _write_field_template(self, text):
with open(self.template_file_path, 'w') as f:
f.write(text)
def assert_plot_length_context_value(self, user, name, value,
template_fn=None):
if template_fn is None:
template_fn = (self._form_template_with_request_user_for
if user else self._form_template_for)
plot = Plot(length=12.3, instance=self.instance)
plot.convert_to_display_units()
template = template_fn('plot.length')
self._write_field_template("{{" + name + "}}")
with self.settings(TEMPLATE_DIRS=(self.template_dir,)):
content = template.render(Context({
'request': {'user': user, 'instance': self.instance},
#.........这里部分代码省略.........
开发者ID:JoshIUSBStudent,项目名称:otm-core,代码行数:101,代码来源:test_templatetags.py
示例15: UserCanReadTagTest
class UserCanReadTagTest(OTMTestCase):
def setUp(self):
self.instance = make_instance()
self.user = make_user(username='user', password='user')
self.role = Role(name='role', instance=self.instance, rep_thresh=0)
self.role.save()
self.user_perm, __ = FieldPermission.objects.get_or_create(
model_name='Plot', field_name='width',
permission_level=FieldPermission.NONE,
role=self.role, instance=self.instance)
iuser = InstanceUser(instance=self.instance, user=self.user,
role=self.role)
iuser.save_with_user(self.user)
inst_role = Role(name='inst def role',
instance=self.instance,
rep_thresh=0)
inst_role.save()
self.inst_perm, __ = FieldPermission.objects.get_or_create(
model_name='Plot', field_name='width',
permission_level=FieldPermission.NONE,
role=inst_role, instance=self.instance)
self.instance.default_role = inst_role
self.instance.save()
self.plot = Plot(instance=self.instance)
basic_template = Template(
"""
{% load auth_extras %}
{% usercanread plot "width" as w %}
plot width {{ w }}
{% endusercanread %}
""")
def _render_basic_template_with_vars(self, user, plot):
return UserCanReadTagTest.basic_template.render(
Context({
'request': {'user': user},
'plot': plot})).strip()
def test_works_with_empty_user_no_perm(self):
self.assertEqual(
self._render_basic_template_with_vars(None, self.plot), '')
def test_works_with_empty_user_with_perm(self):
perms = [FieldPermission.READ_ONLY,
FieldPermission.WRITE_WITH_AUDIT,
FieldPermission.WRITE_DIRECTLY]
self.plot.width = 9
for plevel in perms:
self.inst_perm.permission_level = plevel
self.inst_perm.save()
self.assertEqual(
self._render_basic_template_with_vars(None, self.plot),
'plot width 9')
def test_works_with_user_with_role_no_perm(self):
self.assertEqual(
self._render_basic_template_with_vars(self.user, self.plot), '')
def test_works_with_user_with_role_with_perm(self):
perms = [FieldPermission.READ_ONLY,
FieldPermission.WRITE_WITH_AUDIT,
FieldPermission.WRITE_DIRECTLY]
self.plot.width = 9
for plevel in perms:
self.user_perm.permission_level = plevel
self.user_perm.save()
self.assertEqual(
self._render_basic_template_with_vars(self.user, self.plot),
'plot width 9')
def test_works_with_udf(self):
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type='Plot',
datatype=json.dumps({'type': 'choice',
'choices': ['a', 'b', 'c']}),
iscollection=False,
name='Test choice')
udf_perm, __ = FieldPermission.objects.get_or_create(
model_name='Plot', field_name='udf:Test choice',
permission_level=FieldPermission.NONE,
role=self.role, instance=self.instance)
udf_perm.save()
#.........这里部分代码省略.........
开发者ID:JoshIUSBStudent,项目名称:otm-core,代码行数:101,代码来源:test_templatetags.py
注:本文中的treemap.audit.Role类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论