<s> from django . test import TestCase <EOL> from offers . models import Offer , Provider , Plan , Comment , Location , Like <EOL> from model_mommy import mommy <EOL> from django . core . files import File <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> import os <EOL> from datetime import timedelta <EOL> from decimal import Decimal <EOL> from django . utils . text import slugify <EOL> from django . core . urlresolvers import reverse <EOL> class OfferMethodTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . provider = mommy . make ( Provider ) <EOL> self . offer = mommy . make ( Offer , provider = self . provider , status = Offer . PUBLISHED ) <EOL> self . user = User . objects . create_user ( '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . user . user_profile . provider = self . provider <EOL> self . user . user_profile . save ( ) <EOL> def test_unicode_string ( self ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" . format ( self . offer . name , self . offer . provider . name ) <EOL> self . assertEqual ( name , self . offer . __unicode__ ( ) ) <EOL> def test_plan_count ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Plan , _quantity = <NUM_LIT:4> , offer = self . offer ) <EOL> self . assertEqual ( self . offer . plan_count ( ) , <NUM_LIT:4> ) <EOL> def test_min_cost ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:100> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:50> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:11> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:10> ) <EOL> self . assertEqual ( <NUM_LIT:10> , self . offer . min_cost ( ) ) <EOL> def test_min_cost_with_other ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Plan , cost = <NUM_LIT:5> ) <EOL> mommy . make ( Plan , cost = <NUM_LIT:10> ) <EOL> mommy . make ( Plan , cost = <NUM_LIT:20> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:100> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:50> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:11> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:10> ) <EOL> self . assertEqual ( <NUM_LIT:10> , self . offer . min_cost ( ) ) <EOL> def test_max_cost ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:50> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:100> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT> , self . offer . max_cost ( ) ) <EOL> def test_max_cost_with_other ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Plan , cost = <NUM_LIT:100> ) <EOL> mommy . make ( Plan , cost = <NUM_LIT> ) <EOL> mommy . make ( Plan , cost = <NUM_LIT> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:50> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT:100> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT> ) <EOL> mommy . make ( Plan , offer = self . offer , cost = <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT> , self . offer . max_cost ( ) ) <EOL> def test_get_comments_published ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Comment , _quantity = <NUM_LIT:20> ) <EOL> comments = mommy . make ( Comment , offer = self . offer , _quantity = <NUM_LIT:10> , status = Comment . PUBLISHED ) <EOL> self . assertEqual ( <NUM_LIT:10> , self . offer . get_comments ( ) . count ( ) ) <EOL> for comment in comments : <EOL> self . assertIn ( comment , self . offer . get_comments ( ) ) <EOL> def test_get_comments_unpublished ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Comment , _quantity = <NUM_LIT:20> ) <EOL> comments = mommy . make ( Comment , offer = self . offer , _quantity = <NUM_LIT:20> , status = Comment . UNPUBLISHED ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:0> ) <EOL> def test_get_comments_deleted ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Comment , _quantity = <NUM_LIT:20> ) <EOL> comments = mommy . make ( Comment , offer = self . offer , _quantity = <NUM_LIT:20> , status = Comment . DELETED ) <EOL> self . assertEqual ( self . offer . get_comments ( ) . count ( ) , <NUM_LIT:0> ) <EOL> def test_get_min_max_gets_correct_values_for_monthly ( self ) : <EOL> """<STR_LIT>""" <EOL> plan_min = mommy . make ( Plan , offer = self . offer , billing_time = Plan . MONTHLY , cost = <NUM_LIT> ) <EOL> plan_mid = mommy . make ( Plan , offer = self . offer , billing_time = Plan . MONTHLY , cost = <NUM_LIT> ) <EOL> plan_max = mommy . make ( Plan , offer = self . offer , billing_time = Plan . MONTHLY , cost = <NUM_LIT> ) <EOL> min_max = self . offer . get_min_max_cost ( ) <EOL> self . assertEqual ( len ( min_max ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT:name>" ] , plan_mid . get_billing_time_display ( ) ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT:code>" ] , Plan . MONTHLY ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertFalse ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> def test_get_min_max_gets_correct_values_for_yearly ( self ) : <EOL> """<STR_LIT>""" <EOL> plan_min = mommy . make ( Plan , offer = self . offer , billing_time = Plan . YEARLY , cost = <NUM_LIT> ) <EOL> plan_mid = mommy . make ( Plan , offer = self . offer , billing_time = Plan . YEARLY , cost = <NUM_LIT> ) <EOL> plan_max = mommy . make ( Plan , offer = self . offer , billing_time = Plan . YEARLY , cost = <NUM_LIT> ) <EOL> min_max = self . offer . get_min_max_cost ( ) <EOL> self . assertEqual ( len ( min_max ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT:name>" ] , plan_mid . get_billing_time_display ( ) ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT:code>" ] , Plan . YEARLY ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertFalse ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> def test_get_min_max_sets_same_with_one_plan ( self ) : <EOL> """<STR_LIT>""" <EOL> plan = mommy . make ( Plan , offer = self . offer , billing_time = Plan . MONTHLY , cost = <NUM_LIT> ) <EOL> min_max = self . offer . get_min_max_cost ( ) <EOL> self . assertEqual ( len ( min_max ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT:name>" ] , plan . get_billing_time_display ( ) ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT:code>" ] , Plan . MONTHLY ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertTrue ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> def test_get_min_max_gets_correct_values_two_billing_periods ( self ) : <EOL> """<STR_LIT>""" <EOL> plan_month_min = mommy . make ( Plan , offer = self . offer , billing_time = Plan . MONTHLY , cost = <NUM_LIT> ) <EOL> plan_month_mid = mommy . make ( Plan , offer = self . offer , billing_time = Plan . MONTHLY , cost = <NUM_LIT> ) <EOL> plan_month_max = mommy . make ( Plan , offer = self . offer , billing_time = Plan . MONTHLY , cost = <NUM_LIT> ) <EOL> plan_year_min = mommy . make ( Plan , offer = self . offer , billing_time = Plan . YEARLY , cost = <NUM_LIT> ) <EOL> plan_year_mid = mommy . make ( Plan , offer = self . offer , billing_time = Plan . YEARLY , cost = <NUM_LIT> ) <EOL> plan_year_max = mommy . make ( Plan , offer = self . offer , billing_time = Plan . YEARLY , cost = <NUM_LIT> ) <EOL> min_max = self . offer . get_min_max_cost ( ) <EOL> self . assertEqual ( len ( min_max ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT:name>" ] , plan_month_mid . get_billing_time_display ( ) ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT:code>" ] , Plan . MONTHLY ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertFalse ( min_max [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:1> ] [ "<STR_LIT:name>" ] , plan_year_mid . get_billing_time_display ( ) ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:1> ] [ "<STR_LIT:code>" ] , Plan . YEARLY ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:1> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertEqual ( min_max [ <NUM_LIT:1> ] [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> self . assertFalse ( min_max [ <NUM_LIT:1> ] [ "<STR_LIT>" ] ) <EOL> def test_offer_active_gives_correct_offer_for_active_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . is_active = True <EOL> self . offer . status = Offer . PUBLISHED <EOL> self . offer . save ( ) <EOL> self . assertTrue ( self . offer . offer_active ( ) ) <EOL> def test_offer_active_gives_result_for_inactive_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . is_active = False <EOL> self . offer . status = Offer . PUBLISHED <EOL> self . offer . save ( ) <EOL> self . assertFalse ( self . offer . offer_active ( ) ) <EOL> self . offer . is_active = True <EOL> self . offer . status = Offer . UNPUBLISHED <EOL> self . offer . save ( ) <EOL> self . assertFalse ( self . offer . offer_active ( ) ) <EOL> def test_queue_position_gives_correct_position ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . delete ( ) <EOL> offers = mommy . make ( Offer , _quantity = <NUM_LIT:5> , status = Offer . REQUEST_COMPLETE ) <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:2> , status = Offer . REQUEST_INCOMPLETE ) <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:2> , status = Offer . PUBLISHED ) <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:2> , status = Offer . UNPUBLISHED ) <EOL> offers [ <NUM_LIT:0> ] . readied_at -= timedelta ( days = <NUM_LIT:5> ) <EOL> offers [ <NUM_LIT:1> ] . readied_at -= timedelta ( days = <NUM_LIT:4> ) <EOL> offers [ <NUM_LIT:2> ] . readied_at -= timedelta ( days = <NUM_LIT:3> ) <EOL> offers [ <NUM_LIT:3> ] . readied_at -= timedelta ( days = <NUM_LIT:2> ) <EOL> offers [ <NUM_LIT:4> ] . readied_at -= timedelta ( days = <NUM_LIT:1> ) <EOL> for offer in offers : <EOL> offer . save ( ) <EOL> self . assertEqual ( offers [ <NUM_LIT:0> ] . queue_position ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( offers [ <NUM_LIT:1> ] . queue_position ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( offers [ <NUM_LIT:2> ] . queue_position ( ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( offers [ <NUM_LIT:3> ] . queue_position ( ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( offers [ <NUM_LIT:4> ] . queue_position ( ) , <NUM_LIT:5> ) <EOL> def test_queue_position_with_not_ready_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . is_ready = False <EOL> self . offer . save ( ) <EOL> self . assertEqual ( self . offer . queue_position ( ) , None ) <EOL> def test_queue_position_with_published_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . status = Offer . PUBLISHED <EOL> self . offer . save ( ) <EOL> self . assertEqual ( self . offer . queue_position ( ) , None ) <EOL> def test_queue_position_with_not_request_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> self . offer . is_request = False <EOL> self . offer . save ( ) <EOL> self . assertEqual ( self . offer . queue_position ( ) , None ) <EOL> def test_get_plan_locations_gets_correct_unique_locations ( self ) : <EOL> """<STR_LIT>""" <EOL> location1 = mommy . make ( Location , provider = self . provider ) <EOL> location2 = mommy . make ( Location , provider = self . provider ) <EOL> location3 = mommy . make ( Location , provider = self . provider ) <EOL> mommy . make ( Plan , _quantity = <NUM_LIT:5> , locations = [ location1 ] , offer = self . offer ) <EOL> mommy . make ( Plan , _quantity = <NUM_LIT:5> , locations = [ location2 ] , offer = self . offer ) <EOL> mommy . make ( Plan , _quantity = <NUM_LIT:5> , locations = [ location3 ] , offer = self . offer ) <EOL> locations = self . offer . get_plan_locations ( ) <EOL> self . assertEqual ( len ( locations ) , <NUM_LIT:3> ) <EOL> self . assertIn ( location1 , locations ) <EOL> self . assertIn ( location2 , locations ) <EOL> self . assertIn ( location3 , locations ) <EOL> def test_get_plan_locations_does_not_get_other_locations ( self ) : <EOL> """<STR_LIT>""" <EOL> location1 = mommy . make ( Location , provider = self . provider ) <EOL> location2 = mommy . make ( Location , provider = self . provider ) <EOL> location3 = mommy . make ( Location , provider = self . provider ) <EOL> mommy . make ( Plan , _quantity = <NUM_LIT:5> , locations = [ location1 ] , offer = self . offer ) <EOL> mommy . make ( Plan , _quantity = <NUM_LIT:5> , locations = [ location2 ] , offer = self . offer ) <EOL> mommy . make ( Plan , _quantity = <NUM_LIT:5> , locations = [ location3 ] , offer = self . offer ) <EOL> mommy . make ( Plan , _quantity = <NUM_LIT:10> ) <EOL> locations = self . offer . get_plan_locations ( ) <EOL> self . assertEqual ( len ( locations ) , <NUM_LIT:3> ) <EOL> self . assertIn ( location1 , locations ) <EOL> self . assertIn ( location2 , locations ) <EOL> self . assertIn ( location3 , locations ) <EOL> def test_get_absolute_url_gets_slugified_url ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . offer . get_absolute_url ( ) , <EOL> reverse ( '<STR_LIT>' , args = [ self . offer . pk , slugify ( self . offer . name ) ] ) <EOL> ) <EOL> def test_comment_count_gets_correct_comment_count ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Comment , _quantity = <NUM_LIT:5> , offer = self . offer , status = Comment . PUBLISHED ) <EOL> mommy . make ( Comment , _quantity = <NUM_LIT:5> , offer = self . offer , status = Comment . UNPUBLISHED ) <EOL> mommy . make ( Comment , _quantity = <NUM_LIT:5> , offer = self . offer , status = Comment . DELETED ) <EOL> self . assertEqual ( self . offer . comment_count ( ) , <NUM_LIT:5> ) <EOL> def test_active_plan_count_returns_correct_values_with_active_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Plan , offer = self . offer , is_active = True , _quantity = <NUM_LIT:5> ) <EOL> mommy . make ( Plan , offer = self . offer , is_active = False , _quantity = <NUM_LIT:5> ) <EOL> self . assertEqual ( self . offer . active_plan_count ( ) , <NUM_LIT:5> ) <EOL> def test_active_plan_count_with_inactive_offer_returns_zero ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Plan , offer = self . offer , is_active = True , _quantity = <NUM_LIT:5> ) <EOL> mommy . make ( Plan , offer = self . offer , is_active = False , _quantity = <NUM_LIT:5> ) <EOL> self . offer . is_active = False <EOL> self . offer . save ( ) <EOL> self . assertEqual ( self . offer . active_plan_count ( ) , <NUM_LIT:0> ) <EOL> class ProviderMethodTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . provider = mommy . make ( Provider ) <EOL> def test_unicode_string ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . provider . name , self . provider . __unicode__ ( ) ) <EOL> def test_offer_count_with_published_active ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . PUBLISHED , is_active = True ) <EOL> self . assertEqual ( self . provider . offer_count ( ) , <NUM_LIT:20> ) <EOL> def test_offer_count_with_unpublished_active ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . UNPUBLISHED , is_active = True ) <EOL> self . assertEqual ( self . provider . offer_count ( ) , <NUM_LIT:0> ) <EOL> def test_offer_count_with_published_inactive ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . PUBLISHED , is_active = False ) <EOL> self . assertEqual ( self . provider . offer_count ( ) , <NUM_LIT:20> ) <EOL> def test_offer_count_with_unpublished_inactive ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . UNPUBLISHED , is_active = False ) <EOL> self . assertEqual ( self . provider . offer_count ( ) , <NUM_LIT:0> ) <EOL> def test_active_offer_count_with_published_active ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . PUBLISHED , is_active = True ) <EOL> self . assertEqual ( self . provider . active_offer_count ( ) , <NUM_LIT:20> ) <EOL> def test_active_offer_count_with_unpublished_active ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . UNPUBLISHED , is_active = True ) <EOL> self . assertEqual ( self . provider . active_offer_count ( ) , <NUM_LIT:0> ) <EOL> def test_active_offer_count_with_published_inactive ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . PUBLISHED , is_active = False ) <EOL> self . assertEqual ( self . provider . active_offer_count ( ) , <NUM_LIT:0> ) <EOL> def test_active_offer_count_with_unpublished_inactive ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Offer , _quantity = <NUM_LIT:20> , provider = self . provider , status = Offer . UNPUBLISHED , is_active = False ) <EOL> self . assertEqual ( self . provider . active_offer_count ( ) , <NUM_LIT:0> ) <EOL> def test_plan_count_with_active_offer_active_plan_published_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( <EOL> Plan , <EOL> _quantity = <NUM_LIT:20> , <EOL> offer__provider = self . provider , <EOL> offer__is_active = True , <EOL> is_active = True , <EOL> offer__status = Offer . PUBLISHED , <EOL> ) <EOL> self . assertEqual ( self . provider . plan_count ( ) , <NUM_LIT:20> ) <EOL> def test_plan_count_with_inactive_offer_active_plan_published_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( <EOL> Plan , <EOL> _quantity = <NUM_LIT:20> , <EOL> offer__provider = self . provider , <EOL> offer__is_active = False , <EOL> is_active = True , <EOL> offer__status = Offer . PUBLISHED , <EOL> ) <EOL> self . assertEqual ( self . provider . plan_count ( ) , <NUM_LIT:0> ) <EOL> def test_plan_count_with_active_offer_inactive_plan_published_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( <EOL> Plan , <EOL> _quantity = <NUM_LIT:20> , <EOL> offer__provider = self . provider , <EOL> offer__is_active = True , <EOL> is_active = False , <EOL> offer__status = Offer . PUBLISHED , <EOL> ) <EOL> self . assertEqual ( self . provider . plan_count ( ) , <NUM_LIT:0> ) <EOL> def test_plan_count_with_active_offer_active_plan_unpublished_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( <EOL> Plan , <EOL> _quantity = <NUM_LIT:20> , <EOL> offer__provider = self . provider , <EOL> offer__is_active = True , <EOL> is_active = True , <EOL> offer__status = Offer . UNPUBLISHED , <EOL> ) <EOL> self . assertEqual ( self . provider . plan_count ( ) , <NUM_LIT:0> ) <EOL> def test_plan_count_with_inactive_offer_inactive_plan_unpublished_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( <EOL> Plan , <EOL> _quantity = <NUM_LIT:20> , <EOL> offer__provider = self . provider , <EOL> offer__is_active = False , <EOL> is_active = False , <EOL> offer__status = Offer . UNPUBLISHED , <EOL> ) <EOL> self . assertEqual ( self . provider . plan_count ( ) , <NUM_LIT:0> ) <EOL> def test_file_path_naming ( self ) : <EOL> """<STR_LIT>""" <EOL> from offers . models import get_file_path <EOL> filename = '<STR_LIT>' <EOL> extension = '<STR_LIT>' <EOL> resulting_filename = get_file_path ( None , filename ) <EOL> self . assertTrue ( resulting_filename . endswith ( extension ) ) <EOL> class PlanMethodTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . plans = mommy . make ( Plan , _quantity = <NUM_LIT:20> ) <EOL> def test_data_format_from_MB_to_GB ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> value = i * <NUM_LIT> <EOL> plan = mommy . make ( Plan ) <EOL> result = plan . data_format ( value , '<STR_LIT>' ) <EOL> self . assertEqual ( "<STR_LIT>" . format ( i ) , result ) <EOL> def test_data_format_from_GB_to_TB ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> value = i * <NUM_LIT> <EOL> plan = mommy . make ( Plan ) <EOL> result = plan . data_format ( value , '<STR_LIT>' ) <EOL> self . assertEqual ( "<STR_LIT>" . format ( i ) , result ) <EOL> def test_data_format_from_MB_to_MB ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> value = ( i * <NUM_LIT> ) + <NUM_LIT:1> <EOL> plan = mommy . make ( Plan ) <EOL> result = plan . data_format ( value , '<STR_LIT>' ) <EOL> self . assertEqual ( "<STR_LIT>" . format ( value ) , result ) <EOL> def test_data_format_from_GB_to_GB ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> value = ( i * <NUM_LIT> ) + <NUM_LIT:1> <EOL> plan = mommy . make ( Plan ) <EOL> result = plan . data_format ( value , '<STR_LIT>' ) <EOL> self . assertEqual ( "<STR_LIT>" . format ( value ) , result ) <EOL> def test_get_memory ( self ) : <EOL> """<STR_LIT>""" <EOL> for plan in self . plans : <EOL> self . assertEqual ( plan . get_memory ( ) , plan . data_format ( plan . memory , '<STR_LIT>' ) ) <EOL> def test_get_bandwidth ( self ) : <EOL> """<STR_LIT>""" <EOL> for plan in self . plans : <EOL> self . assertEqual ( plan . get_bandwidth ( ) , plan . data_format ( plan . bandwidth , '<STR_LIT>' ) ) <EOL> def test_get_hdd ( self ) : <EOL> """<STR_LIT>""" <EOL> for plan in self . plans : <EOL> self . assertEqual ( plan . get_hdd ( ) , plan . data_format ( plan . disk_space , '<STR_LIT>' ) ) <EOL> def test_get_cost_for_decimal_gives_two_places_with_integer ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Plan . get_cost_for_decimal ( Decimal ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> def test_get_cost_for_decimal_gives_two_places_with_single_decimal_float ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Plan . get_cost_for_decimal ( Decimal ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> def test_get_cost_for_decimal_gives_two_places_with_two_decimal_float ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Plan . get_cost_for_decimal ( Decimal ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> def test_get_cost_for_decimal_gives_three_places_with_triple_decimal_float ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Plan . get_cost_for_decimal ( Decimal ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> def test_get_cost_for_decimal_gives_three_places_with_quadruple_decimal_float_and_rounds ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Plan . get_cost_for_decimal ( Decimal ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> def test_get_cost_for_decimal_gives_two_places_with_empty_decimal ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Plan . get_cost_for_decimal ( Decimal ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> class LocationMethodTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . location = mommy . make ( Location ) <EOL> def test_location_name_with_unicode_name ( self ) : <EOL> """<STR_LIT>""" <EOL> location = mommy . make ( Location , country = '<STR_LIT>' ) <EOL> self . assertIn ( location . country . name . __unicode__ ( ) , location . __unicode__ ( ) ) <EOL> def test_location_name_with_non_unicode_name ( self ) : <EOL> """<STR_LIT>""" <EOL> location = mommy . make ( Location , country = '<STR_LIT>' ) <EOL> self . assertIn ( location . country . name . __unicode__ ( ) , location . __unicode__ ( ) ) <EOL> class CommentMethodTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . comment = mommy . make ( Comment ) <EOL> def test_like_count_correct_with_correct_offer ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Like , _quantity = <NUM_LIT:5> , comment = self . comment ) <EOL> mommy . make ( Like , _quantity = <NUM_LIT:5> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:5> ) <EOL> def test_like_count_returns_zero_on_no_likes ( self ) : <EOL> """<STR_LIT>""" <EOL> mommy . make ( Like , _quantity = <NUM_LIT:5> ) <EOL> self . assertEqual ( self . comment . like_count ( ) , <NUM_LIT:0> ) <EOL> def test_does_like_returns_true_if_user_likes_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . create_user ( '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> like = mommy . make ( Like , user = user , comment = self . comment ) <EOL> self . assertTrue ( self . comment . does_like ( user ) ) <EOL> def test_does_like_returns_false_if_user_not_like_comment ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . create_user ( '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertFalse ( self . comment . does_like ( user ) ) </s>
