<s> from django . core . urlresolvers import reverse_lazy <EOL> from django . test import TestCase <EOL> from timepiece . tests import factories <EOL> from timepiece . tests . base import ViewTestMixin <EOL> from . . models import Business <EOL> class TestCreateBusiness ( ViewTestMixin , TestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> factory = factories . Business <EOL> model = Business <EOL> permissions = ( '<STR_LIT>' , ) <EOL> def setUp ( self ) : <EOL> super ( TestCreateBusiness , self ) . setUp ( ) <EOL> self . user = factories . User ( permissions = self . permissions ) <EOL> self . login_user ( self . user ) <EOL> self . post_data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def test_get_no_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_permissions . clear ( ) <EOL> response = self . _get ( ) <EOL> self . assertRedirectsToLogin ( response ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_post_no_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_permissions . clear ( ) <EOL> response = self . _post ( ) <EOL> self . assertRedirectsToLogin ( response ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertTrue ( '<STR_LIT>' in response . context ) <EOL> self . assertFalse ( response . context [ '<STR_LIT>' ] . is_bound ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_post_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . _post ( ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:1> ) <EOL> obj = self . model . objects . get ( ) <EOL> self . assertRedirectsNoFollow ( response , obj . get_absolute_url ( ) ) <EOL> self . assertEquals ( obj . name , self . post_data [ '<STR_LIT:name>' ] ) <EOL> self . assertEquals ( obj . email , self . post_data [ '<STR_LIT:email>' ] ) <EOL> self . assertEquals ( obj . description , self . post_data [ '<STR_LIT:description>' ] ) <EOL> self . assertEquals ( obj . notes , self . post_data [ '<STR_LIT>' ] ) <EOL> def test_post_invalid ( self ) : <EOL> """<STR_LIT>""" <EOL> self . post_data [ '<STR_LIT:name>' ] = '<STR_LIT>' <EOL> response = self . _post ( ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertTrue ( '<STR_LIT>' in response . context ) <EOL> self . assertTrue ( response . context [ '<STR_LIT>' ] . is_bound ) <EOL> self . assertFalse ( response . context [ '<STR_LIT>' ] . is_valid ( ) ) <EOL> class TestDeleteBusiness ( ViewTestMixin , TestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> model = Business <EOL> factory = factories . Business <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> permissions = ( '<STR_LIT>' , ) <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( TestDeleteBusiness , self ) . setUp ( ) <EOL> self . user = factories . User ( permissions = self . permissions ) <EOL> self . login_user ( self . user ) <EOL> self . obj = self . factory . create ( ) <EOL> self . url_kwargs = { self . pk_url_kwarg : self . obj . pk } <EOL> def test_get_no_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_permissions . clear ( ) <EOL> response = self . _get ( ) <EOL> self . assertRedirectsToLogin ( response ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:1> ) <EOL> def test_post_no_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_permissions . clear ( ) <EOL> response = self . _post ( ) <EOL> self . assertRedirectsToLogin ( response ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:1> ) <EOL> def test_bad_pk ( self ) : <EOL> """<STR_LIT>""" <EOL> Business . objects . all ( ) . delete ( ) <EOL> self . url_kwargs [ self . pk_url_kwarg ] = <NUM_LIT> <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertTrue ( '<STR_LIT:object>' in response . context ) <EOL> self . assertEquals ( response . context [ '<STR_LIT:object>' ] , self . obj ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:1> ) <EOL> def test_post ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . _post ( ) <EOL> self . assertRedirectsNoFollow ( response , self . success_url ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:0> ) <EOL> class TestEditBusiness ( ViewTestMixin , TestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> model = Business <EOL> factory = factories . Business <EOL> permissions = ( '<STR_LIT>' , ) <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( TestEditBusiness , self ) . setUp ( ) <EOL> self . user = factories . User ( permissions = self . permissions ) <EOL> self . login_user ( self . user ) <EOL> self . obj = self . factory . create ( ) <EOL> self . url_kwargs = { self . pk_url_kwarg : self . obj . pk } <EOL> self . post_data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def _assert_no_change ( self ) : <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:1> ) <EOL> obj = self . model . objects . get ( ) <EOL> self . assertEquals ( obj . name , self . obj . name ) <EOL> self . assertEquals ( obj . email , self . obj . email ) <EOL> self . assertEquals ( obj . description , self . obj . description ) <EOL> self . assertEquals ( obj . notes , self . obj . notes ) <EOL> def test_get_no_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_permissions . clear ( ) <EOL> response = self . _get ( ) <EOL> self . assertRedirectsToLogin ( response ) <EOL> self . _assert_no_change ( ) <EOL> def test_post_no_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_permissions . clear ( ) <EOL> response = self . _post ( ) <EOL> self . assertRedirectsToLogin ( response ) <EOL> self . _assert_no_change ( ) <EOL> def test_bad_pk ( self ) : <EOL> """<STR_LIT>""" <EOL> Business . objects . all ( ) . delete ( ) <EOL> self . url_kwargs [ self . pk_url_kwarg ] = <NUM_LIT> <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertTrue ( '<STR_LIT:object>' in response . context ) <EOL> self . assertEquals ( response . context [ '<STR_LIT:object>' ] , self . obj ) <EOL> self . assertTrue ( '<STR_LIT>' in response . context ) <EOL> self . assertFalse ( response . context [ '<STR_LIT>' ] . is_bound ) <EOL> self . assertEquals ( response . context [ '<STR_LIT>' ] . instance , self . obj ) <EOL> self . _assert_no_change ( ) <EOL> def test_post_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . _post ( ) <EOL> self . assertEquals ( self . model . objects . count ( ) , <NUM_LIT:1> ) <EOL> obj = self . model . objects . get ( ) <EOL> self . assertEquals ( obj . pk , self . obj . pk ) <EOL> self . assertRedirectsNoFollow ( response , obj . get_absolute_url ( ) ) <EOL> self . assertEquals ( obj . name , self . post_data [ '<STR_LIT:name>' ] ) <EOL> self . assertEquals ( obj . email , self . post_data [ '<STR_LIT:email>' ] ) <EOL> self . assertEquals ( obj . description , self . post_data [ '<STR_LIT:description>' ] ) <EOL> self . assertEquals ( obj . notes , self . post_data [ '<STR_LIT>' ] ) <EOL> def test_post_invalid ( self ) : <EOL> """<STR_LIT>""" <EOL> self . post_data [ '<STR_LIT:name>' ] = '<STR_LIT>' <EOL> response = self . _post ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertTrue ( '<STR_LIT:object>' in response . context ) <EOL> self . assertEquals ( response . context [ '<STR_LIT:object>' ] , self . obj ) <EOL> self . assertTrue ( '<STR_LIT>' in response . context ) <EOL> self . assertTrue ( response . context [ '<STR_LIT>' ] . is_bound ) <EOL> self . assertFalse ( response . context [ '<STR_LIT>' ] . is_valid ( ) ) <EOL> self . assertEquals ( response . context [ '<STR_LIT>' ] . instance , self . obj ) <EOL> self . _assert_no_change ( ) <EOL> class TestListBusinesses ( ViewTestMixin , TestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> factory = factories . Business <EOL> model = Business <EOL> permissions = ( '<STR_LIT>' , ) <EOL> def setUp ( self ) : <EOL> super ( TestListBusinesses , self ) . setUp ( ) <EOL> self . user = factories . User ( permissions = self . permissions ) <EOL> self . login_user ( self . user ) <EOL> def test_get_no_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_permissions . clear ( ) <EOL> response = self . _get ( ) <EOL> self . assertRedirectsToLogin ( response ) <EOL> def test_list_all ( self ) : <EOL> """<STR_LIT>""" <EOL> object_list = [ self . factory . create ( ) for i in range ( <NUM_LIT:3> ) ] <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertEquals ( response . context [ '<STR_LIT>' ] . count ( ) , <NUM_LIT:3> ) <EOL> for obj in object_list : <EOL> self . assertTrue ( obj in response . context [ '<STR_LIT>' ] ) <EOL> def test_list_none ( self ) : <EOL> """<STR_LIT>""" <EOL> self . model . objects . all ( ) . delete ( ) <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertEquals ( response . context [ '<STR_LIT>' ] . count ( ) , <NUM_LIT:0> ) <EOL> def test_list_one ( self ) : <EOL> """<STR_LIT>""" <EOL> obj = self . factory . create ( ) <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertEquals ( response . context [ '<STR_LIT>' ] . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( response . context [ '<STR_LIT>' ] . get ( ) , obj ) <EOL> def test_no_results ( self ) : <EOL> """<STR_LIT>""" <EOL> self . factory . create ( ) <EOL> response = self . _get ( get_kwargs = { '<STR_LIT>' : '<STR_LIT:hello>' } ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertEquals ( response . context [ '<STR_LIT>' ] . count ( ) , <NUM_LIT:0> ) <EOL> def test_one_result ( self ) : <EOL> """<STR_LIT>""" <EOL> obj = self . factory . create ( name = '<STR_LIT:hello>' ) <EOL> response = self . _get ( get_kwargs = { '<STR_LIT>' : '<STR_LIT:hello>' } ) <EOL> self . assertRedirectsNoFollow ( response , obj . get_absolute_url ( ) ) <EOL> def test_multiple_results ( self ) : <EOL> """<STR_LIT>""" <EOL> obj_list = [ self . factory . create ( name = '<STR_LIT:hello>' ) for i in range ( <NUM_LIT:2> ) ] <EOL> response = self . _get ( get_kwargs = { '<STR_LIT>' : '<STR_LIT:hello>' } ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertEquals ( response . context [ '<STR_LIT>' ] . count ( ) , <NUM_LIT:2> ) <EOL> for obj in obj_list : <EOL> self . assertTrue ( obj in response . context [ '<STR_LIT>' ] ) <EOL> def test_filter_name ( self ) : <EOL> """<STR_LIT>""" <EOL> self . factory . create ( ) <EOL> obj = self . factory . create ( name = '<STR_LIT:hello>' ) <EOL> response = self . _get ( get_kwargs = { '<STR_LIT>' : '<STR_LIT:hello>' } ) <EOL> self . assertRedirectsNoFollow ( response , obj . get_absolute_url ( ) ) <EOL> def test_filter_description ( self ) : <EOL> """<STR_LIT>""" <EOL> self . factory . create ( ) <EOL> obj = self . factory . create ( description = '<STR_LIT:hello>' ) <EOL> response = self . _get ( get_kwargs = { '<STR_LIT>' : '<STR_LIT:hello>' } ) <EOL> self . assertRedirectsNoFollow ( response , obj . get_absolute_url ( ) ) <EOL> class TestViewBusiness ( ViewTestMixin , TestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> model = Business <EOL> factory = factories . Business <EOL> permissions = ( '<STR_LIT>' , ) <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( TestViewBusiness , self ) . setUp ( ) <EOL> self . user = factories . User ( permissions = self . permissions ) <EOL> self . login_user ( self . user ) <EOL> self . obj = self . factory . create ( ) <EOL> self . url_kwargs = { self . pk_url_kwarg : self . obj . pk } <EOL> def test_get_no_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_permissions . clear ( ) <EOL> response = self . _get ( ) <EOL> self . assertRedirectsToLogin ( response ) <EOL> def test_post ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . _post ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_bad_pk ( self ) : <EOL> """<STR_LIT>""" <EOL> Business . objects . all ( ) . delete ( ) <EOL> self . url_kwargs [ self . pk_url_kwarg ] = <NUM_LIT> <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . _get ( ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , self . template_name ) <EOL> self . assertTrue ( '<STR_LIT:object>' in response . context ) <EOL> self . assertEquals ( response . context [ '<STR_LIT:object>' ] , self . obj ) </s>
