<s> from tests import unittest , mock , Redmine , URL <EOL> response = { <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:foo>' , '<STR_LIT:id>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:bar>' , '<STR_LIT:id>' : <NUM_LIT:2> } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:id>' : <NUM_LIT:3> } , <EOL> ] <EOL> } <EOL> class TestResultSet ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . url = URL <EOL> self . redmine = Redmine ( self . url ) <EOL> self . response = mock . Mock ( status_code = <NUM_LIT:200> , json = mock . Mock ( return_value = response ) ) <EOL> patcher_get = mock . patch ( '<STR_LIT>' , return_value = self . response ) <EOL> patcher_put = mock . patch ( '<STR_LIT>' , return_value = self . response ) <EOL> patcher_delete = mock . patch ( '<STR_LIT>' , return_value = self . response ) <EOL> patcher_get . start ( ) <EOL> patcher_put . start ( ) <EOL> patcher_delete . start ( ) <EOL> self . addCleanup ( patcher_get . stop ) <EOL> self . addCleanup ( patcher_put . stop ) <EOL> self . addCleanup ( patcher_delete . stop ) <EOL> def test_has_custom_repr ( self ) : <EOL> self . assertEqual ( <EOL> repr ( self . redmine . project . all ( ) ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_offset_limit_all ( self ) : <EOL> self . response . json . return_value = dict ( response , total_count = <NUM_LIT:3> , limit = <NUM_LIT:0> , offset = <NUM_LIT:0> ) <EOL> projects = self . redmine . project . all ( ) <EOL> self . assertEqual ( projects . limit , <NUM_LIT:0> ) <EOL> self . assertEqual ( projects . offset , <NUM_LIT:0> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] . id , <NUM_LIT:2> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:2> ] . id , <NUM_LIT:3> ) <EOL> def test_offset_limit ( self ) : <EOL> response_with_limit_offset = { '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : response [ '<STR_LIT>' ] [ <NUM_LIT:1> : <NUM_LIT:3> ] } <EOL> self . response . json . return_value = response_with_limit_offset <EOL> projects = self . redmine . project . all ( ) [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . assertEqual ( projects . limit , <NUM_LIT:3> ) <EOL> self . assertEqual ( projects . offset , <NUM_LIT:1> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] . id , <NUM_LIT:2> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] . id , <NUM_LIT:3> ) <EOL> def test_offset_limit_mimic ( self ) : <EOL> projects = self . redmine . project . all ( ) [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . assertEqual ( projects . limit , <NUM_LIT:3> ) <EOL> self . assertEqual ( projects . offset , <NUM_LIT:1> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] . id , <NUM_LIT:2> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] . id , <NUM_LIT:3> ) <EOL> def test_total_count ( self ) : <EOL> self . response . json . return_value = dict ( response , total_count = <NUM_LIT:3> , limit = <NUM_LIT:0> , offset = <NUM_LIT:0> ) <EOL> projects = self . redmine . project . all ( ) <EOL> len ( projects ) <EOL> self . assertEqual ( projects . total_count , <NUM_LIT:3> ) <EOL> def test_total_count_mimic ( self ) : <EOL> response_with_custom_fields = { '<STR_LIT>' : dict ( response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , custom_fields = [ { '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT:value>' : <NUM_LIT:0> } ] ) } <EOL> self . response . json . return_value = response_with_custom_fields <EOL> project = self . redmine . project . get ( '<STR_LIT:foo>' ) <EOL> self . assertEqual ( project . custom_fields . total_count , <NUM_LIT:1> ) <EOL> def test_total_count_raise_exception_if_not_evaluated ( self ) : <EOL> from redmine . exceptions import ResultSetTotalCountError <EOL> self . assertRaises ( ResultSetTotalCountError , lambda : self . redmine . project . all ( ) . total_count ) <EOL> def test_resultset_is_empty ( self ) : <EOL> self . response . json . return_value = { '<STR_LIT>' : <NUM_LIT:100> , '<STR_LIT>' : [ ] , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> projects = self . redmine . project . all ( ) <EOL> self . assertEqual ( len ( projects ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( list ( projects ) , [ ] ) <EOL> def test_sliced_resultset_is_empty ( self ) : <EOL> self . response . json . return_value = { '<STR_LIT>' : <NUM_LIT:100> , '<STR_LIT>' : [ ] , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> projects = self . redmine . project . all ( ) [ : <NUM_LIT:200> ] <EOL> self . assertEqual ( len ( projects ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( list ( projects ) , [ ] ) <EOL> def test_supports_iteration ( self ) : <EOL> projects = list ( self . redmine . project . all ( ) ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] . identifier , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] . identifier , '<STR_LIT:bar>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] . id , <NUM_LIT:2> ) <EOL> def test_supports_len ( self ) : <EOL> self . assertEqual ( len ( self . redmine . project . all ( ) ) , <NUM_LIT:3> ) <EOL> def test_get_method_resource_found ( self ) : <EOL> projects = self . redmine . project . all ( ) . get ( <NUM_LIT:2> ) <EOL> self . assertEqual ( projects . id , <NUM_LIT:2> ) <EOL> def test_get_method_resource_not_found ( self ) : <EOL> projects = self . redmine . project . all ( ) . get ( <NUM_LIT:6> ) <EOL> self . assertEqual ( projects , None ) <EOL> def test_filter_method ( self ) : <EOL> projects = self . redmine . project . all ( ) . filter ( ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] . id , <NUM_LIT:3> ) <EOL> def test_update_method ( self ) : <EOL> projects = self . redmine . project . all ( ) . update ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:2> ] . name , '<STR_LIT>' ) <EOL> def test_delete_method ( self ) : <EOL> self . assertEqual ( self . redmine . project . all ( ) . delete ( ) , True ) <EOL> def test_values_method ( self ) : <EOL> from redmine . resultsets import ValuesResourceSet <EOL> self . assertIsInstance ( self . redmine . project . all ( ) . values ( ) , ValuesResourceSet ) <EOL> def test_values_resourceset_supports_iteration ( self ) : <EOL> projects = list ( self . redmine . project . all ( ) . values ( ) ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , '<STR_LIT:bar>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , <NUM_LIT:2> ) <EOL> def test_values_resourceset_supports_field_limits ( self ) : <EOL> projects = list ( self . redmine . project . all ( ) . values ( '<STR_LIT:id>' ) ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <NUM_LIT:1> ) <EOL> self . assertRaises ( KeyError , lambda : projects [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , <NUM_LIT:2> ) <EOL> self . assertRaises ( KeyError , lambda : projects [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] ) <EOL> def test_values_resourceset_get_method_resource_found ( self ) : <EOL> projects = self . redmine . project . all ( ) . values ( ) . get ( <NUM_LIT:2> ) <EOL> self . assertEqual ( projects [ '<STR_LIT:id>' ] , <NUM_LIT:2> ) <EOL> def test_values_resourceset_get_method_resource_not_found ( self ) : <EOL> projects = self . redmine . project . all ( ) . values ( ) . get ( <NUM_LIT:6> ) <EOL> self . assertEqual ( projects , None ) <EOL> def test_values_resourceset_filter_method ( self ) : <EOL> projects = self . redmine . project . all ( ) . values ( ) . filter ( ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , <NUM_LIT:3> ) <EOL> def test_values_resourceset_update_method ( self ) : <EOL> projects = self . redmine . project . all ( ) . values ( ) . update ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( projects [ <NUM_LIT:2> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> def test_resourceset_is_picklable ( self ) : <EOL> import pickle <EOL> projects = self . redmine . project . all ( ) <EOL> unpickled_projects = pickle . loads ( pickle . dumps ( projects ) ) <EOL> self . assertEqual ( projects [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , unpickled_projects [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( projects [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] , unpickled_projects [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( projects [ <NUM_LIT:2> ] [ '<STR_LIT:name>' ] , unpickled_projects [ <NUM_LIT:2> ] [ '<STR_LIT:name>' ] ) <EOL> def test_values_resourceset_delete_method ( self ) : <EOL> self . assertEqual ( self . redmine . project . all ( ) . values ( ) . delete ( ) , True ) <EOL> def test_values_resourceset_filter_param_exception ( self ) : <EOL> from redmine . exceptions import ResourceSetFilterParamError <EOL> self . assertRaises ( ResourceSetFilterParamError , lambda : self . redmine . project . all ( ) . values ( ) . filter ( <NUM_LIT:1> ) ) <EOL> def test_filter_param_exception ( self ) : <EOL> from redmine . exceptions import ResourceSetFilterParamError <EOL> self . assertRaises ( ResourceSetFilterParamError , lambda : self . redmine . project . all ( ) . filter ( <NUM_LIT:1> ) ) <EOL> def test_index_error_exception ( self ) : <EOL> from redmine . exceptions import ResourceSetIndexError <EOL> self . assertRaises ( ResourceSetIndexError , lambda : self . redmine . project . all ( ) [ <NUM_LIT:6> ] ) </s>
