<s> from __future__ import unicode_literals <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . models import Group <EOL> from django . core . exceptions import PermissionDenied <EOL> from django . test import TestCase <EOL> from user_management . tests import TEST_GROUP , TEST_USER_USERNAME <EOL> from . . classes import Permission <EOL> from . . models import Role <EOL> from . . permissions import permission_role_view <EOL> from . literals import TEST_ROLE_LABEL <EOL> class PermissionTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = get_user_model ( ) . objects . create ( <EOL> username = TEST_USER_USERNAME <EOL> ) <EOL> self . group = Group . objects . create ( name = TEST_GROUP ) <EOL> self . role = Role . objects . create ( label = TEST_ROLE_LABEL ) <EOL> Permission . invalidate_cache ( ) <EOL> def test_no_permissions ( self ) : <EOL> with self . assertRaises ( PermissionDenied ) : <EOL> Permission . check_permissions ( <EOL> requester = self . user , permissions = ( permission_role_view , ) <EOL> ) <EOL> def test_with_permissions ( self ) : <EOL> self . group . user_set . add ( self . user ) <EOL> self . role . permissions . add ( permission_role_view . stored_permission ) <EOL> self . role . groups . add ( self . group ) <EOL> try : <EOL> Permission . check_permissions ( <EOL> requester = self . user , permissions = ( permission_role_view , ) <EOL> ) <EOL> except PermissionDenied : <EOL> self . fail ( '<STR_LIT>' ) </s>
