<s> from __future__ import unicode_literals <EOL> from django . contrib . auth . models import User <EOL> from django . core . files import File <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import override_settings <EOL> from rest_framework . test import APITestCase <EOL> from documents . models import DocumentType <EOL> from documents . tests import TEST_DOCUMENT_TYPE , TEST_SMALL_DOCUMENT_PATH <EOL> from user_management . tests . literals import ( <EOL> TEST_ADMIN_EMAIL , TEST_ADMIN_PASSWORD , TEST_ADMIN_USERNAME <EOL> ) <EOL> from . . models import Tag <EOL> from . literals import ( <EOL> TEST_TAG_COLOR , TEST_TAG_COLOR_EDITED , TEST_TAG_LABEL , <EOL> TEST_TAG_LABEL_EDITED <EOL> ) <EOL> class TagAPITestCase ( APITestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <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 . force_authenticate ( user = self . admin_user ) <EOL> def tearDown ( self ) : <EOL> self . admin_user . delete ( ) <EOL> def test_tag_create ( self ) : <EOL> self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , { <EOL> '<STR_LIT:label>' : TEST_TAG_LABEL , '<STR_LIT>' : TEST_TAG_COLOR <EOL> } <EOL> ) <EOL> tag = Tag . objects . first ( ) <EOL> self . assertEqual ( Tag . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( tag . label , TEST_TAG_LABEL ) <EOL> self . assertEqual ( tag . color , TEST_TAG_COLOR ) <EOL> def test_tag_delete ( self ) : <EOL> tag = Tag . objects . create ( color = TEST_TAG_COLOR , label = TEST_TAG_LABEL ) <EOL> self . client . delete ( reverse ( '<STR_LIT>' , args = ( tag . pk , ) ) ) <EOL> self . assertEqual ( Tag . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_tag_edit ( self ) : <EOL> tag = Tag . objects . create ( color = TEST_TAG_COLOR , label = TEST_TAG_LABEL ) <EOL> self . client . put ( <EOL> reverse ( '<STR_LIT>' , args = ( tag . pk , ) ) , <EOL> { <EOL> '<STR_LIT:label>' : TEST_TAG_LABEL_EDITED , <EOL> '<STR_LIT>' : TEST_TAG_COLOR_EDITED <EOL> } <EOL> ) <EOL> tag = Tag . objects . first ( ) <EOL> self . assertEqual ( tag . label , TEST_TAG_LABEL_EDITED ) <EOL> self . assertEqual ( tag . color , TEST_TAG_COLOR_EDITED ) <EOL> @ override_settings ( OCR_AUTO_OCR = False ) <EOL> def test_tag_add_document ( self ) : <EOL> tag = Tag . objects . create ( color = TEST_TAG_COLOR , label = TEST_TAG_LABEL ) <EOL> document_type = DocumentType . objects . create ( <EOL> label = TEST_DOCUMENT_TYPE <EOL> ) <EOL> with open ( TEST_SMALL_DOCUMENT_PATH ) as file_object : <EOL> document = document_type . new_document ( <EOL> file_object = File ( file_object ) , <EOL> ) <EOL> self . client . post ( <EOL> reverse ( '<STR_LIT>' , args = ( document . pk , ) ) , <EOL> { '<STR_LIT>' : tag . pk } <EOL> ) <EOL> self . assertEqual ( tag . documents . count ( ) , <NUM_LIT:1> ) <EOL> @ override_settings ( OCR_AUTO_OCR = False ) <EOL> def test_tag_remove_document ( self ) : <EOL> tag = Tag . objects . create ( color = TEST_TAG_COLOR , label = TEST_TAG_LABEL ) <EOL> document_type = DocumentType . objects . create ( <EOL> label = TEST_DOCUMENT_TYPE <EOL> ) <EOL> with open ( TEST_SMALL_DOCUMENT_PATH ) as file_object : <EOL> document = document_type . new_document ( <EOL> file_object = File ( file_object ) , <EOL> ) <EOL> tag . documents . add ( document ) <EOL> self . client . delete ( <EOL> reverse ( '<STR_LIT>' , args = ( document . pk , tag . pk ) ) , <EOL> ) <EOL> self . assertEqual ( tag . documents . count ( ) , <NUM_LIT:0> ) </s>
