<s> import datetime <EOL> import hashlib <EOL> import re <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . models import AnonymousUser <EOL> from django . core import mail <EOL> from django . conf import settings <EOL> from django . test import TestCase <EOL> from django . utils . six import text_type <EOL> from django . utils . six . moves . urllib_parse import urlparse , parse_qs <EOL> from userena . models import UserenaSignup , upload_to_mugshot <EOL> from userena import settings as userena_settings <EOL> from userena . tests . profiles . models import Profile <EOL> from userena . utils import get_user_profile <EOL> User = get_user_model ( ) <EOL> MUGSHOT_RE = re . compile ( '<STR_LIT>' ) <EOL> class UserenaSignupModelTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> user_info = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' } <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def test_upload_mugshot ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . get ( pk = <NUM_LIT:1> ) <EOL> filename = '<STR_LIT>' <EOL> path = upload_to_mugshot ( get_user_profile ( user = user ) , filename ) <EOL> self . assertNotEqual ( filename , path ) <EOL> MUGSHOT_RE = re . compile ( '<STR_LIT>' % <EOL> { '<STR_LIT>' : userena_settings . USERENA_MUGSHOT_PATH } ) <EOL> self . assertTrue ( MUGSHOT_RE . search ( path ) ) <EOL> def test_stringification ( self ) : <EOL> """<STR_LIT>""" <EOL> signup = UserenaSignup . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( signup . __str__ ( ) , <EOL> signup . user . username ) <EOL> def test_change_email ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_activation_expired_account ( 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 = User . objects . get ( username = '<STR_LIT>' ) <EOL> self . assertTrue ( user . userena_signup . activation_key_expired ( ) ) <EOL> def test_activation_used_account ( self ) : <EOL> """<STR_LIT>""" <EOL> user = UserenaSignup . objects . create_user ( ** self . user_info ) <EOL> activated_user = UserenaSignup . objects . activate_user ( user . userena_signup . activation_key ) <EOL> self . assertTrue ( activated_user . userena_signup . activation_key_expired ( ) ) <EOL> def test_activation_unexpired_account ( self ) : <EOL> """<STR_LIT>""" <EOL> user = UserenaSignup . objects . create_user ( ** self . user_info ) <EOL> self . assertFalse ( user . userena_signup . activation_key_expired ( ) ) <EOL> def test_activation_email ( self ) : <EOL> """<STR_LIT>""" <EOL> new_user = UserenaSignup . objects . create_user ( ** self . user_info ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( mail . outbox [ <NUM_LIT:0> ] . to , [ self . user_info [ '<STR_LIT:email>' ] ] ) <EOL> def test_plain_email ( self ) : <EOL> """<STR_LIT>""" <EOL> userena_settings . USERENA_HTML_EMAIL = False <EOL> new_user = UserenaSignup . objects . create_user ( ** self . user_info ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) , - <NUM_LIT:1> ) <EOL> def test_html_email ( self ) : <EOL> """<STR_LIT>""" <EOL> userena_settings . USERENA_HTML_EMAIL = True <EOL> userena_settings . USERENA_USE_PLAIN_TEMPLATE = True <EOL> new_user = UserenaSignup . objects . create_user ( ** self . user_info ) <EOL> userena_settings . USERENA_HTML_EMAIL = False <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertFalse ( mail . outbox [ <NUM_LIT:0> ] . body . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> def test_generated_plain_email ( self ) : <EOL> """<STR_LIT>""" <EOL> userena_settings . USERENA_HTML_EMAIL = True <EOL> userena_settings . USERENA_USE_PLAIN_TEMPLATE = False <EOL> new_user = UserenaSignup . objects . create_user ( ** self . user_info ) <EOL> userena_settings . USERENA_HTML_EMAIL = False <EOL> userena_settings . USERENA_USE_PLAIN_TEMPLATE = True <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertTrue ( text_type ( mail . outbox [ <NUM_LIT:0> ] . message ( ) ) . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> self . assertTrue ( mail . outbox [ <NUM_LIT:0> ] . body . find ( "<STR_LIT>" ) > - <NUM_LIT:1> ) <EOL> class BaseProfileModelTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def test_mugshot_url ( self ) : <EOL> """<STR_LIT>""" <EOL> profile = Profile . objects . get ( pk = <NUM_LIT:1> ) <EOL> profile . mugshot = '<STR_LIT>' <EOL> profile . save ( ) <EOL> profile = Profile . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( profile . get_mugshot_url ( ) , <EOL> settings . MEDIA_URL + '<STR_LIT>' ) <EOL> def test_stringification ( self ) : <EOL> """<STR_LIT>""" <EOL> profile = Profile . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( profile . __str__ ( ) , <EOL> '<STR_LIT>' % profile . user . username ) <EOL> def test_get_mugshot_url_without_gravatar ( self ) : <EOL> """<STR_LIT>""" <EOL> userena_settings . USERENA_MUGSHOT_GRAVATAR = False <EOL> profile = Profile . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( profile . get_mugshot_url ( ) , None ) <EOL> userena_settings . USERENA_MUGSHOT_DEFAULT = '<STR_LIT>' <EOL> profile = Profile . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( profile . get_mugshot_url ( ) , '<STR_LIT>' ) <EOL> userena_settings . USERENA_MUGSHOT_GRAVATAR = True <EOL> def test_get_mugshot_url_with_gravatar ( self ) : <EOL> """<STR_LIT>""" <EOL> profile = Profile . objects . get ( pk = <NUM_LIT:1> ) <EOL> gravatar_hash = hashlib . md5 ( profile . user . email . encode ( '<STR_LIT:utf-8>' ) ) . hexdigest ( ) <EOL> mugshot_url = profile . get_mugshot_url ( ) <EOL> parsed = urlparse ( mugshot_url ) <EOL> self . assertEqual ( parsed . netloc , '<STR_LIT>' ) <EOL> self . assertEqual ( parsed . path , '<STR_LIT>' + gravatar_hash ) <EOL> self . assertEqual ( <EOL> parse_qs ( parsed . query ) , <EOL> parse_qs ( '<STR_LIT>' % { <EOL> '<STR_LIT:size>' : userena_settings . USERENA_MUGSHOT_SIZE , <EOL> '<STR_LIT:default>' : userena_settings . USERENA_MUGSHOT_DEFAULT <EOL> } ) <EOL> ) <EOL> userena_settings . USERENA_MUGSHOT_SIZE = <NUM_LIT> <EOL> userena_settings . USERENA_MUGSHOT_DEFAULT = '<STR_LIT>' <EOL> mugshot_url = profile . get_mugshot_url ( ) <EOL> parsed = urlparse ( mugshot_url ) <EOL> self . assertEqual ( parsed . netloc , '<STR_LIT>' ) <EOL> self . assertEqual ( parsed . path , '<STR_LIT>' + gravatar_hash ) <EOL> self . assertEqual ( <EOL> parse_qs ( parsed . query ) , <EOL> parse_qs ( '<STR_LIT>' % { <EOL> '<STR_LIT:size>' : userena_settings . USERENA_MUGSHOT_SIZE , <EOL> '<STR_LIT:default>' : userena_settings . USERENA_MUGSHOT_DEFAULT <EOL> } ) <EOL> ) <EOL> userena_settings . USERENA_MUGSHOT_SIZE = <NUM_LIT> <EOL> userena_settings . USERENA_MUGSHOT_DEFAULT = '<STR_LIT>' <EOL> def test_get_full_name_or_username ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . get ( pk = <NUM_LIT:1> ) <EOL> profile = get_user_profile ( user = user ) <EOL> full_name = profile . get_full_name_or_username ( ) <EOL> self . assertEqual ( full_name , "<STR_LIT>" ) <EOL> user . first_name = '<STR_LIT>' <EOL> user . last_name = '<STR_LIT>' <EOL> user . save ( ) <EOL> self . assertEqual ( profile . get_full_name_or_username ( ) , <EOL> "<STR_LIT>" ) <EOL> userena_settings . USERENA_WITHOUT_USERNAMES = True <EOL> self . assertEqual ( profile . get_full_name_or_username ( ) , <EOL> "<STR_LIT>" ) <EOL> userena_settings . USERENA_WITHOUT_USERNAMES = False <EOL> def test_can_view_profile ( self ) : <EOL> """<STR_LIT>""" <EOL> anon_user = AnonymousUser ( ) <EOL> super_user = User . objects . get ( pk = <NUM_LIT:1> ) <EOL> reg_user = User . objects . get ( pk = <NUM_LIT:2> ) <EOL> profile = Profile . objects . get ( pk = <NUM_LIT:1> ) <EOL> profile . privacy = '<STR_LIT>' <EOL> self . assertTrue ( profile . can_view_profile ( anon_user ) ) <EOL> self . assertTrue ( profile . can_view_profile ( super_user ) ) <EOL> self . assertTrue ( profile . can_view_profile ( reg_user ) ) <EOL> profile . privacy = '<STR_LIT>' <EOL> self . assertFalse ( profile . can_view_profile ( anon_user ) ) <EOL> self . assertTrue ( profile . can_view_profile ( super_user ) ) <EOL> self . assertTrue ( profile . can_view_profile ( reg_user ) ) <EOL> profile . privacy = '<STR_LIT>' <EOL> self . assertFalse ( profile . can_view_profile ( anon_user ) ) <EOL> self . assertTrue ( profile . can_view_profile ( super_user ) ) <EOL> self . assertFalse ( profile . can_view_profile ( reg_user ) ) </s>
