<s> from django . test import TestCase <EOL> from django . contrib . auth import get_user_model <EOL> from django . template import Context , Template <EOL> from model_mommy import mommy <EOL> from rolepermissions . roles import RolesManager , AbstractUserRole <EOL> from rolepermissions . templatetags . permission_tags import has_role_template_tag <EOL> class TemRole1 ( AbstractUserRole ) : <EOL> available_permissions = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> class TemRole2 ( AbstractUserRole ) : <EOL> available_permissions = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> class TemRole3 ( AbstractUserRole ) : <EOL> role_name = '<STR_LIT>' <EOL> available_permissions = { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> class HasRoleTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = mommy . make ( get_user_model ( ) ) <EOL> TemRole1 . assign_role_to_user ( self . user ) <EOL> def tag_test ( self , template , context , output ) : <EOL> t = Template ( '<STR_LIT>' + template ) <EOL> c = Context ( context ) <EOL> self . assertEqual ( t . render ( c ) , output ) <EOL> def test_has_role_tag ( self ) : <EOL> user = self . user <EOL> template = '<STR_LIT>' <EOL> context = { <EOL> '<STR_LIT:user>' : user , <EOL> } <EOL> output = '<STR_LIT>' <EOL> self . tag_test ( template , context , output ) <EOL> def test_has_role_tag_with_multiple_roles ( self ) : <EOL> user = self . user <EOL> template = '<STR_LIT>' <EOL> context = { <EOL> '<STR_LIT:user>' : user , <EOL> } <EOL> output = '<STR_LIT>' <EOL> self . tag_test ( template , context , output ) <EOL> def test_does_not_have_role_tag_with_multiple_roles ( self ) : <EOL> user = self . user <EOL> template = '<STR_LIT>' <EOL> context = { <EOL> '<STR_LIT:user>' : user , <EOL> } <EOL> output = '<STR_LIT>' <EOL> self . tag_test ( template , context , output ) </s>
