<s> from django . test import TestCase <EOL> from django . core . management import call_command <EOL> from django . contrib . auth . models import Permission <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from userena . models import UserenaSignup <EOL> from userena . managers import ASSIGNED_PERMISSIONS <EOL> from userena import settings as userena_settings <EOL> from userena . utils import get_profile_model , get_user_model <EOL> from guardian . shortcuts import remove_perm <EOL> from guardian . models import UserObjectPermission <EOL> import datetime <EOL> User = get_user_model ( ) <EOL> class CleanExpiredTests ( TestCase ) : <EOL> user_info = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' } <EOL> def test_clean_expired ( self ) : <EOL> """<STR_LIT>""" <EOL> user = UserenaSignup . objects . create_user ( ** self . user_info ) <EOL> user . date_joined -= datetime . timedelta ( days = userena_settings . USERENA_ACTIVATION_DAYS + <NUM_LIT:1> ) <EOL> user . save ( ) <EOL> User . objects . get ( username = self . user_info [ '<STR_LIT:username>' ] ) <EOL> call_command ( '<STR_LIT>' ) <EOL> self . failUnlessEqual ( User . objects . filter ( username = self . user_info [ '<STR_LIT:username>' ] ) . count ( ) , <NUM_LIT:0> ) <EOL> class CheckPermissionTests ( TestCase ) : <EOL> user_info = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' } <EOL> def test_check_permissions ( self ) : <EOL> user = UserenaSignup . objects . create_user ( ** self . user_info ) <EOL> user . save ( ) <EOL> UserObjectPermission . objects . filter ( user = user ) . delete ( ) <EOL> self . failUnlessEqual ( UserObjectPermission . objects . filter ( user = user ) . count ( ) , <EOL> <NUM_LIT:0> ) <EOL> call_command ( '<STR_LIT>' ) <EOL> user_permissions = UserObjectPermission . objects . filter ( user = user ) . values_list ( '<STR_LIT>' , flat = True ) <EOL> required_permissions = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> for perm in required_permissions : <EOL> if perm not in user_permissions : <EOL> self . fail ( ) <EOL> call_command ( '<STR_LIT>' , test = True ) <EOL> def test_incomplete_permissions ( self ) : <EOL> profile_model_obj = get_profile_model ( ) <EOL> content_type_profile = ContentType . objects . get_for_model ( profile_model_obj ) <EOL> content_type_user = ContentType . objects . get_for_model ( User ) <EOL> for model , perms in ASSIGNED_PERMISSIONS . items ( ) : <EOL> if model == "<STR_LIT>" : <EOL> content_type = content_type_profile <EOL> else : content_type = content_type_user <EOL> for perm in perms : <EOL> Permission . objects . get ( name = perm [ <NUM_LIT:1> ] , <EOL> content_type = content_type ) . delete ( ) <EOL> for model , perms in ASSIGNED_PERMISSIONS . items ( ) : <EOL> if model == "<STR_LIT>" : <EOL> content_type = content_type_profile <EOL> else : content_type = content_type_user <EOL> for perm in perms : <EOL> try : <EOL> perm = Permission . objects . get ( name = perm [ <NUM_LIT:1> ] , <EOL> content_type = content_type ) <EOL> except Permission . DoesNotExist : pass <EOL> else : self . fail ( "<STR_LIT>" % perm ) <EOL> call_command ( '<STR_LIT>' , test = True ) <EOL> for model , perms in ASSIGNED_PERMISSIONS . items ( ) : <EOL> if model == "<STR_LIT>" : <EOL> content_type = content_type_profile <EOL> else : content_type = content_type_user <EOL> for perm in perms : <EOL> try : <EOL> perm = Permission . objects . get ( name = perm [ <NUM_LIT:1> ] , <EOL> content_type = content_type ) <EOL> except Permission . DoesNotExist : <EOL> self . fail ( ) <EOL> def test_no_profile ( self ) : <EOL> """<STR_LIT>""" <EOL> user = UserenaSignup . objects . create_user ( ** self . user_info ) <EOL> get_profile_model ( ) . objects . get ( user = user ) . delete ( ) <EOL> call_command ( '<STR_LIT>' , test = True ) </s>
