<s> from mock import Mock <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import AnonymousUser <EOL> from prices import Price <EOL> import pytest <EOL> from . core import Checkout , STORAGE_SESSION_KEY <EOL> from . . shipping . models import ShippingMethodCountry <EOL> from . . userprofile . models import Address <EOL> from . import views <EOL> def test_checkout_version ( ) : <EOL> checkout = Checkout ( Mock ( ) , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> storage = checkout . for_storage ( ) <EOL> assert storage [ '<STR_LIT:version>' ] == Checkout . VERSION <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( { '<STR_LIT:version>' : Checkout . VERSION , '<STR_LIT>' : <NUM_LIT:1> } , { '<STR_LIT:version>' : Checkout . VERSION , '<STR_LIT>' : <NUM_LIT:1> } ) , <EOL> ( { '<STR_LIT:version>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> } , { '<STR_LIT:version>' : Checkout . VERSION } ) , <EOL> ( { '<STR_LIT>' : <NUM_LIT:1> } , { '<STR_LIT:version>' : Checkout . VERSION } ) , <EOL> ( { } , { '<STR_LIT:version>' : Checkout . VERSION } ) , <EOL> ( None , { '<STR_LIT:version>' : Checkout . VERSION } ) , <EOL> ] ) <EOL> def test_checkout_version_with_from_storage ( storage_data , expected_storage ) : <EOL> checkout = Checkout . from_storage ( <EOL> storage_data , Mock ( ) , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> storage = checkout . for_storage ( ) <EOL> assert storage == expected_storage <EOL> def test_checkout_clear_storage ( ) : <EOL> checkout = Checkout ( Mock ( ) , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> checkout . storage [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> checkout . clear_storage ( ) <EOL> assert checkout . storage is None <EOL> assert checkout . modified is True <EOL> def test_checkout_is_shipping_required ( ) : <EOL> cart = Mock ( is_shipping_required = Mock ( return_value = True ) ) <EOL> checkout = Checkout ( cart , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> assert checkout . is_shipping_required is True <EOL> def test_checkout_deliveries ( ) : <EOL> partition = Mock ( <EOL> get_total = Mock ( return_value = Price ( <NUM_LIT:10> , currency = settings . DEFAULT_CURRENCY ) ) ) <EOL> cart = Mock ( partition = Mock ( return_value = [ partition ] ) ) <EOL> checkout = Checkout ( cart , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> deliveries = list ( checkout . deliveries ) <EOL> assert deliveries == [ ( partition , Price ( <EOL> <NUM_LIT:0> , currency = settings . DEFAULT_CURRENCY ) , partition . get_total ( ) ) ] <EOL> def test_checkout_deliveries_with_shipping_method ( monkeypatch ) : <EOL> partition = Mock ( <EOL> get_total = Mock ( return_value = Price ( <NUM_LIT:10> , currency = settings . DEFAULT_CURRENCY ) ) ) <EOL> cart = Mock ( partition = Mock ( return_value = [ partition ] ) ) <EOL> cart . partition . return_value = [ partition ] <EOL> shipping_method_mock = Mock ( <EOL> get_total = Mock ( return_value = Price ( <NUM_LIT:5> , currency = settings . DEFAULT_CURRENCY ) ) ) <EOL> monkeypatch . setattr ( Checkout , '<STR_LIT>' , shipping_method_mock ) <EOL> checkout = Checkout ( cart , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> deliveries = list ( checkout . deliveries ) <EOL> total = partition . get_total ( ) + shipping_method_mock . get_total ( ) <EOL> assert deliveries == [ <EOL> ( partition , shipping_method_mock . get_total ( ) , total ) ] <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( Mock ( default_shipping_address = '<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( AnonymousUser ( ) , None ) , <EOL> ] ) <EOL> def test_checkout_shipping_address_with_anonymous_user ( user , shipping ) : <EOL> checkout = Checkout ( Mock ( ) , user , '<STR_LIT>' ) <EOL> assert checkout . shipping_address == shipping <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( Mock ( get = Mock ( return_value = '<STR_LIT>' ) ) , '<STR_LIT>' ) , <EOL> ( Mock ( get = Mock ( side_effect = Address . DoesNotExist ) ) , None ) , <EOL> ] ) <EOL> def test_checkout_shipping_address_with_storage ( address_objects , shipping , monkeypatch ) : <EOL> monkeypatch . setattr ( '<STR_LIT>' , address_objects ) <EOL> checkout = Checkout ( Mock ( ) , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> checkout . storage [ '<STR_LIT>' ] = { '<STR_LIT:id>' : <NUM_LIT:1> } <EOL> assert checkout . shipping_address == shipping <EOL> def test_checkout_shipping_address_setter ( ) : <EOL> address = Address ( first_name = '<STR_LIT>' , last_name = '<STR_LIT>' ) <EOL> checkout = Checkout ( Mock ( ) , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> checkout . shipping_address = address <EOL> assert checkout . storage [ '<STR_LIT>' ] == { <EOL> '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:id>' : None , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' } <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( Mock ( country = Mock ( code = '<STR_LIT>' ) ) , <EOL> Mock ( country_code = '<STR_LIT>' , __eq__ = lambda n , o : n . country_code == o . country_code ) , <EOL> Mock ( country_code = '<STR_LIT>' ) ) , <EOL> ( Mock ( country = Mock ( code = '<STR_LIT>' ) ) , Mock ( country_code = '<STR_LIT>' ) , None ) , <EOL> ( None , Mock ( country_code = '<STR_LIT>' ) , None ) , <EOL> ] ) <EOL> def test_checkout_shipping_method ( shipping_address , shipping_method , value , monkeypatch ) : <EOL> queryset = Mock ( get = Mock ( return_value = shipping_method ) ) <EOL> monkeypatch . setattr ( Checkout , '<STR_LIT>' , shipping_address ) <EOL> monkeypatch . setattr ( '<STR_LIT>' , queryset ) <EOL> checkout = Checkout ( Mock ( ) , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> checkout . storage [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> assert checkout . shipping_method == value <EOL> def test_checkout_shipping_does_not_exists ( monkeypatch ) : <EOL> queryset = Mock ( get = Mock ( side_effect = ShippingMethodCountry . DoesNotExist ) ) <EOL> monkeypatch . setattr ( '<STR_LIT>' , queryset ) <EOL> checkout = Checkout ( Mock ( ) , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> checkout . storage [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> assert checkout . shipping_method is None <EOL> def test_checkout_shipping_method_setter ( ) : <EOL> shipping_method = Mock ( id = <NUM_LIT:1> ) <EOL> checkout = Checkout ( Mock ( ) , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> assert checkout . modified is False <EOL> checkout . shipping_method = shipping_method <EOL> assert checkout . modified is True <EOL> assert checkout . storage [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( AnonymousUser ( ) , None ) , <EOL> ( Mock ( default_billing_address = '<STR_LIT>' , <EOL> addresses = Mock ( is_authenticated = Mock ( return_value = True ) ) ) , '<STR_LIT>' ) , <EOL> ] ) <EOL> def test_checkout_billing_address ( user , address ) : <EOL> checkout = Checkout ( Mock ( ) , user , '<STR_LIT>' ) <EOL> assert checkout . billing_address == address <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( Mock ( __len__ = Mock ( return_value = <NUM_LIT:0> ) ) , <NUM_LIT> , '<STR_LIT>' ) , <EOL> ( Mock ( __len__ = Mock ( return_value = <NUM_LIT:1> ) , <EOL> is_shipping_required = Mock ( return_value = True ) ) , <EOL> <NUM_LIT> , '<STR_LIT>' ) , <EOL> ( Mock ( __len__ = Mock ( return_value = <NUM_LIT:1> ) , <EOL> is_shipping_required = Mock ( return_value = False ) ) , <EOL> <NUM_LIT> , '<STR_LIT>' ) , <EOL> ( Mock ( __len__ = Mock ( return_value = <NUM_LIT:0> ) , <EOL> is_shipping_required = Mock ( return_value = False ) ) , <NUM_LIT> , '<STR_LIT>' ) , <EOL> ] ) <EOL> def test_index_view ( cart , status_code , url , rf ) : <EOL> checkout = Checkout ( cart , AnonymousUser ( ) , '<STR_LIT>' ) <EOL> request = rf . get ( '<STR_LIT>' ) <EOL> request . user = checkout . user <EOL> request . cart = checkout . cart <EOL> request . session = { STORAGE_SESSION_KEY : checkout . for_storage ( ) } <EOL> request . discounts = [ ] <EOL> response = views . index_view ( request , checkout ) <EOL> assert response . status_code == status_code <EOL> assert response . url == url </s>
