<s> from __future__ import unicode_literals <EOL> from django . contrib . auth . models import User <EOL> from django . core . urlresolvers import reverse <EOL> from django . test . client import Client <EOL> from django . test import TestCase , override_settings <EOL> from documents . models import Document , DocumentType , NewVersionBlock <EOL> from documents . tests import ( <EOL> TEST_DOCUMENT_PATH , TEST_SMALL_DOCUMENT_PATH , TEST_DOCUMENT_DESCRIPTION , <EOL> TEST_DOCUMENT_TYPE <EOL> ) <EOL> from documents . tests . test_views import GenericDocumentViewTestCase <EOL> from user_management . tests import ( <EOL> TEST_ADMIN_EMAIL , TEST_ADMIN_PASSWORD , TEST_ADMIN_USERNAME , <EOL> ) <EOL> from . . links import link_upload_version <EOL> from . . literals import SOURCE_CHOICE_WEB_FORM <EOL> from . . models import WebFormSource <EOL> @ override_settings ( OCR_AUTO_OCR = False ) <EOL> class UploadDocumentTestCase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . document_type = DocumentType . objects . create ( <EOL> label = TEST_DOCUMENT_TYPE <EOL> ) <EOL> self . admin_user = User . objects . create_superuser ( <EOL> username = TEST_ADMIN_USERNAME , email = TEST_ADMIN_EMAIL , <EOL> password = TEST_ADMIN_PASSWORD <EOL> ) <EOL> self . client = Client ( ) <EOL> def tearDown ( self ) : <EOL> self . document_type . delete ( ) <EOL> def test_upload_a_document ( self ) : <EOL> logged_in = self . client . login ( <EOL> username = TEST_ADMIN_USERNAME , password = TEST_ADMIN_PASSWORD <EOL> ) <EOL> self . assertTrue ( logged_in ) <EOL> self . assertTrue ( self . admin_user . is_authenticated ( ) ) <EOL> self . client . post ( <EOL> reverse ( <EOL> '<STR_LIT>' , args = ( SOURCE_CHOICE_WEB_FORM , ) <EOL> ) , { '<STR_LIT:label>' : '<STR_LIT:test>' , '<STR_LIT>' : '<STR_LIT:n>' , '<STR_LIT>' : True } <EOL> ) <EOL> self . assertEqual ( WebFormSource . objects . count ( ) , <NUM_LIT:1> ) <EOL> with open ( TEST_DOCUMENT_PATH ) as file_descriptor : <EOL> self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : file_descriptor , <EOL> '<STR_LIT>' : self . document_type . pk , <EOL> '<STR_LIT:label>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> self . assertEqual ( Document . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . document = Document . objects . all ( ) . first ( ) <EOL> self . assertEqual ( self . document . exists ( ) , True ) <EOL> self . assertEqual ( self . document . size , <NUM_LIT> ) <EOL> self . assertEqual ( self . document . file_mimetype , '<STR_LIT>' ) <EOL> self . assertEqual ( self . document . file_mime_encoding , '<STR_LIT>' ) <EOL> self . assertEqual ( self . document . label , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> self . document . checksum , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( self . document . page_count , <NUM_LIT> ) <EOL> def test_issue_25 ( self ) : <EOL> logged_in = self . client . login ( <EOL> username = TEST_ADMIN_USERNAME , password = TEST_ADMIN_PASSWORD <EOL> ) <EOL> self . assertTrue ( logged_in ) <EOL> self . assertTrue ( self . admin_user . is_authenticated ( ) ) <EOL> self . client . post ( <EOL> reverse ( <EOL> '<STR_LIT>' , args = ( SOURCE_CHOICE_WEB_FORM , ) <EOL> ) , { '<STR_LIT:label>' : '<STR_LIT:test>' , '<STR_LIT>' : '<STR_LIT:n>' , '<STR_LIT>' : True } <EOL> ) <EOL> self . assertEqual ( WebFormSource . objects . count ( ) , <NUM_LIT:1> ) <EOL> with open ( TEST_SMALL_DOCUMENT_PATH ) as file_descriptor : <EOL> self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : file_descriptor , <EOL> '<STR_LIT>' : self . document_type . pk <EOL> } <EOL> ) <EOL> self . assertEqual ( Document . objects . count ( ) , <NUM_LIT:1> ) <EOL> document = Document . objects . first ( ) <EOL> self . assertEqual ( document . description , '<STR_LIT>' ) <EOL> document . description = TEST_DOCUMENT_DESCRIPTION <EOL> document . save ( ) <EOL> self . assertEqual ( document . description , TEST_DOCUMENT_DESCRIPTION ) <EOL> self . client . post ( <EOL> reverse ( '<STR_LIT>' , args = ( document . pk , ) ) , <EOL> { <EOL> '<STR_LIT:description>' : TEST_DOCUMENT_DESCRIPTION , <EOL> '<STR_LIT>' : document . language , '<STR_LIT:label>' : document . label <EOL> } <EOL> ) <EOL> document = Document . objects . first ( ) <EOL> self . assertEqual ( document . description , TEST_DOCUMENT_DESCRIPTION ) <EOL> class NewDocumentVersionViewTestCase ( GenericDocumentViewTestCase ) : <EOL> def test_new_version_block ( self ) : <EOL> """<STR_LIT>""" <EOL> self . login ( <EOL> username = TEST_ADMIN_USERNAME , password = TEST_ADMIN_PASSWORD <EOL> ) <EOL> NewVersionBlock . objects . block ( self . document ) <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 ) </s>
