<s> from __future__ import unicode_literals <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . models import User <EOL> from django . test import TestCase <EOL> from hunger . utils import setting , now <EOL> from hunger . models import Invitation , InvitationCode <EOL> from django . test . utils import override_settings <EOL> class BetaViewTests ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> redirect = setting ( '<STR_LIT>' ) <EOL> def create_invite ( self , email ) : <EOL> code = InvitationCode ( num_invites = <NUM_LIT:0> ) <EOL> code . save ( ) <EOL> invitation = Invitation ( code = code , email = email , invited = now ( ) ) <EOL> invitation . save ( ) <EOL> return invitation <EOL> def create_code ( self , private = True , email = '<STR_LIT>' ) : <EOL> code = InvitationCode ( private = private ) <EOL> code . save ( ) <EOL> if private : <EOL> invitation = Invitation ( code = code , email = email , invited = now ( ) ) <EOL> invitation . save ( ) <EOL> return code <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . alice = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . bob = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> right_now = now ( ) <EOL> invitation = Invitation ( user = self . bob , invited = right_now , used = right_now ) <EOL> invitation . save ( ) <EOL> self . charlie = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> invitation = Invitation ( user = self . charlie , invited = right_now , used = right_now ) <EOL> invitation . save ( ) <EOL> code = InvitationCode ( owner = self . charlie ) <EOL> code . save ( ) <EOL> def test_always_allow_view ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . templates [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> def test_always_allow_module ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_garden_when_not_invited ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , setting ( '<STR_LIT>' ) ) <EOL> def test_using_invite ( self ) : <EOL> cary = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( self . redirect ) ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( self . redirect ) ) <EOL> invitation = Invitation . objects . get ( user = cary ) <EOL> invitation . invited = now ( ) <EOL> invitation . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_user_invite ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , { '<STR_LIT:email>' : '<STR_LIT>' } ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> self . client . logout ( ) <EOL> User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> invitation = Invitation . objects . get ( email = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ invitation . code . code ] ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> self . client . logout ( ) <EOL> User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_invite_non_user_with_email ( self ) : <EOL> """<STR_LIT>""" <EOL> self . create_invite ( email = '<STR_LIT>' ) <EOL> User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_invite_existing_user_with_email ( self ) : <EOL> """<STR_LIT>""" <EOL> self . create_invite ( email = '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_invite_non_user_without_email ( self ) : <EOL> """<STR_LIT>""" <EOL> code = self . create_code ( email = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ code . code ] ) , follow = True ) <EOL> self . assertRedirects ( response , setting ( '<STR_LIT>' ) ) <EOL> User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' , args = [ code . code ] ) ) <EOL> def test_invite_non_user_public_invitation ( self ) : <EOL> """<STR_LIT>""" <EOL> code = self . create_code ( private = False ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ code . code ] ) , follow = True ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , setting ( '<STR_LIT>' ) ) <EOL> User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_invite_existing_user_without_email ( self ) : <EOL> """<STR_LIT>""" <EOL> code = self . create_code ( email = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ code . code ] ) , follow = True ) <EOL> self . assertRedirects ( response , setting ( '<STR_LIT>' ) ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' , args = [ code . code ] ) ) <EOL> def test_invalid_code ( self ) : <EOL> """<STR_LIT>""" <EOL> invalid_code = '<STR_LIT>' <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ invalid_code ] ) , follow = True ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' , args = [ invalid_code ] ) ) <EOL> @ override_settings ( HUNGER_ENABLE = False ) <EOL> def test_settings ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( False , setting ( '<STR_LIT>' ) ) </s>
