<s> from __future__ import unicode_literals <EOL> from documents . models import DocumentType <EOL> from documents . permissions import ( <EOL> permission_document_properties_edit , permission_document_view <EOL> ) <EOL> from documents . tests . literals import TEST_DOCUMENT_TYPE_2 <EOL> from documents . tests . test_views import GenericDocumentViewTestCase <EOL> from user_management . tests . literals import ( <EOL> TEST_USER_USERNAME , TEST_USER_PASSWORD <EOL> ) <EOL> from . . models import MetadataType <EOL> from . . permissions import ( <EOL> permission_metadata_document_add , permission_metadata_document_remove , <EOL> permission_metadata_document_edit <EOL> ) <EOL> from . literals import ( <EOL> TEST_DOCUMENT_METADATA_VALUE_2 , TEST_METADATA_TYPE_LABEL , <EOL> TEST_METADATA_TYPE_LABEL_2 , TEST_METADATA_TYPE_NAME , <EOL> TEST_METADATA_TYPE_NAME_2 <EOL> ) <EOL> class DocumentMetadataTestCase ( GenericDocumentViewTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( DocumentMetadataTestCase , self ) . setUp ( ) <EOL> self . metadata_type = MetadataType . objects . create ( <EOL> name = TEST_METADATA_TYPE_NAME , label = TEST_METADATA_TYPE_LABEL <EOL> ) <EOL> self . document_type . metadata . create ( metadata_type = self . metadata_type ) <EOL> def test_metadata_add_view_no_permission ( self ) : <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_document_view . stored_permission <EOL> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , <EOL> data = { '<STR_LIT>' : self . metadata_type . pk } <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( len ( self . document . metadata . all ( ) ) , <NUM_LIT:0> ) <EOL> def test_metadata_add_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_view . stored_permission <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_metadata_document_add . stored_permission <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_metadata_document_edit . stored_permission <EOL> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , <EOL> data = { '<STR_LIT>' : self . metadata_type . pk } , follow = True <EOL> ) <EOL> self . assertContains ( response , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( self . document . metadata . all ( ) ) , <NUM_LIT:1> ) <EOL> def test_metadata_edit_after_document_type_change ( self ) : <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_document_properties_edit . stored_permission <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_metadata_document_edit . stored_permission <EOL> ) <EOL> document_type_2 = DocumentType . objects . create ( <EOL> label = TEST_DOCUMENT_TYPE_2 <EOL> ) <EOL> metadata_type_2 = MetadataType . objects . create ( <EOL> name = TEST_METADATA_TYPE_NAME_2 , label = TEST_METADATA_TYPE_LABEL_2 <EOL> ) <EOL> document_metadata_2 = document_type_2 . metadata . create ( <EOL> metadata_type = metadata_type_2 , required = True <EOL> ) <EOL> self . document . set_document_type ( document_type = document_type_2 ) <EOL> response = self . get ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , follow = True <EOL> ) <EOL> self . assertContains ( response , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , data = { <EOL> '<STR_LIT>' : document_metadata_2 . pk , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : TEST_DOCUMENT_METADATA_VALUE_2 , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , follow = True <EOL> ) <EOL> self . assertContains ( response , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> self . assertEqual ( <EOL> self . document . metadata . get ( metadata_type = metadata_type_2 ) . value , <EOL> TEST_DOCUMENT_METADATA_VALUE_2 <EOL> ) <EOL> def test_metadata_remove_view_no_permission ( self ) : <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> document_metadata = self . document . metadata . create ( <EOL> metadata_type = self . metadata_type , value = '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( len ( self . document . metadata . all ( ) ) , <NUM_LIT:1> ) <EOL> self . role . permissions . add ( <EOL> permission_document_view . stored_permission <EOL> ) <EOL> response = self . get ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , data = { <EOL> '<STR_LIT>' : document_metadata . metadata_type . pk , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , follow = True <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( len ( self . document . metadata . all ( ) ) , <NUM_LIT:1> ) <EOL> def test_metadata_remove_view_with_permission ( self ) : <EOL> self . login ( <EOL> username = TEST_USER_USERNAME , password = TEST_USER_PASSWORD <EOL> ) <EOL> document_metadata = self . document . metadata . create ( <EOL> metadata_type = self . metadata_type , value = '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( len ( self . document . metadata . all ( ) ) , <NUM_LIT:1> ) <EOL> self . role . permissions . add ( <EOL> permission_document_view . stored_permission <EOL> ) <EOL> self . role . permissions . add ( <EOL> permission_metadata_document_remove . stored_permission <EOL> ) <EOL> response = self . get ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , <EOL> ) <EOL> self . assertContains ( response , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> response = self . post ( <EOL> '<STR_LIT>' , args = ( self . document . pk , ) , data = { <EOL> '<STR_LIT>' : document_metadata . metadata_type . pk , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , follow = True <EOL> ) <EOL> self . assertContains ( response , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( self . document . metadata . all ( ) ) , <NUM_LIT:0> ) </s>
