<s> import json <EOL> from django . core . urlresolvers import reverse <EOL> from django . dispatch import receiver <EOL> from rest_framework import status <EOL> from rest_framework . test import APIClient <EOL> from openslides import __version__ as version <EOL> from openslides . core . config import ConfigVariable , config <EOL> from openslides . core . models import CustomSlide , Projector <EOL> from openslides . core . signals import config_signal <EOL> from openslides . utils . rest_api import ValidationError <EOL> from openslides . utils . test import TestCase <EOL> class ProjectorAPI ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_slide_on_default_projector ( self ) : <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> customslide = CustomSlide . objects . create ( title = '<STR_LIT>' , text = '<STR_LIT>' ) <EOL> default_projector = Projector . objects . get ( pk = <NUM_LIT:1> ) <EOL> default_projector . config = { <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:id>' : customslide . id } } <EOL> default_projector . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ '<STR_LIT:1>' ] ) ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( json . loads ( response . content . decode ( ) ) , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT:id>' : customslide . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } } , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> def test_invalid_slide_on_default_projector ( self ) : <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> default_projector = Projector . objects . get ( pk = <NUM_LIT:1> ) <EOL> default_projector . config = { <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' } } <EOL> default_projector . save ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ '<STR_LIT:1>' ] ) ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( json . loads ( response . content . decode ( ) ) , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:error>' : '<STR_LIT>' } } , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> class VersionView ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_get ( self ) : <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( json . loads ( response . content . decode ( ) ) , { <EOL> '<STR_LIT>' : version , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT>' } ] } ) <EOL> class ConfigViewSet ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_retrieve ( self ) : <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( <EOL> response . data , <EOL> { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' } ) <EOL> def test_update ( self ) : <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . put ( <EOL> reverse ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT:value>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_update_wrong_datatype ( self ) : <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . put ( <EOL> reverse ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT:value>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , status . HTTP_400_BAD_REQUEST ) <EOL> self . assertEqual ( response . data , { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> def test_update_wrong_datatype_that_can_be_converted ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . put ( <EOL> reverse ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT:value>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_update_good_choice ( self ) : <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . put ( <EOL> reverse ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT:value>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_update_bad_choice ( self ) : <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . put ( <EOL> reverse ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT:value>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , status . HTTP_400_BAD_REQUEST ) <EOL> self . assertEqual ( response . data , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_update_validator_ok ( self ) : <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . put ( <EOL> reverse ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT:value>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_update_validator_invalid ( self ) : <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . put ( <EOL> reverse ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) , <EOL> { '<STR_LIT:value>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , status . HTTP_400_BAD_REQUEST ) <EOL> self . assertEqual ( response . data , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_update_only_with_key ( self ) : <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . put ( <EOL> reverse ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( response . status_code , status . HTTP_400_BAD_REQUEST ) <EOL> self . assertEqual ( response . data , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_metadata_with_hidden ( self ) : <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . options ( reverse ( '<STR_LIT>' ) ) <EOL> filter_obj = filter ( <EOL> lambda item : item [ '<STR_LIT:key>' ] == '<STR_LIT>' , <EOL> response . data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( list ( filter_obj ) ) , <NUM_LIT:0> ) <EOL> def validator_for_testing ( value ) : <EOL> """<STR_LIT>""" <EOL> if value == '<STR_LIT>' : <EOL> raise ValidationError ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> @ receiver ( config_signal , dispatch_uid = '<STR_LIT>' ) <EOL> def set_simple_config_view_integration_config_test ( sender , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> yield ConfigVariable ( <EOL> name = '<STR_LIT>' , <EOL> default_value = None , <EOL> label = '<STR_LIT>' ) <EOL> yield ConfigVariable ( <EOL> name = '<STR_LIT>' , <EOL> default_value = '<STR_LIT>' ) <EOL> yield ConfigVariable ( <EOL> name = '<STR_LIT>' , <EOL> default_value = <NUM_LIT:0> , <EOL> input_type = '<STR_LIT>' ) <EOL> yield ConfigVariable ( <EOL> name = '<STR_LIT>' , <EOL> default_value = '<STR_LIT>' , <EOL> input_type = '<STR_LIT>' , <EOL> choices = ( <EOL> { '<STR_LIT:value>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:value>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> yield ConfigVariable ( <EOL> name = '<STR_LIT>' , <EOL> default_value = '<STR_LIT>' , <EOL> validators = ( validator_for_testing , ) ) <EOL> yield ConfigVariable ( <EOL> name = '<STR_LIT>' , <EOL> default_value = None , <EOL> label = '<STR_LIT>' , <EOL> hidden = True ) </s>
