<s> from django . test . client import RequestFactory <EOL> from open_facebook . api import OpenFacebook , FacebookAuthorization <EOL> from django . core . handlers . base import BaseHandler <EOL> class RequestMock ( RequestFactory ) : <EOL> '''<STR_LIT>''' <EOL> def request ( self , ** request ) : <EOL> "<STR_LIT>" <EOL> request [ '<STR_LIT:POST>' ] = dict ( ) <EOL> request [ '<STR_LIT:GET>' ] = dict ( ) <EOL> request = RequestFactory . request ( self , ** request ) <EOL> handler = BaseHandler ( ) <EOL> handler . load_middleware ( ) <EOL> for middleware_method in handler . _request_middleware : <EOL> if middleware_method ( request ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return request <EOL> class MockFacebookAPI ( OpenFacebook ) : <EOL> mock = True <EOL> def me ( self ) : <EOL> from django_facebook . test_utils . sample_user_data import user_data <EOL> data = user_data [ self . access_token ] <EOL> return data <EOL> def my_image_url ( self , size = None ) : <EOL> from django_facebook . test_utils . sample_user_data import user_data <EOL> data = user_data [ self . access_token ] <EOL> image_url = data [ '<STR_LIT:image>' ] <EOL> return image_url <EOL> def is_authenticated ( self , * args , ** kwargs ) : <EOL> from django_facebook . test_utils . sample_user_data import user_data <EOL> return self . access_token in user_data <EOL> def get ( self , path , ** kwargs ) : <EOL> if '<STR_LIT>' in path : <EOL> like = dict ( <EOL> name = "<STR_LIT>" , category = "<STR_LIT>" , id = "<STR_LIT>" ) <EOL> response = dict ( data = [ like ] ) <EOL> return response <EOL> if '<STR_LIT>' or '<STR_LIT>' in path : <EOL> friend = dict ( name = "<STR_LIT>" , id = "<STR_LIT>" ) <EOL> response = dict ( data = [ friend ] ) <EOL> return response <EOL> def set ( self , path , ** kwargs ) : <EOL> return dict ( id = <NUM_LIT> ) <EOL> def fql ( self , query , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> friend = dict ( name = "<STR_LIT>" , uid = <NUM_LIT> , gender = '<STR_LIT:F>' ) <EOL> response = [ friend ] <EOL> return response <EOL> class MockFacebookAuthorization ( FacebookAuthorization ) : <EOL> @ classmethod <EOL> def extend_access_token ( cls , access_token ) : <EOL> '''<STR_LIT>''' <EOL> response = dict ( access_token = access_token , expires = '<STR_LIT>' ) <EOL> return response </s>
