<s> from __future__ import unicode_literals <EOL> import mock <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> import trovebox <EOL> class TestActions ( unittest . TestCase ) : <EOL> test_host = "<STR_LIT>" <EOL> test_photos_dict = [ { "<STR_LIT:id>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:id>" : "<STR_LIT>" } ] <EOL> test_actions_dict = [ { "<STR_LIT:id>" : "<STR_LIT:1>" , <EOL> "<STR_LIT:target>" : test_photos_dict [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:2> } , <EOL> { "<STR_LIT:id>" : "<STR_LIT:2>" , <EOL> "<STR_LIT:target>" : test_photos_dict [ <NUM_LIT:1> ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:2> } ] <EOL> def setUp ( self ) : <EOL> self . client = trovebox . Trovebox ( host = self . test_host ) <EOL> self . test_photos = [ trovebox . objects . photo . Photo ( self . client , photo ) <EOL> for photo in self . test_photos_dict ] <EOL> self . test_actions = [ trovebox . objects . action . Action ( self . client , action ) <EOL> for action in self . test_actions_dict ] <EOL> @ staticmethod <EOL> def _return_value ( result , message = "<STR_LIT>" , code = <NUM_LIT:200> ) : <EOL> return { "<STR_LIT:message>" : message , "<STR_LIT:code>" : code , "<STR_LIT:result>" : result } <EOL> class TestActionCreate ( TestActions ) : <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_create ( self , mock_post ) : <EOL> """<STR_LIT>""" <EOL> mock_post . return_value = self . _return_value ( self . test_actions_dict [ <NUM_LIT:0> ] ) <EOL> result = self . client . action . create ( target = self . test_photos [ <NUM_LIT:0> ] , type = "<STR_LIT>" , foo = "<STR_LIT:bar>" ) <EOL> mock_post . assert_called_with ( "<STR_LIT>" % <EOL> self . test_photos [ <NUM_LIT:0> ] . id , <EOL> type = "<STR_LIT>" , <EOL> foo = "<STR_LIT:bar>" ) <EOL> self . assertEqual ( result . id , "<STR_LIT:1>" ) <EOL> self . assertEqual ( result . target . id , "<STR_LIT>" ) <EOL> self . assertEqual ( result . target_type , "<STR_LIT>" ) <EOL> self . assertEqual ( result . type , "<STR_LIT>" ) <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_create_id ( self , mock_post ) : <EOL> """<STR_LIT>""" <EOL> mock_post . return_value = self . _return_value ( self . test_actions_dict [ <NUM_LIT:0> ] ) <EOL> result = self . client . action . create ( target = self . test_photos [ <NUM_LIT:0> ] . id , <EOL> target_type = "<STR_LIT>" , type = "<STR_LIT>" , <EOL> foo = "<STR_LIT:bar>" ) <EOL> mock_post . assert_called_with ( "<STR_LIT>" % <EOL> self . test_photos [ <NUM_LIT:0> ] . id , <EOL> type = "<STR_LIT>" , <EOL> foo = "<STR_LIT:bar>" ) <EOL> self . assertEqual ( result . id , "<STR_LIT:1>" ) <EOL> self . assertEqual ( result . target . id , "<STR_LIT>" ) <EOL> self . assertEqual ( result . target_type , "<STR_LIT>" ) <EOL> self . assertEqual ( result . type , "<STR_LIT>" ) <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_create_invalid_type ( self , mock_post ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( AttributeError ) : <EOL> self . client . action . create ( target = object ( ) ) <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_create_invalid_return_type ( self , mock_post ) : <EOL> """<STR_LIT>""" <EOL> mock_post . return_value = self . _return_value ( { "<STR_LIT:target>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } ) <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> self . client . action . create ( target = self . test_photos [ <NUM_LIT:0> ] ) <EOL> class TestActionDelete ( TestActions ) : <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_delete ( self , mock_post ) : <EOL> """<STR_LIT>""" <EOL> mock_post . return_value = self . _return_value ( True ) <EOL> result = self . client . action . delete ( self . test_actions [ <NUM_LIT:0> ] , foo = "<STR_LIT:bar>" ) <EOL> mock_post . assert_called_with ( "<STR_LIT>" , foo = "<STR_LIT:bar>" ) <EOL> self . assertEqual ( result , True ) <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_delete_id ( self , mock_post ) : <EOL> """<STR_LIT>""" <EOL> mock_post . return_value = self . _return_value ( True ) <EOL> result = self . client . action . delete ( "<STR_LIT:1>" , foo = "<STR_LIT:bar>" ) <EOL> mock_post . assert_called_with ( "<STR_LIT>" , foo = "<STR_LIT:bar>" ) <EOL> self . assertEqual ( result , True ) <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_object_delete ( self , mock_post ) : <EOL> """<STR_LIT>""" <EOL> mock_post . return_value = self . _return_value ( True ) <EOL> action = self . test_actions [ <NUM_LIT:0> ] <EOL> result = action . delete ( foo = "<STR_LIT:bar>" ) <EOL> mock_post . assert_called_with ( "<STR_LIT>" , foo = "<STR_LIT:bar>" ) <EOL> self . assertEqual ( result , True ) <EOL> self . assertEqual ( action . get_fields ( ) , { } ) <EOL> self . assertEqual ( action . id , None ) <EOL> class TestActionView ( TestActions ) : <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_view ( self , mock_get ) : <EOL> """<STR_LIT>""" <EOL> mock_get . return_value = self . _return_value ( self . test_actions_dict [ <NUM_LIT:1> ] ) <EOL> result = self . client . action . view ( self . test_actions [ <NUM_LIT:0> ] , name = "<STR_LIT>" ) <EOL> mock_get . assert_called_with ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> self . assertEqual ( result . id , "<STR_LIT:2>" ) <EOL> self . assertEqual ( result . target . id , "<STR_LIT>" ) <EOL> self . assertEqual ( result . target_type , "<STR_LIT>" ) <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_view_id ( self , mock_get ) : <EOL> """<STR_LIT>""" <EOL> mock_get . return_value = self . _return_value ( self . test_actions_dict [ <NUM_LIT:1> ] ) <EOL> result = self . client . action . view ( "<STR_LIT:1>" , name = "<STR_LIT>" ) <EOL> mock_get . assert_called_with ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> self . assertEqual ( result . id , "<STR_LIT:2>" ) <EOL> self . assertEqual ( result . target . id , "<STR_LIT>" ) <EOL> self . assertEqual ( result . target_type , "<STR_LIT>" ) <EOL> @ mock . patch . object ( trovebox . Trovebox , '<STR_LIT>' ) <EOL> def test_action_object_view ( self , mock_get ) : <EOL> """<STR_LIT>""" <EOL> mock_get . return_value = self . _return_value ( self . test_actions_dict [ <NUM_LIT:1> ] ) <EOL> action = self . test_actions [ <NUM_LIT:0> ] <EOL> action . view ( name = "<STR_LIT>" ) <EOL> mock_get . assert_called_with ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> self . assertEqual ( action . id , "<STR_LIT:2>" ) <EOL> self . assertEqual ( action . target . id , "<STR_LIT>" ) <EOL> self . assertEqual ( action . target_type , "<STR_LIT>" ) <EOL> class TestActionMisc ( TestActions ) : <EOL> def test_update_fields_with_no_target ( self ) : <EOL> """<STR_LIT>""" <EOL> action = self . test_actions [ <NUM_LIT:0> ] <EOL> action . target = None <EOL> action . target_type = None <EOL> action . _update_fields_with_objects ( ) </s>
