<s> from django . test import TestCase <EOL> from offers . models import Offer , Comment , Provider , Plan , Location , Datacenter , TestDownload , TestIP , Like <EOL> from model_mommy import mommy <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . models import User <EOL> from django_webtest import WebTest <EOL> class ProviderProfileViewTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . provider = mommy . make ( Provider ) <EOL> def test_provider_profile_can_be_accessed ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( self . provider . get_absolute_url ( ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_provider_profile_shows_info ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( self . provider . get_absolute_url ( ) ) <EOL> self . assertContains ( response , self . provider . name ) <EOL> def test_provider_profile_shows_offers ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . PUBLISHED ) <EOL> offers = Offer . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> : <NUM_LIT:5> ] <EOL> response = self . client . get ( self . provider . get_absolute_url ( ) ) <EOL> for offer in offers : <EOL> self . assertContains ( response , offer . name ) <EOL> def test_provider_profile_shows_offers_paginated ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . PUBLISHED ) <EOL> for page_num in range ( <NUM_LIT:4> ) : <EOL> response = self . client . get ( self . provider . get_absolute_url ( ) + '<STR_LIT>' + str ( page_num + <NUM_LIT:1> ) ) <EOL> offers = Offer . objects . order_by ( '<STR_LIT>' ) [ page_num * <NUM_LIT:5> : ( page_num * <NUM_LIT:5> ) + <NUM_LIT:5> ] <EOL> for offer in offers : <EOL> self . assertContains ( response , offer . name ) <EOL> def test_provider_profile_shows_offers_bad_paginated ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . PUBLISHED ) <EOL> response = self . client . get ( self . provider . get_absolute_url ( ) + "<STR_LIT>" ) <EOL> offers = Offer . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:15> : <NUM_LIT:20> ] <EOL> for offer in offers : <EOL> self . assertContains ( response , offer . name ) <EOL> class OfferViewTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . offer = mommy . make ( Offer ) <EOL> def test_can_view_published_offers ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . status = Offer . PUBLISHED <EOL> self . offer . save ( ) <EOL> response = self . client . get ( self . offer . get_absolute_url ( ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , self . offer . content ) <EOL> def test_can_not_view_unpublished_offers ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . status = Offer . UNPUBLISHED <EOL> self . offer . save ( ) <EOL> response = self . client . get ( self . offer . get_absolute_url ( ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> class OfferAuthenticatedViewTests ( OfferViewTests ) : <EOL> def setUp ( self ) : <EOL> self . offer = mommy . make ( Offer , status = Offer . PUBLISHED ) <EOL> self . user = User . objects . create_user ( username = '<STR_LIT:user>' , email = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT:password>' ) <EOL> def test_user_cannot_post_invalid_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> post_data = { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : - <NUM_LIT:1> , <EOL> } <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:0> ) <EOL> response = self . client . post ( self . offer . get_absolute_url ( ) , post_data ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_user_cannot_post_comment_when_logged_out ( self ) : <EOL> """<STR_LIT>""" <EOL> post_data = { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : - <NUM_LIT:1> , <EOL> } <EOL> self . client . logout ( ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:0> ) <EOL> response = self . client . post ( self . offer . get_absolute_url ( ) , post_data ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_user_can_post_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> post_data = { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : - <NUM_LIT:1> , <EOL> } <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:0> ) <EOL> response = self . client . post ( self . offer . get_absolute_url ( ) , post_data ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_user_can_post_multiple_comments ( self ) : <EOL> """<STR_LIT>""" <EOL> post_data = { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : - <NUM_LIT:1> , <EOL> } <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:0> ) <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> response = self . client . post ( self . offer . get_absolute_url ( ) , post_data ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , i + <NUM_LIT:1> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:4> ) <EOL> def test_user_can_post_reply_to_another_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> another_comment = mommy . make ( Comment , offer = self . offer ) <EOL> post_data = { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : another_comment . pk , <EOL> } <EOL> response = self . client . post ( self . offer . get_absolute_url ( ) , post_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:2> ) <EOL> new_comment = Comment . objects . order_by ( '<STR_LIT:id>' ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( new_comment . reply_to , another_comment ) <EOL> def test_user_can_not_post_reply_to_comment_on_another_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> another_comment = mommy . make ( Comment ) <EOL> post_data = { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : another_comment . pk , <EOL> } <EOL> response = self . client . post ( self . offer . get_absolute_url ( ) , post_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:1> ) <EOL> class OfferListViewTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . offers = mommy . make ( Offer , _quantity = <NUM_LIT:20> , status = Offer . PUBLISHED ) <EOL> def test_offer_list_view_without_pagination ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> offers = Offer . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> : <NUM_LIT:5> ] <EOL> for offer in offers : <EOL> self . assertContains ( response , offer . name ) <EOL> class PlanListViewTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . providers = mommy . make ( Provider , _quantity = <NUM_LIT:5> ) <EOL> def test_user_can_view_providers ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> for provider in self . providers : <EOL> self . assertContains ( response , provider . name ) <EOL> class ProviderAdminRequestViewTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_user ( username = '<STR_LIT:user>' , email = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> self . provider = mommy . make ( Provider ) <EOL> self . user . user_profile . provider = self . provider <EOL> self . user . user_profile . save ( ) <EOL> self . offer = mommy . make ( <EOL> Offer , <EOL> provider = self . provider , <EOL> status = Offer . REQUEST_INCOMPLETE , <EOL> creator = self . user , <EOL> ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT:password>' ) <EOL> def test_user_can_view_provider_admin_profile ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , self . provider . name ) <EOL> def test_logged_out_user_can_not_view_provider_admin_profile ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . logout ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) , follow = True ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) + '<STR_LIT>' + reverse ( '<STR_LIT>' ) ) <EOL> self . assertNotContains ( response , self . provider . name ) <EOL> def test_unauthorized_user_can_not_view_provider_admin_profile ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_profile . provider = None <EOL> self . user . user_profile . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) , follow = True ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) + '<STR_LIT>' + reverse ( '<STR_LIT>' ) ) <EOL> self . assertNotContains ( response , self . provider . name ) <EOL> def test_user_can_modify_their_provider ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , self . provider . name ) <EOL> new_data = { <EOL> "<STR_LIT:name>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : self . provider . start_date , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , new_data , follow = True ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> new_provider = Provider . objects . get ( pk = self . provider . pk ) <EOL> self . assertEqual ( new_provider . name , '<STR_LIT>' ) <EOL> self . assertEqual ( new_provider . website , '<STR_LIT>' ) <EOL> self . assertEqual ( new_provider . tos , '<STR_LIT>' ) <EOL> def test_user_can_not_modify_their_provider_with_incorrect_information ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , self . provider . name ) <EOL> new_data = { <EOL> "<STR_LIT:name>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : self . provider . start_date , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , new_data , follow = True ) <EOL> new_provider = Provider . objects . get ( pk = self . provider . pk ) <EOL> self . assertNotEqual ( new_provider . name , '<STR_LIT>' ) <EOL> self . assertNotEqual ( new_provider . website , '<STR_LIT>' ) <EOL> self . assertEqual ( new_provider . name , self . provider . name ) <EOL> self . assertEqual ( new_provider . website , self . provider . website ) <EOL> def test_user_can_view_provider_admin_new_request ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_unauthorized_user_can_not_view_provider_admin_new_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_profile . provider = None <EOL> self . user . user_profile . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) , follow = True ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) + "<STR_LIT>" + reverse ( '<STR_LIT>' ) ) <EOL> self . assertNotContains ( response , self . provider . name ) <EOL> def test_user_can_view_provider_admin_edit_request ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , self . offer . name ) <EOL> self . assertContains ( response , self . offer . content ) <EOL> def test_user_can_not_view_other_provider_admin_edit_request ( self ) : <EOL> """<STR_LIT>""" <EOL> new_user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> offer = mommy . make ( Offer , status = Offer . REQUEST_INCOMPLETE , creator = new_user ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_not_view_published_admin_edit_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . status = Offer . PUBLISHED <EOL> self . offer . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_not_view_non_request_edit_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . status = Offer . PUBLISHED <EOL> self . offer . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . offer . status = Offer . UNPUBLISHED <EOL> self . offer . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_view_offer_request_list ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , self . offer . name ) <EOL> self . assertContains ( response , self . offer . creator . username ) <EOL> def test_unauthorized_user_can_not_view_offer_request_list ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_profile . provider = None <EOL> self . user . user_profile . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) , follow = True ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) + "<STR_LIT>" + reverse ( '<STR_LIT>' ) ) <EOL> self . assertNotContains ( response , self . provider . name ) <EOL> def test_user_can_view_offer_request_list_only_of_self ( self ) : <EOL> """<STR_LIT>""" <EOL> other_requests = mommy . make ( Offer , _quantity = <NUM_LIT:10> , is_request = True , status = Offer . UNPUBLISHED ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , self . offer . name ) <EOL> self . assertContains ( response , self . offer . creator . username ) <EOL> for other_request in other_requests : <EOL> self . assertNotContains ( response , other_request . name ) <EOL> def test_user_can_view_delete_request ( self ) : <EOL> """<STR_LIT>""" <EOL> plans = mommy . make ( Plan , _quantity = <NUM_LIT:4> , offer = self . offer ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , self . offer . name ) <EOL> for plan in plans : <EOL> self . assertContains ( response , plan . get_memory ( ) ) <EOL> def test_user_can_perform_delete_request ( self ) : <EOL> """<STR_LIT>""" <EOL> plans = mommy . make ( Plan , _quantity = <NUM_LIT:4> , offer = self . offer ) <EOL> response = self . client . get ( <EOL> reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) + '<STR_LIT>' , <EOL> follow = True <EOL> ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> self . assertNotContains ( response , self . offer . name ) <EOL> self . assertFalse ( Offer . objects . filter ( pk = self . offer . pk ) . exists ( ) ) <EOL> for plan in plans : <EOL> self . assertFalse ( Plan . objects . filter ( pk = plan . pk ) . exists ( ) ) <EOL> def test_unauthorized_user_can_not_view_delete_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_profile . provider = None <EOL> self . user . user_profile . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , follow = True ) <EOL> self . assertRedirects ( <EOL> response , <EOL> reverse ( '<STR_LIT>' ) + "<STR_LIT>" + reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) <EOL> ) <EOL> self . assertNotContains ( response , self . provider . name ) <EOL> class ProviderAdminOfferViewTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_user ( username = '<STR_LIT:user>' , email = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> self . provider = mommy . make ( Provider ) <EOL> self . user . user_profile . provider = self . provider <EOL> self . user . user_profile . save ( ) <EOL> self . offer = mommy . make ( Offer , provider = self . provider , status = Offer . UNPUBLISHED , creator = self . user ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT:password>' ) <EOL> def test_user_can_view_offer_list ( self ) : <EOL> """<STR_LIT>""" <EOL> offers = mommy . make ( Offer , provider = self . provider , _quantity = <NUM_LIT:20> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( self . provider , response . context [ "<STR_LIT>" ] ) <EOL> for offer in offers : <EOL> self . assertIn ( offer , response . context [ "<STR_LIT>" ] ) <EOL> def test_offer_list_does_not_contain_offer_requests ( self ) : <EOL> """<STR_LIT>""" <EOL> offers = mommy . make ( Offer , provider = self . provider , _quantity = <NUM_LIT:20> ) <EOL> offer_requests = mommy . make ( <EOL> Offer , <EOL> provider = self . provider , <EOL> status = Offer . REQUEST_INCOMPLETE , <EOL> _quantity = <NUM_LIT:20> <EOL> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( self . provider , response . context [ "<STR_LIT>" ] ) <EOL> for offer in offers : <EOL> self . assertIn ( offer , response . context [ "<STR_LIT>" ] ) <EOL> for offer_request in offer_requests : <EOL> self . assertNotIn ( offer_request , response . context [ "<STR_LIT>" ] ) <EOL> def test_user_can_mark_offer_as_active ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . is_active = False <EOL> self . offer . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , follow = True ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> updated_offer = Offer . objects . get ( pk = self . offer . pk ) <EOL> self . assertTrue ( updated_offer . is_active ) <EOL> def test_user_can_mark_offer_as_inactive ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . is_active = True <EOL> self . offer . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , follow = True ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> updated_offer = Offer . objects . get ( pk = self . offer . pk ) <EOL> self . assertFalse ( updated_offer . is_active ) <EOL> def test_user_can_not_mark_other_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> new_offer = mommy . make ( Offer , is_active = True ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ new_offer . pk ] ) , follow = True ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> updated_offer = Offer . objects . get ( pk = new_offer . pk ) <EOL> self . assertTrue ( updated_offer . is_active ) <EOL> def test_user_can_not_mark_offer_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . status = Offer . REQUEST_INCOMPLETE <EOL> self . offer . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , follow = True ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> updated_offer = Offer . objects . get ( pk = self . offer . pk ) <EOL> self . assertTrue ( updated_offer . is_active ) <EOL> def test_user_can_mark_plan_as_active ( self ) : <EOL> """<STR_LIT>""" <EOL> plan = mommy . make ( Plan , offer = self . offer , is_active = False ) <EOL> response = self . client . get ( <EOL> reverse ( '<STR_LIT>' , args = [ self . offer . pk , plan . pk ] ) , <EOL> follow = True <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) ) <EOL> updated_plan = Plan . objects . get ( pk = plan . pk ) <EOL> self . assertTrue ( updated_plan . is_active ) <EOL> def test_user_can_mark_plan_as_inactive ( self ) : <EOL> """<STR_LIT>""" <EOL> plan = mommy . make ( Plan , offer = self . offer , is_active = True ) <EOL> response = self . client . get ( <EOL> reverse ( '<STR_LIT>' , args = [ self . offer . pk , plan . pk ] ) , <EOL> follow = True <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) ) <EOL> updated_plan = Plan . objects . get ( pk = plan . pk ) <EOL> self . assertFalse ( updated_plan . is_active ) <EOL> def test_user_can_not_mark_other_offer_plan ( self ) : <EOL> """<STR_LIT>""" <EOL> new_offer = mommy . make ( Offer , is_active = True ) <EOL> plan = mommy . make ( Plan , offer = new_offer , is_active = True ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ new_offer . pk , plan . pk ] ) , follow = True ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> updated_plan = Plan . objects . get ( pk = plan . pk ) <EOL> self . assertTrue ( updated_plan . is_active ) <EOL> def test_user_can_not_mark_non_existent_plan ( self ) : <EOL> """<STR_LIT>""" <EOL> plan = mommy . make ( Plan , is_active = True ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk , plan . pk ] ) , follow = True ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> updated_plan = Plan . objects . get ( pk = plan . pk ) <EOL> self . assertTrue ( updated_plan . is_active ) <EOL> def test_user_can_not_mark_offer_request_plan ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . status = Offer . REQUEST_INCOMPLETE <EOL> self . offer . save ( ) <EOL> plan = mommy . make ( Plan , offer = self . offer , is_active = True ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk , plan . pk ] ) , follow = True ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> updated_plan = Plan . objects . get ( pk = plan . pk ) <EOL> self . assertTrue ( updated_plan . is_active ) <EOL> def test_user_can_view_offer_edit_page ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Plan , offer = self . offer , _quantity = <NUM_LIT:5> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ "<STR_LIT>" ] , self . offer ) <EOL> self . assertQuerysetEqual ( response . context [ "<STR_LIT>" ] , map ( repr , self . offer . plan_set . all ( ) ) , ordered = False ) <EOL> def test_user_can_not_view_offer_edit_page_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . status = Offer . REQUEST_INCOMPLETE <EOL> self . offer . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_not_view_offer_edit_page_of_other_provider ( self ) : <EOL> """<STR_LIT>""" <EOL> other_offer = mommy . make ( Offer ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ other_offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_not_view_offer_update_page_of_other_provider ( self ) : <EOL> """<STR_LIT>""" <EOL> other_offer = mommy . make ( Offer ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ other_offer . pk ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> class ProviderNewRequestViewTests ( WebTest ) : <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_user ( username = '<STR_LIT:user>' , email = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> self . provider = mommy . make ( Provider ) <EOL> self . user . user_profile . provider = self . provider <EOL> self . user . user_profile . save ( ) <EOL> self . location = mommy . make ( Location , provider = self . provider ) <EOL> def test_providers_can_view_new_request_page ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_user_can_not_view_new_request_page ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user . user_profile . provider = None <EOL> self . user . user_profile . save ( ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT:password>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) , follow = True ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) + '<STR_LIT>' + reverse ( '<STR_LIT>' ) ) <EOL> def test_user_can_submit_no_plans_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:0> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT:name>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT:content>" ] = "<STR_LIT>" <EOL> response = form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:0> ) <EOL> offer = Offer . objects . latest ( '<STR_LIT>' ) <EOL> self . assertEqual ( offer . status , Offer . REQUEST_INCOMPLETE ) <EOL> self . assertEqual ( offer . creator , self . user ) <EOL> self . assertEqual ( offer . name , '<STR_LIT>' ) <EOL> self . assertEqual ( offer . content , '<STR_LIT>' ) <EOL> self . assertEqual ( offer . is_active , True ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' , args = [ offer . pk ] ) ) <EOL> def test_user_can_submit_with_plan_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:0> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT:name>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT:content>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = Plan . KVM <EOL> form [ "<STR_LIT>" ] = self . location . pk <EOL> form [ "<STR_LIT>" ] = <NUM_LIT:16> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = Plan . YEARLY <EOL> form [ "<STR_LIT>" ] = '<STR_LIT>' <EOL> form [ "<STR_LIT>" ] = '<STR_LIT>' <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> response = form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:1> ) <EOL> offer = Offer . objects . latest ( '<STR_LIT>' ) <EOL> self . assertEqual ( offer . creator , self . user ) <EOL> self . assertEqual ( offer . name , '<STR_LIT>' ) <EOL> self . assertEqual ( offer . content , '<STR_LIT>' ) <EOL> self . assertEqual ( offer . status , Offer . REQUEST_INCOMPLETE ) <EOL> self . assertEqual ( offer . is_active , True ) <EOL> plan = Plan . objects . latest ( '<STR_LIT>' ) <EOL> self . assertEqual ( plan . bandwidth , <NUM_LIT> ) <EOL> self . assertEqual ( plan . disk_space , <NUM_LIT> ) <EOL> self . assertEqual ( plan . memory , <NUM_LIT> ) <EOL> self . assertEqual ( plan . server_type , Plan . KVM ) <EOL> self . assertIn ( self . location , plan . locations . all ( ) ) <EOL> self . assertEqual ( plan . locations . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( plan . ipv4_space , <NUM_LIT:16> ) <EOL> self . assertEqual ( plan . ipv6_space , <NUM_LIT> ) <EOL> self . assertEqual ( plan . billing_time , Plan . YEARLY ) <EOL> self . assertEqual ( plan . url , '<STR_LIT>' ) <EOL> self . assertEqual ( plan . promo_code , "<STR_LIT>" ) <EOL> self . assertEqual ( plan . cost , <NUM_LIT> ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' , args = [ offer . pk ] ) ) <EOL> def test_user_can_submit_with_multiple_plans_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:0> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT:name>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT:content>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = Plan . KVM <EOL> form [ "<STR_LIT>" ] = self . location . pk <EOL> form [ "<STR_LIT>" ] = <NUM_LIT:16> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = Plan . YEARLY <EOL> form [ "<STR_LIT>" ] = '<STR_LIT>' <EOL> form [ "<STR_LIT>" ] = '<STR_LIT>' <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = Plan . KVM <EOL> form [ "<STR_LIT>" ] = self . location . pk <EOL> form [ "<STR_LIT>" ] = <NUM_LIT:16> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = Plan . YEARLY <EOL> form [ "<STR_LIT>" ] = '<STR_LIT>' <EOL> form [ "<STR_LIT>" ] = '<STR_LIT>' <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> response = form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:2> ) <EOL> offer = Offer . objects . latest ( '<STR_LIT>' ) <EOL> self . assertEqual ( offer . creator , self . user ) <EOL> self . assertEqual ( offer . name , '<STR_LIT>' ) <EOL> self . assertEqual ( offer . content , '<STR_LIT>' ) <EOL> self . assertEqual ( offer . status , Offer . REQUEST_INCOMPLETE ) <EOL> self . assertEqual ( offer . is_active , True ) <EOL> plan1 = Plan . objects . order_by ( '<STR_LIT:id>' ) [ <NUM_LIT:0> ] <EOL> plan2 = Plan . objects . order_by ( '<STR_LIT:id>' ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( plan1 . bandwidth , <NUM_LIT> ) <EOL> self . assertEqual ( plan2 . bandwidth , <NUM_LIT> ) <EOL> self . assertIn ( self . location , plan1 . locations . all ( ) ) <EOL> self . assertIn ( self . location , plan2 . locations . all ( ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' , args = [ offer . pk ] ) ) <EOL> def test_user_can_not_submit_invalid_form ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:0> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT:name>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT:content>" ] = "<STR_LIT>" <EOL> response = form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_user_can_not_submit_with_invalid_plans_form ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:0> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT:name>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT:content>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> response = form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_user_locations_are_present ( self ) : <EOL> """<STR_LIT>""" <EOL> self . location . delete ( ) <EOL> locations = mommy . make ( Location , provider = self . provider , _quantity = <NUM_LIT:20> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> options = response . html . find ( '<STR_LIT>' , id = "<STR_LIT>" ) . find_all ( "<STR_LIT:input>" ) <EOL> options = [ option . get ( '<STR_LIT:value>' ) for option in options ] <EOL> for location in locations : <EOL> self . assertIn ( unicode ( location . pk ) , options ) <EOL> self . assertEqual ( len ( options ) , <NUM_LIT:20> ) <EOL> def test_other_user_locations_are_not_present ( self ) : <EOL> """<STR_LIT>""" <EOL> self . location . delete ( ) <EOL> locations = mommy . make ( Location , provider = self . provider , _quantity = <NUM_LIT:20> ) <EOL> other_locations = mommy . make ( Location , _quantity = <NUM_LIT:20> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> options = response . html . find ( '<STR_LIT>' , id = "<STR_LIT>" ) . find_all ( "<STR_LIT:input>" ) <EOL> options = [ option . get ( '<STR_LIT:value>' ) for option in options ] <EOL> for location in locations : <EOL> self . assertIn ( unicode ( location . pk ) , options ) <EOL> for location in other_locations : <EOL> self . assertNotIn ( unicode ( location . pk ) , options ) <EOL> self . assertEqual ( len ( options ) , <NUM_LIT:20> ) <EOL> class ProviderEditRequestViewTests ( WebTest ) : <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_user ( username = '<STR_LIT:user>' , email = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> self . provider = mommy . make ( Provider ) <EOL> self . user . user_profile . provider = self . provider <EOL> self . user . user_profile . save ( ) <EOL> self . offer = mommy . make ( <EOL> Offer , <EOL> provider = self . provider , <EOL> status = Offer . REQUEST_INCOMPLETE , <EOL> creator = self . user <EOL> ) <EOL> self . location = mommy . make ( Location , provider = self . provider ) <EOL> self . plans = mommy . make ( <EOL> Plan , <EOL> offer = self . offer , <EOL> _quantity = <NUM_LIT:2> , <EOL> locations = [ self . location ] , <EOL> cost = <NUM_LIT> , <EOL> url = "<STR_LIT>" <EOL> ) <EOL> def test_edit_request_page_contains_correct_details ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . app . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , user = self . user ) <EOL> form = response . form <EOL> self . assertEqual ( form [ "<STR_LIT:name>" ] . value , self . offer . name ) <EOL> self . assertEqual ( form [ "<STR_LIT:content>" ] . value , self . offer . content ) <EOL> plan = self . plans [ <NUM_LIT:0> ] <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . bandwidth ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . disk_space ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . memory ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , plan . server_type ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . locations . all ( ) [ <NUM_LIT:0> ] . pk ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . ipv4_space ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . ipv6_space ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , plan . billing_time ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , plan . url ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , plan . promo_code ) <EOL> self . assertEqual ( float ( form [ "<STR_LIT>" ] . value ) , float ( plan . cost ) ) <EOL> plan = self . plans [ <NUM_LIT:1> ] <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . bandwidth ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . disk_space ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . memory ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , plan . server_type ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . locations . all ( ) [ <NUM_LIT:0> ] . pk ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . ipv4_space ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( plan . ipv6_space ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , plan . billing_time ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , plan . url ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , plan . promo_code ) <EOL> self . assertEqual ( float ( form [ "<STR_LIT>" ] . value ) , float ( plan . cost ) ) <EOL> def test_edit_request_page_can_edit_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . app . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT:name>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT:content>" ] = "<STR_LIT>" <EOL> form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:2> ) <EOL> offer = Offer . objects . get ( pk = self . offer . pk ) <EOL> self . assertEqual ( offer . status , Offer . REQUEST_INCOMPLETE ) <EOL> self . assertEqual ( offer . name , "<STR_LIT>" ) <EOL> self . assertEqual ( offer . content , "<STR_LIT>" ) <EOL> def test_edit_request_page_can_edit_plans ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . app . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT:1> <EOL> form [ "<STR_LIT>" ] = <NUM_LIT:16> <EOL> form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Offer . objects . filter ( status = Offer . REQUEST_INCOMPLETE ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:2> ) <EOL> plan1 = Plan . objects . order_by ( '<STR_LIT:id>' ) [ <NUM_LIT:0> ] <EOL> plan2 = Plan . objects . order_by ( '<STR_LIT:id>' ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( plan1 . bandwidth , <NUM_LIT> ) <EOL> self . assertEqual ( plan1 . disk_space , <NUM_LIT> ) <EOL> self . assertEqual ( plan2 . ipv4_space , <NUM_LIT:1> ) <EOL> self . assertEqual ( plan2 . ipv6_space , <NUM_LIT:16> ) <EOL> def test_edit_request_page_can_delete_plan ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Offer . objects . filter ( status = Offer . REQUEST_INCOMPLETE ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:2> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT>" ] = True <EOL> form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Offer . objects . filter ( status = Offer . REQUEST_INCOMPLETE ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:1> ) <EOL> def test_edit_request_page_can_delete_multiple_plans ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Offer . objects . filter ( status = Offer . REQUEST_INCOMPLETE ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:2> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT>" ] = True <EOL> form [ "<STR_LIT>" ] = True <EOL> form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Offer . objects . filter ( status = Offer . REQUEST_INCOMPLETE ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_edit_request_can_not_edit_with_invalid_data ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . app . get ( reverse ( '<STR_LIT>' , args = [ self . offer . pk ] ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT:name>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT:content>" ] = "<STR_LIT>" <EOL> form . submit ( ) <EOL> self . assertEqual ( Offer . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Offer . objects . filter ( status = Offer . REQUEST_INCOMPLETE ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Plan . objects . count ( ) , <NUM_LIT:2> ) <EOL> offer = Offer . objects . get ( pk = self . offer . pk ) <EOL> self . assertEqual ( offer . name , self . offer . name ) <EOL> self . assertEqual ( offer . content , self . offer . content ) <EOL> self . assertNotEqual ( offer . name , "<STR_LIT>" ) <EOL> self . assertNotEqual ( offer . content , "<STR_LIT>" ) <EOL> class ProviderLocationsListViewTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_user ( username = '<STR_LIT:user>' , email = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> self . provider = mommy . make ( Provider ) <EOL> self . user . user_profile . provider = self . provider <EOL> self . user . user_profile . save ( ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT:password>' ) <EOL> self . locations = mommy . make ( Location , provider = self . provider , _quantity = <NUM_LIT:10> ) <EOL> def test_locations_list_contains_all_of_own_locations ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> for location in self . locations : <EOL> self . assertContains ( response , location . country . flag ) <EOL> self . assertContains ( response , location . city ) <EOL> def test_locations_list_does_not_contain_other_provider_locations ( self ) : <EOL> """<STR_LIT>""" <EOL> provider_locations = mommy . make ( Location , _quantity = <NUM_LIT:10> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> for location in provider_locations : <EOL> self . assertNotContains ( response , location . city ) <EOL> class ProviderLocationNewViewTests ( WebTest ) : <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_user ( username = '<STR_LIT:user>' , email = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> self . provider = mommy . make ( Provider ) <EOL> self . user . user_profile . provider = self . provider <EOL> self . user . user_profile . save ( ) <EOL> self . datacenter = mommy . make ( Datacenter ) <EOL> def test_can_view_new_provider_page ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_can_add_location_with_no_ip_no_downloads ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:0> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = self . datacenter . pk <EOL> form . submit ( ) <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:0> ) <EOL> location = Location . objects . latest ( '<STR_LIT>' ) <EOL> self . assertEqual ( location . city , "<STR_LIT>" ) <EOL> self . assertEqual ( location . country , "<STR_LIT>" ) <EOL> self . assertEqual ( location . datacenter , self . datacenter ) <EOL> def test_can_not_add_location_with_incorrect_details ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:0> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = self . datacenter . pk <EOL> form . submit ( ) <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_can_add_location_with_ip_and_download ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:0> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = self . datacenter . pk <EOL> form [ "<STR_LIT>" ] = "<STR_LIT:127.0.0.1>" <EOL> form [ "<STR_LIT>" ] = TestIP . IPV4 <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form . submit ( ) <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:1> ) <EOL> location = Location . objects . latest ( '<STR_LIT>' ) <EOL> ip = TestIP . objects . latest ( '<STR_LIT>' ) <EOL> download = TestDownload . objects . latest ( '<STR_LIT>' ) <EOL> self . assertEqual ( location . city , "<STR_LIT>" ) <EOL> self . assertEqual ( location . country , "<STR_LIT>" ) <EOL> self . assertEqual ( location . datacenter , self . datacenter ) <EOL> self . assertEqual ( ip . ip , "<STR_LIT:127.0.0.1>" ) <EOL> self . assertEqual ( ip . ip_type , TestIP . IPV4 ) <EOL> self . assertEqual ( ip . location , location ) <EOL> self . assertEqual ( download . url , "<STR_LIT>" ) <EOL> self . assertEqual ( download . size , <NUM_LIT> ) <EOL> self . assertEqual ( download . location , location ) <EOL> class ProviderLocationEditViewTests ( WebTest ) : <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_user ( username = '<STR_LIT:user>' , email = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> self . provider = mommy . make ( Provider ) <EOL> self . user . user_profile . provider = self . provider <EOL> self . user . user_profile . save ( ) <EOL> self . datacenter = mommy . make ( Datacenter ) <EOL> self . location = mommy . make ( Location , provider = self . provider , datacenter = self . datacenter ) <EOL> self . ips = mommy . make ( TestIP , _quantity = <NUM_LIT:2> , location = self . location , ip = '<STR_LIT:127.0.0.1>' ) <EOL> self . downloads = mommy . make ( TestDownload , _quantity = <NUM_LIT:2> , location = self . location , url = '<STR_LIT>' ) <EOL> def test_edit_location_page_contains_correct_data ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:2> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' , args = [ self . location . pk ] ) , user = self . user ) <EOL> form = response . form <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , self . location . city ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , self . location . country ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , str ( self . datacenter . pk ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , self . ips [ <NUM_LIT:0> ] . ip ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , self . ips [ <NUM_LIT:0> ] . ip_type ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , self . ips [ <NUM_LIT:1> ] . ip ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , self . ips [ <NUM_LIT:1> ] . ip_type ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , self . downloads [ <NUM_LIT:0> ] . url ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( self . downloads [ <NUM_LIT:0> ] . size ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , self . downloads [ <NUM_LIT:1> ] . url ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . value , unicode ( self . downloads [ <NUM_LIT:1> ] . size ) ) <EOL> def test_user_can_update_location_data ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:2> ) <EOL> new_data_center = mommy . make ( Datacenter ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' , args = [ self . location . pk ] ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = new_data_center . pk <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = <NUM_LIT> <EOL> form . submit ( ) <EOL> location = Location . objects . get ( pk = self . location . pk ) <EOL> ip = TestIP . objects . get ( pk = self . ips [ <NUM_LIT:0> ] . pk ) <EOL> download = TestDownload . objects . get ( pk = self . downloads [ <NUM_LIT:0> ] . pk ) <EOL> self . assertEqual ( location . city , "<STR_LIT>" ) <EOL> self . assertEqual ( location . country , "<STR_LIT>" ) <EOL> self . assertEqual ( location . datacenter , new_data_center ) <EOL> self . assertEqual ( ip . ip , "<STR_LIT>" ) <EOL> self . assertEqual ( download . url , "<STR_LIT>" ) <EOL> self . assertEqual ( download . size , <NUM_LIT> ) <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:2> ) <EOL> def test_user_can_not_update_location_with_incorrect_data ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:2> ) <EOL> response = self . app . get ( reverse ( '<STR_LIT>' , args = [ self . location . pk ] ) , user = self . user ) <EOL> form = response . form <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> form [ "<STR_LIT>" ] = self . datacenter . pk <EOL> response = form . submit ( ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> location = Location . objects . get ( pk = self . location . pk ) <EOL> self . assertEqual ( location . city , self . location . city ) <EOL> self . assertEqual ( Location . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( TestIP . objects . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( TestDownload . objects . count ( ) , <NUM_LIT:2> ) <EOL> class LikeCommentViewTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_user ( '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . commenter = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . comment = mommy . make ( Comment , commenter = self . commenter , offer__status = Offer . PUBLISHED ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT>' ) <EOL> self . like_url = reverse ( "<STR_LIT>" , args = [ self . comment . pk ] ) <EOL> def test_logged_out_user_can_not_like_a_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . logout ( ) <EOL> response = self . client . get ( self . like_url ) <EOL> self . assertRedirects ( response , reverse ( "<STR_LIT>" ) + "<STR_LIT>" + self . like_url ) <EOL> def test_user_can_not_like_unpublished_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> self . comment . status = Comment . UNPUBLISHED <EOL> self . comment . save ( ) <EOL> response = self . client . get ( self . like_url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_not_like_deleted_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> self . comment . status = Comment . DELETED <EOL> self . comment . save ( ) <EOL> response = self . client . get ( self . like_url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_not_like_offer_unpublished_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> self . comment . offer . status = Offer . UNPUBLISHED <EOL> self . comment . offer . save ( ) <EOL> response = self . client . get ( self . like_url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_not_like_offer_request_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> self . comment . offer . status = Offer . REQUEST_INCOMPLETE <EOL> self . comment . offer . save ( ) <EOL> response = self . client . get ( self . like_url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_not_like_own_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> self . comment . commenter = self . user <EOL> self . comment . save ( ) <EOL> response = self . client . get ( self . like_url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_user_can_like_an_unliked_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Like . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . user . like_set . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:0> ) <EOL> self . assertFalse ( self . comment . does_like ( self . user ) ) <EOL> self . client . get ( self . like_url ) <EOL> self . assertEqual ( Like . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . user . like_set . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( self . comment . does_like ( self . user ) ) <EOL> like = Like . objects . latest ( '<STR_LIT>' ) <EOL> self . assertEqual ( like . user , self . user ) <EOL> self . assertEqual ( like . comment , self . comment ) <EOL> def test_user_can_unlike_liked_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> like = mommy . make ( Like , user = self . user , comment = self . comment ) <EOL> self . assertEqual ( Like . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . user . like_set . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( self . comment . does_like ( self . user ) ) <EOL> self . client . get ( self . like_url ) <EOL> self . assertEqual ( Like . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . user . like_set . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:0> ) <EOL> self . assertFalse ( self . comment . does_like ( self . user ) ) <EOL> def test_like_view_toggles_data_correctly ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Like . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . user . like_set . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:0> ) <EOL> self . assertFalse ( self . comment . does_like ( self . user ) ) <EOL> self . client . get ( self . like_url ) <EOL> self . assertEqual ( Like . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . user . like_set . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( self . comment . does_like ( self . user ) ) <EOL> self . client . get ( self . like_url ) <EOL> self . assertEqual ( Like . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . user . like_set . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:0> ) <EOL> self . assertFalse ( self . comment . does_like ( self . user ) ) <EOL> self . client . get ( self . like_url ) <EOL> self . assertEqual ( Like . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . user . like_set . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( self . comment . does_like ( self . user ) ) <EOL> self . client . get ( self . like_url ) </s>
