<s> from __future__ import unicode_literals <EOL> import datetime <EOL> from django . utils . timezone import now <EOL> from common . literals import TIME_DELTA_UNIT_DAYS <EOL> from documents . tests . test_views import GenericDocumentViewTestCase <EOL> from sources . links import link_upload_version <EOL> from user_management . tests import ( <EOL> TEST_USER_PASSWORD , TEST_USER_USERNAME , TEST_ADMIN_PASSWORD , <EOL> TEST_ADMIN_USERNAME , <EOL> ) <EOL> from . . models import DocumentCheckout <EOL> from . . permissions import ( <EOL> permission_document_checkin , permission_document_checkin_override , <EOL> permission_document_checkout <EOL> ) <EOL> class DocumentCheckoutViewTestCase ( GenericDocumentViewTestCase ) : <EOL> def test_checkin_document_view_no_permission ( self ) : <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> expiration_datetime = now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> DocumentCheckout . objects . checkout_document ( <EOL> document = self . document , expiration_datetime = expiration_datetime , <EOL> user = self . user , block_new_version = True <EOL> ) <EOL> self . assertTrue ( self . document . is_checked_out ( ) ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , follow = True <EOL> ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> self . assertTrue ( self . document . is_checked_out ( ) ) <EOL> def test_checkin_document_view_with_permission ( self ) : <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> expiration_datetime = now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> DocumentCheckout . objects . checkout_document ( <EOL> document = self . document , expiration_datetime = expiration_datetime , <EOL> user = self . user , block_new_version = True <EOL> ) <EOL> self . assertTrue ( self . document . is_checked_out ( ) ) <EOL> self . role . permissions . add ( <EOL> permission_document_checkin . stored_permission <EOL> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , follow = True <EOL> ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertFalse ( self . document . is_checked_out ( ) ) <EOL> self . assertFalse ( <EOL> DocumentCheckout . objects . is_document_checked_out ( <EOL> document = self . document <EOL> ) <EOL> ) <EOL> def test_checkout_document_view_no_permission ( self ) : <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , data = { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : TIME_DELTA_UNIT_DAYS , <EOL> '<STR_LIT>' : True <EOL> } , follow = True <EOL> ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> self . assertFalse ( self . document . is_checked_out ( ) ) <EOL> def test_checkout_document_view_with_permission ( self ) : <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_document_checkout . stored_permission <EOL> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , data = { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : TIME_DELTA_UNIT_DAYS , <EOL> '<STR_LIT>' : True <EOL> } , follow = True <EOL> ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( self . document . is_checked_out ( ) ) <EOL> def test_document_new_version_after_checkout ( self ) : <EOL> """<STR_LIT>""" <EOL> self . login ( <EOL> username = TEST_ADMIN_USERNAME , password = TEST_ADMIN_PASSWORD <EOL> ) <EOL> expiration_datetime = now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> DocumentCheckout . objects . checkout_document ( <EOL> document = self . document , expiration_datetime = expiration_datetime , <EOL> user = self . admin_user , block_new_version = True <EOL> ) <EOL> self . assertTrue ( self . document . is_checked_out ( ) ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , <EOL> follow = True <EOL> ) <EOL> self . assertContains ( <EOL> response , text = '<STR_LIT>' , <EOL> status_code = <NUM_LIT:200> <EOL> ) <EOL> response = self . get ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , <EOL> follow = True <EOL> ) <EOL> response . context . current_app = None <EOL> resolved_link = link_upload_version . resolve ( context = response . context ) <EOL> self . assertEqual ( resolved_link , None ) <EOL> def test_forcefull_check_in_document_view_no_permission ( self ) : <EOL> expiration_datetime = now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> DocumentCheckout . objects . checkout_document ( <EOL> document = self . document , expiration_datetime = expiration_datetime , <EOL> user = self . admin_user , block_new_version = True <EOL> ) <EOL> self . assertTrue ( self . document . is_checked_out ( ) ) <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_document_checkin . stored_permission <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_document_checkout . stored_permission <EOL> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , follow = True <EOL> ) <EOL> self . assertContains ( <EOL> response , text = '<STR_LIT>' , status_code = <NUM_LIT> <EOL> ) <EOL> self . assertTrue ( self . document . is_checked_out ( ) ) <EOL> def test_forcefull_check_in_document_view_with_permission ( self ) : <EOL> expiration_datetime = now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> DocumentCheckout . objects . checkout_document ( <EOL> document = self . document , expiration_datetime = expiration_datetime , <EOL> user = self . admin_user , block_new_version = True <EOL> ) <EOL> self . assertTrue ( self . document . is_checked_out ( ) ) <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_document_checkin . stored_permission <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_document_checkin . stored_permission <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_document_checkin_override . stored_permission <EOL> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , follow = True <EOL> ) <EOL> self . assertContains ( <EOL> response , text = '<STR_LIT>' , status_code = <NUM_LIT:200> <EOL> ) <EOL> self . assertFalse ( self . document . is_checked_out ( ) ) </s>
