<s> from decimal import Decimal as D <EOL> from django . utils . six . moves import http_client <EOL> import datetime <EOL> from django . conf import settings <EOL> from django . test import TestCase , Client <EOL> from django . utils . translation import ugettext <EOL> from django . core . urlresolvers import reverse <EOL> from oscar . test . factories import create_product <EOL> from oscar . core . compat import get_user_model <EOL> from oscar . apps . basket . models import Basket <EOL> from oscar . apps . basket import reports <EOL> from oscar . test . basket import add_product <EOL> from oscar . test import factories <EOL> from oscar . apps . partner import strategy <EOL> User = get_user_model ( ) <EOL> class TestBasketMerging ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . product = create_product ( num_in_stock = <NUM_LIT:10> ) <EOL> self . user_basket = Basket ( ) <EOL> self . user_basket . strategy = strategy . Default ( ) <EOL> add_product ( self . user_basket , product = self . product ) <EOL> self . cookie_basket = Basket ( ) <EOL> self . cookie_basket . strategy = strategy . Default ( ) <EOL> add_product ( self . cookie_basket , quantity = <NUM_LIT:2> , product = self . product ) <EOL> self . user_basket . merge ( self . cookie_basket , add_quantities = False ) <EOL> def test_cookie_basket_has_status_set ( self ) : <EOL> self . assertEqual ( Basket . MERGED , self . cookie_basket . status ) <EOL> def test_lines_are_moved_across ( self ) : <EOL> self . assertEqual ( <NUM_LIT:1> , self . user_basket . lines . all ( ) . count ( ) ) <EOL> def test_merge_line_takes_max_quantity ( self ) : <EOL> line = self . user_basket . lines . get ( product = self . product ) <EOL> self . assertEqual ( <NUM_LIT:2> , line . quantity ) <EOL> class AnonAddToBasketViewTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . product = create_product ( <EOL> price = D ( '<STR_LIT>' ) , num_in_stock = <NUM_LIT:10> ) <EOL> url = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : self . product . pk } ) <EOL> post_params = { '<STR_LIT>' : self . product . id , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> } <EOL> self . client = Client ( ) <EOL> self . response = self . client . post ( url , post_params ) <EOL> def test_cookie_is_created ( self ) : <EOL> self . assertTrue ( '<STR_LIT>' in self . response . cookies ) <EOL> def test_price_is_recorded ( self ) : <EOL> basket_id = self . response . cookies [ '<STR_LIT>' ] . value . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> basket = Basket . objects . get ( id = basket_id ) <EOL> line = basket . lines . get ( product = self . product ) <EOL> stockrecord = self . product . stockrecords . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( stockrecord . price_excl_tax , line . price_excl_tax ) <EOL> class BasketSummaryViewTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> url = reverse ( '<STR_LIT>' ) <EOL> self . response = self . client . get ( url ) <EOL> def test_shipping_method_in_context ( self ) : <EOL> self . assertTrue ( '<STR_LIT>' in self . response . context ) <EOL> def test_order_total_in_context ( self ) : <EOL> self . assertTrue ( '<STR_LIT>' in self . response . context ) <EOL> def test_view_does_not_error ( self ) : <EOL> self . assertEqual ( http_client . OK , self . response . status_code ) <EOL> def test_basket_in_context ( self ) : <EOL> self . assertTrue ( '<STR_LIT>' in self . response . context ) <EOL> def test_basket_is_empty ( self ) : <EOL> basket = self . response . context [ '<STR_LIT>' ] <EOL> self . assertEqual ( <NUM_LIT:0> , basket . num_lines ) <EOL> class BasketThresholdTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _old_threshold = settings . OSCAR_MAX_BASKET_QUANTITY_THRESHOLD <EOL> settings . OSCAR_MAX_BASKET_QUANTITY_THRESHOLD = <NUM_LIT:3> <EOL> def tearDown ( self ) : <EOL> settings . OSCAR_MAX_BASKET_QUANTITY_THRESHOLD = self . _old_threshold <EOL> def test_adding_more_than_threshold_raises ( self ) : <EOL> dummy_product = create_product ( price = D ( '<STR_LIT>' ) , num_in_stock = <NUM_LIT:10> ) <EOL> url = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : dummy_product . pk } ) <EOL> post_params = { '<STR_LIT>' : dummy_product . id , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:2> } <EOL> response = self . client . post ( url , post_params ) <EOL> self . assertTrue ( '<STR_LIT>' in response . cookies ) <EOL> post_params = { '<STR_LIT>' : dummy_product . id , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:2> } <EOL> response = self . client . post ( url , post_params ) <EOL> expected = ugettext ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) % ( { '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> self . assertTrue ( expected in response . cookies [ '<STR_LIT>' ] . value ) <EOL> class BasketReportTests ( TestCase ) : <EOL> def test_open_report_doesnt_error ( self ) : <EOL> data = { <EOL> '<STR_LIT>' : datetime . date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> ) , <EOL> '<STR_LIT>' : datetime . date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> generator = reports . OpenBasketReportGenerator ( ** data ) <EOL> generator . generate ( ) <EOL> def test_submitted_report_doesnt_error ( self ) : <EOL> data = { <EOL> '<STR_LIT>' : datetime . date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> ) , <EOL> '<STR_LIT>' : datetime . date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> generator = reports . SubmittedBasketReportGenerator ( ** data ) <EOL> generator . generate ( ) <EOL> class SavedBasketTests ( TestCase ) : <EOL> def test_moving_from_saved_basket ( self ) : <EOL> user = User . objects . create_user ( username = '<STR_LIT:test>' , password = '<STR_LIT>' , <EOL> email = '<STR_LIT>' ) <EOL> client = Client ( ) <EOL> client . login ( email = user . email , password = '<STR_LIT>' ) <EOL> product = create_product ( price = D ( '<STR_LIT>' ) , num_in_stock = <NUM_LIT:2> ) <EOL> basket = factories . create_basket ( empty = True ) <EOL> basket . owner = user <EOL> basket . save ( ) <EOL> add_product ( basket , product = product ) <EOL> saved_basket , created = Basket . saved . get_or_create ( owner = user ) <EOL> saved_basket . strategy = basket . strategy <EOL> add_product ( saved_basket , product = product ) <EOL> response = client . get ( reverse ( '<STR_LIT>' ) ) <EOL> saved_formset = response . context [ '<STR_LIT>' ] <EOL> saved_form = saved_formset . forms [ <NUM_LIT:0> ] <EOL> data = { <EOL> saved_formset . add_prefix ( '<STR_LIT>' ) : <NUM_LIT:1> , <EOL> saved_formset . add_prefix ( '<STR_LIT>' ) : <NUM_LIT:1> , <EOL> saved_formset . add_prefix ( '<STR_LIT>' ) : <NUM_LIT:1> , <EOL> saved_form . add_prefix ( '<STR_LIT:id>' ) : saved_form . initial [ '<STR_LIT:id>' ] , <EOL> saved_form . add_prefix ( '<STR_LIT>' ) : True , <EOL> } <EOL> response = client . post ( reverse ( '<STR_LIT>' ) , data = data ) <EOL> self . assertEqual ( Basket . open . get ( id = basket . id ) . lines . get ( <EOL> product = product ) . quantity , <NUM_LIT:2> ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_moving_from_saved_basket_more_than_stocklevel_raises ( self ) : <EOL> user = User . objects . create_user ( username = '<STR_LIT:test>' , password = '<STR_LIT>' , <EOL> email = '<STR_LIT>' ) <EOL> client = Client ( ) <EOL> client . login ( email = user . email , password = '<STR_LIT>' ) <EOL> product = create_product ( price = D ( '<STR_LIT>' ) , num_in_stock = <NUM_LIT:1> ) <EOL> basket , created = Basket . open . get_or_create ( owner = user ) <EOL> add_product ( basket , product = product ) <EOL> saved_basket , created = Basket . saved . get_or_create ( owner = user ) <EOL> add_product ( saved_basket , product = product ) <EOL> response = client . get ( reverse ( '<STR_LIT>' ) ) <EOL> saved_formset = response . context [ '<STR_LIT>' ] <EOL> saved_form = saved_formset . forms [ <NUM_LIT:0> ] <EOL> data = { <EOL> saved_formset . add_prefix ( '<STR_LIT>' ) : <NUM_LIT:1> , <EOL> saved_formset . add_prefix ( '<STR_LIT>' ) : <NUM_LIT:1> , <EOL> saved_formset . add_prefix ( '<STR_LIT>' ) : <NUM_LIT:1> , <EOL> saved_form . add_prefix ( '<STR_LIT:id>' ) : saved_form . initial [ '<STR_LIT:id>' ] , <EOL> saved_form . add_prefix ( '<STR_LIT>' ) : True , <EOL> } <EOL> response = client . post ( reverse ( '<STR_LIT>' ) , data = data ) <EOL> self . assertEqual ( Basket . open . get ( id = basket . id ) . lines . get ( product = product ) . quantity , <NUM_LIT:1> ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) </s>
