<s> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils . six . moves import http_client <EOL> from oscar . core . loading import get_model <EOL> from oscar . apps . order . models import ( <EOL> Order , OrderNote , PaymentEvent , PaymentEventType ) <EOL> from oscar . test . factories import PartnerFactory , ShippingAddressFactory <EOL> from oscar . test . factories import create_order , create_basket <EOL> from oscar . test . testcases import WebTestCase <EOL> from oscar . test . factories import SourceTypeFactory <EOL> Basket = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Partner = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ShippingAddress = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TestOrderListDashboard ( WebTestCase ) : <EOL> is_staff = True <EOL> def test_redirects_to_detail_page ( self ) : <EOL> order = create_order ( ) <EOL> page = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = order . number <EOL> response = form . submit ( ) <EOL> self . assertEqual ( http_client . FOUND , response . status_code ) <EOL> def test_downloads_to_csv_without_error ( self ) : <EOL> address = ShippingAddressFactory ( ) <EOL> create_order ( shipping_address = address ) <EOL> page = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] . checked = True <EOL> form . submit ( '<STR_LIT>' ) <EOL> def test_allows_order_number_search ( self ) : <EOL> page = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = '<STR_LIT:+>' <EOL> form . submit ( ) <EOL> class PermissionBasedDashboardOrderTestsBase ( WebTestCase ) : <EOL> permissions = [ '<STR_LIT>' , ] <EOL> username = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( PermissionBasedDashboardOrderTestsBase , self ) . setUp ( ) <EOL> self . address = ShippingAddressFactory ( ) <EOL> self . basket_in = create_basket ( ) <EOL> self . basket_out = create_basket ( ) <EOL> self . partner_in = PartnerFactory ( users = [ self . user ] ) <EOL> stockrecord = self . basket_in . lines . all ( ) [ <NUM_LIT:0> ] . stockrecord <EOL> stockrecord . partner = self . partner_in <EOL> stockrecord . save ( ) <EOL> self . order_in = create_order ( basket = self . basket_in , <EOL> shipping_address = self . address ) <EOL> self . order_out = create_order ( basket = self . basket_out , <EOL> shipping_address = self . address ) <EOL> class PermissionBasedDashboardOrderTestsNoStaff ( PermissionBasedDashboardOrderTestsBase ) : <EOL> is_staff = False <EOL> def test_non_staff_can_only_list_her_orders ( self ) : <EOL> response = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( set ( response . context [ '<STR_LIT>' ] ) , <EOL> set ( [ self . order_in ] ) ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . order_in . number } ) <EOL> self . assertIsOk ( self . get ( url ) ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . order_out . number } ) <EOL> self . assertNoAccess ( self . get ( url , status = "<STR_LIT:*>" ) ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . order_in . number , <EOL> '<STR_LIT>' : self . order_in . lines . all ( ) [ <NUM_LIT:0> ] . pk } ) <EOL> self . assertIsOk ( self . get ( url ) ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . order_out . number , <EOL> '<STR_LIT>' : self . order_out . lines . all ( ) [ <NUM_LIT:0> ] . pk } ) <EOL> self . assertNoAccess ( self . get ( url , status = "<STR_LIT:*>" ) ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . order_in . number } ) <EOL> self . assertIsOk ( self . get ( url ) ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . order_out . number } ) <EOL> self . assertNoAccess ( self . get ( url , status = "<STR_LIT:*>" ) ) <EOL> class PermissionBasedDashboardOrderTestsStaff ( PermissionBasedDashboardOrderTestsBase ) : <EOL> is_staff = True <EOL> def test_staff_user_can_list_all_orders ( self ) : <EOL> orders = [ self . order_in , self . order_out ] <EOL> response = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertIsOk ( response ) <EOL> self . assertEqual ( set ( response . context [ '<STR_LIT>' ] ) , <EOL> set ( orders ) ) <EOL> for order in orders : <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : order . number } ) <EOL> self . assertIsOk ( self . get ( url ) ) <EOL> class TestOrderListSearch ( WebTestCase ) : <EOL> is_staff = True <EOL> TEST_CASES = [ <EOL> ( { } , [ ] ) , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { '<STR_LIT:status>' : '<STR_LIT:A>' } , <EOL> [ '<STR_LIT>' ] <EOL> ) , <EOL> ( <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT:A>' <EOL> } , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> ) , <EOL> ] <EOL> def test_search_filter_descriptions ( self ) : <EOL> SourceTypeFactory ( name = '<STR_LIT>' , code = '<STR_LIT>' ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> for params , expected_filters in self . TEST_CASES : <EOL> params . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> response = self . get ( url , params = params ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> applied_filters = [ <EOL> el . text . strip ( ) for el in <EOL> response . html . select ( '<STR_LIT>' ) <EOL> ] <EOL> self . assertEqual ( applied_filters , expected_filters ) <EOL> class TestOrderDetailPage ( WebTestCase ) : <EOL> is_staff = True <EOL> def setUp ( self ) : <EOL> super ( TestOrderDetailPage , self ) . setUp ( ) <EOL> self . order = create_order ( ) <EOL> self . event_type = PaymentEventType . objects . create ( name = '<STR_LIT:foo>' ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . order . number } ) <EOL> self . page = self . get ( url ) <EOL> def test_contains_order ( self ) : <EOL> self . assertEqual ( self . page . context [ '<STR_LIT>' ] , self . order ) <EOL> def test_allows_notes_to_be_added ( self ) : <EOL> form = self . page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT:message>' ] = "<STR_LIT>" <EOL> response = form . submit ( ) <EOL> self . assertIsRedirect ( response ) <EOL> notes = self . order . notes . all ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( notes ) ) <EOL> def test_allows_line_status_to_be_changed ( self ) : <EOL> line = self . order . lines . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( line . status , settings . OSCAR_INITIAL_LINE_STATUS ) <EOL> form = self . page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> form [ '<STR_LIT>' ] = new_status = '<STR_LIT:b>' <EOL> form [ '<STR_LIT>' ] = [ line . pk ] <EOL> form . submit ( ) <EOL> self . assertEqual ( self . order . lines . all ( ) [ <NUM_LIT:0> ] . status , new_status ) <EOL> def test_allows_order_status_to_be_changed ( self ) : <EOL> form = self . page . forms [ '<STR_LIT>' ] <EOL> self . assertEqual ( <EOL> self . order . status , settings . OSCAR_INITIAL_ORDER_STATUS ) <EOL> form = self . page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = new_status = '<STR_LIT:B>' <EOL> form . submit ( ) <EOL> self . assertEqual ( Order . objects . get ( pk = self . order . pk ) . status , new_status ) <EOL> def test_allows_creating_payment_event ( self ) : <EOL> line = self . order . lines . all ( ) [ <NUM_LIT:0> ] <EOL> form = self . page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> form [ '<STR_LIT>' ] = [ line . pk ] <EOL> form [ '<STR_LIT>' ] = self . event_type . code <EOL> form . submit ( ) <EOL> self . assertTrue ( PaymentEvent . objects . exists ( ) ) <EOL> class TestChangingOrderStatus ( WebTestCase ) : <EOL> is_staff = True <EOL> def setUp ( self ) : <EOL> super ( TestChangingOrderStatus , self ) . setUp ( ) <EOL> Order . pipeline = { '<STR_LIT:A>' : ( '<STR_LIT:B>' , '<STR_LIT:C>' ) } <EOL> self . order = create_order ( status = '<STR_LIT:A>' ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . order . number } ) <EOL> page = self . get ( url ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = '<STR_LIT:B>' <EOL> self . response = form . submit ( ) <EOL> def reload_order ( self ) : <EOL> return Order . objects . get ( number = self . order . number ) <EOL> def test_works ( self ) : <EOL> self . assertIsRedirect ( self . response ) <EOL> self . assertEqual ( '<STR_LIT:B>' , self . reload_order ( ) . status ) <EOL> def test_creates_system_note ( self ) : <EOL> notes = self . order . notes . all ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( notes ) ) <EOL> self . assertEqual ( OrderNote . SYSTEM , notes [ <NUM_LIT:0> ] . note_type ) <EOL> class TestChangingOrderStatusFromFormOnOrderListView ( WebTestCase ) : <EOL> is_staff = True <EOL> def setUp ( self ) : <EOL> super ( TestChangingOrderStatusFromFormOnOrderListView , self ) . setUp ( ) <EOL> Order . pipeline = { '<STR_LIT:A>' : ( '<STR_LIT:B>' , '<STR_LIT:C>' ) , '<STR_LIT:B>' : ( '<STR_LIT:A>' , '<STR_LIT:C>' ) , '<STR_LIT:C>' : ( '<STR_LIT:A>' , '<STR_LIT:B>' ) } <EOL> self . order = create_order ( status = '<STR_LIT:A>' ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> page = self . get ( url ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = '<STR_LIT:B>' <EOL> form [ '<STR_LIT>' ] = self . order . pk <EOL> self . response = form . submit ( name = '<STR_LIT:action>' , value = '<STR_LIT>' ) <EOL> def reload_order ( self ) : <EOL> return Order . objects . get ( number = self . order . number ) <EOL> def test_works ( self ) : <EOL> self . assertIsRedirect ( self . response ) <EOL> self . assertEqual ( '<STR_LIT:B>' , self . reload_order ( ) . status ) <EOL> notes = self . order . notes . all ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( notes ) ) <EOL> self . assertEqual ( OrderNote . SYSTEM , notes [ <NUM_LIT:0> ] . note_type ) <EOL> class LineDetailTests ( WebTestCase ) : <EOL> is_staff = True <EOL> def setUp ( self ) : <EOL> self . order = create_order ( ) <EOL> self . line = self . order . lines . all ( ) [ <NUM_LIT:0> ] <EOL> self . url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . order . number , <EOL> '<STR_LIT>' : self . line . id } ) <EOL> super ( LineDetailTests , self ) . setUp ( ) <EOL> def test_line_detail_page_exists ( self ) : <EOL> response = self . get ( self . url ) <EOL> self . assertIsOk ( response ) <EOL> def test_line_in_context ( self ) : <EOL> response = self . get ( self . url ) <EOL> self . assertInContext ( response , '<STR_LIT>' ) </s>
