<s> from unittest import TestCase <EOL> from unittest . mock import MagicMock , patch <EOL> from openslides . core import views <EOL> from openslides . utils . rest_api import ValidationError <EOL> class TestUrlPatternsView ( TestCase ) : <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_context_data ( self , mock_resolver ) : <EOL> mock_resolver ( ) . reverse_dict = { <EOL> '<STR_LIT>' : ( [ [ '<STR_LIT>' , [ None ] ] ] , None , None ) , <EOL> '<STR_LIT>' : ( [ [ '<STR_LIT>' , [ '<STR_LIT>' ] ] ] , None , None ) , <EOL> ( '<STR_LIT>' , ) : [ [ [ '<STR_LIT>' ] ] ] } <EOL> view = views . UrlPatternsView ( ) <EOL> context = view . get_context_data ( ) <EOL> self . assertEqual ( <EOL> context , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> class ProjectorAPI ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . viewset = views . ProjectorViewSet ( ) <EOL> self . viewset . format_kwarg = None <EOL> def test_activate_elements ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> request = MagicMock ( ) <EOL> request . data = [ { '<STR_LIT:name>' : '<STR_LIT>' } ] <EOL> self . viewset . request = request <EOL> self . viewset . activate_elements ( request = request , pk = MagicMock ( ) ) <EOL> self . assertEqual ( len ( mock_object . return_value . config ) , <NUM_LIT:2> ) <EOL> def test_activate_elements_no_list ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> request = MagicMock ( ) <EOL> request . data = { '<STR_LIT:name>' : '<STR_LIT>' } <EOL> self . viewset . request = request <EOL> with self . assertRaises ( ValidationError ) : <EOL> self . viewset . activate_elements ( request = request , pk = MagicMock ( ) ) <EOL> def test_activate_elements_bad_element ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> request = MagicMock ( ) <EOL> request . data = [ { '<STR_LIT>' : '<STR_LIT>' } ] <EOL> self . viewset . request = request <EOL> with self . assertRaises ( ValidationError ) : <EOL> self . viewset . activate_elements ( request = request , pk = MagicMock ( ) ) <EOL> def test_prune_elements ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> request = MagicMock ( ) <EOL> request . data = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> self . viewset . request = request <EOL> self . viewset . prune_elements ( request = request , pk = MagicMock ( ) ) <EOL> self . assertEqual ( len ( mock_object . return_value . config ) , <NUM_LIT:1> ) <EOL> def test_prune_elements_with_stable ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True } } <EOL> request = MagicMock ( ) <EOL> request . data = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> self . viewset . request = request <EOL> self . viewset . prune_elements ( request = request , pk = MagicMock ( ) ) <EOL> self . assertEqual ( len ( mock_object . return_value . config ) , <NUM_LIT:2> ) <EOL> def test_update_elements ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> request = MagicMock ( ) <EOL> request . data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' } } <EOL> self . viewset . request = request <EOL> self . viewset . update_elements ( request = request , pk = MagicMock ( ) ) <EOL> self . assertEqual ( len ( mock_object . return_value . config ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( mock_object . return_value . config [ <EOL> '<STR_LIT>' ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> def test_update_elements_wrong_element ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> request = MagicMock ( ) <EOL> request . data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' } } <EOL> self . viewset . request = request <EOL> with self . assertRaises ( ValidationError ) : <EOL> self . viewset . update_elements ( request = request , pk = MagicMock ( ) ) <EOL> def test_deactivate_elements ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> request = MagicMock ( ) <EOL> request . data = [ '<STR_LIT>' ] <EOL> self . viewset . request = request <EOL> self . viewset . deactivate_elements ( request = request , pk = MagicMock ( ) ) <EOL> self . assertEqual ( len ( mock_object . return_value . config ) , <NUM_LIT:0> ) <EOL> def test_deactivate_elements_wrong_element ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> request = MagicMock ( ) <EOL> request . data = [ '<STR_LIT>' ] <EOL> self . viewset . request = request <EOL> with self . assertRaises ( ValidationError ) : <EOL> self . viewset . deactivate_elements ( request = request , pk = MagicMock ( ) ) <EOL> def test_deactivate_elements_no_list ( self , mock_object ) : <EOL> mock_object . return_value . config = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> request = MagicMock ( ) <EOL> request . data = '<STR_LIT>' <EOL> self . viewset . request = request <EOL> with self . assertRaises ( ValidationError ) : <EOL> self . viewset . deactivate_elements ( request = request , pk = MagicMock ( ) ) <EOL> def test_deactivate_elements_bad_list ( self , mock_object ) : <EOL> mock_object . return_value . config = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] <EOL> request = MagicMock ( ) <EOL> request . data = [ <NUM_LIT:1> ] <EOL> self . viewset . request = request <EOL> with self . assertRaises ( ValidationError ) : <EOL> self . viewset . deactivate_elements ( request = request , pk = MagicMock ( ) ) <EOL> def test_clear_elements ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> request = MagicMock ( ) <EOL> self . viewset . request = request <EOL> self . viewset . clear_elements ( request = request , pk = MagicMock ( ) ) <EOL> self . assertEqual ( len ( mock_object . return_value . config ) , <NUM_LIT:0> ) <EOL> def test_clear_elements_with_stable ( self , mock_object ) : <EOL> mock_object . return_value . config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True } } <EOL> request = MagicMock ( ) <EOL> self . viewset . request = request <EOL> self . viewset . clear_elements ( request = request , pk = MagicMock ( ) ) <EOL> self . assertEqual ( len ( mock_object . return_value . config ) , <NUM_LIT:1> ) </s>
