<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import json <EOL> import mock <EOL> import time <EOL> import unittest <EOL> from cStringIO import StringIO <EOL> from functools import partial <EOL> from tornado import httpclient <EOL> from viewfinder . backend . base . testing import MockAsyncHTTPClient <EOL> from viewfinder . backend . db import dynamodb_client , vf_schema <EOL> from viewfinder . backend . db . db_client import DBKey <EOL> from viewfinder . backend . db . episode import Episode <EOL> from viewfinder . backend . db . photo import Photo <EOL> from viewfinder . backend . db . post import Post <EOL> from viewfinder . backend . db . test . base_test import DBBaseTestCase <EOL> class DBObjectTestCase ( DBBaseTestCase ) : <EOL> @ unittest . skip ( "<STR_LIT>" ) <EOL> def testRangeQuery ( self ) : <EOL> """<STR_LIT>""" <EOL> def _MakeResponse ( max_index , request ) : <EOL> request_dict = json . loads ( request . body ) <EOL> limit = min ( request_dict . get ( '<STR_LIT>' , <NUM_LIT:2> ) , <NUM_LIT:2> ) <EOL> is_count = request_dict . get ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in request_dict : <EOL> start_index = int ( request_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:S>' ] [ '<STR_LIT:S>' ] [ - <NUM_LIT:1> ] ) + <NUM_LIT:1> <EOL> else : <EOL> start_index = <NUM_LIT:0> <EOL> count = min ( max_index - start_index , limit ) <EOL> items = [ ] <EOL> for i in xrange ( start_index , start_index + count ) : <EOL> items . append ( { '<STR_LIT>' : { '<STR_LIT:S>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:S>' : '<STR_LIT>' % i } } ) <EOL> response_dict = { '<STR_LIT>' : count , <EOL> '<STR_LIT>' : <NUM_LIT:0.5> } <EOL> if not is_count : <EOL> response_dict [ '<STR_LIT>' ] = items <EOL> if start_index + count < max_index : <EOL> response_dict [ '<STR_LIT>' ] = { '<STR_LIT>' : { '<STR_LIT:S>' : items [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] } , <EOL> '<STR_LIT>' : { '<STR_LIT:S>' : items [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] } } <EOL> return httpclient . HTTPResponse ( request , <NUM_LIT:200> , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' } , <EOL> buffer = StringIO ( json . dumps ( response_dict ) ) ) <EOL> client = dynamodb_client . DynamoDBClient ( schema = vf_schema . SCHEMA ) <EOL> self . _RunAsync ( client . GetItem , vf_schema . TEST_RENAME , DBKey ( '<STR_LIT:1>' , <NUM_LIT:1> ) , attributes = None , must_exist = False ) <EOL> with mock . patch ( '<STR_LIT>' , MockAsyncHTTPClient ( ) ) as mock_client : <EOL> mock_client . map ( r'<STR_LIT>' , partial ( _MakeResponse , <NUM_LIT:5> ) ) <EOL> posts = self . _RunAsync ( Post . RangeQuery , client , '<STR_LIT>' , None , None , None ) <EOL> self . assertEqual ( len ( posts ) , <NUM_LIT:2> ) <EOL> posts = self . _RunAsync ( Post . RangeQuery , client , '<STR_LIT>' , None , <NUM_LIT:2> , None ) <EOL> self . assertEqual ( len ( posts ) , <NUM_LIT:2> ) <EOL> posts = self . _RunAsync ( Post . RangeQuery , client , '<STR_LIT>' , None , <NUM_LIT:5> , None ) <EOL> self . assertEqual ( len ( posts ) , <NUM_LIT:5> ) <EOL> posts = self . _RunAsync ( Post . RangeQuery , client , '<STR_LIT>' , None , <NUM_LIT:7> , None ) <EOL> self . assertEqual ( len ( posts ) , <NUM_LIT:5> ) <EOL> count = self . _RunAsync ( Post . RangeQuery , client , '<STR_LIT>' , None , None , None , count = True ) <EOL> self . assertEqual ( count , <NUM_LIT:2> ) <EOL> count = self . _RunAsync ( Post . RangeQuery , client , '<STR_LIT>' , None , <NUM_LIT:2> , None , count = True ) <EOL> self . assertEqual ( count , <NUM_LIT:2> ) <EOL> count = self . _RunAsync ( Post . RangeQuery , client , '<STR_LIT>' , None , <NUM_LIT:5> , None , count = True ) <EOL> self . assertEqual ( count , <NUM_LIT:5> ) <EOL> count = self . _RunAsync ( Post . RangeQuery , client , '<STR_LIT>' , None , <NUM_LIT:7> , None , count = True ) <EOL> self . assertEqual ( count , <NUM_LIT:5> ) <EOL> def testBatchQuery ( self ) : <EOL> """<STR_LIT>""" <EOL> keys = [ ] <EOL> for i in xrange ( <NUM_LIT:3> ) : <EOL> photo_id = Photo . ConstructPhotoId ( time . time ( ) , self . _mobile_dev . device_id , <NUM_LIT:1> ) <EOL> episode_id = Episode . ConstructEpisodeId ( time . time ( ) , self . _mobile_dev . device_id , <NUM_LIT:1> ) <EOL> ph_dict = { '<STR_LIT>' : photo_id , <EOL> '<STR_LIT>' : self . _user . user_id , <EOL> '<STR_LIT>' : episode_id } <EOL> self . _RunAsync ( Photo . CreateNew , self . _client , ** ph_dict ) <EOL> keys . append ( DBKey ( photo_id , None ) ) <EOL> keys . append ( DBKey ( '<STR_LIT>' , None ) ) <EOL> photos = self . _RunAsync ( Photo . BatchQuery , self . _client , keys , None , must_exist = False ) <EOL> self . assertEqual ( len ( photos ) , <NUM_LIT:4> ) <EOL> for i in xrange ( <NUM_LIT:3> ) : <EOL> self . assertEqual ( photos [ i ] . GetKey ( ) , keys [ i ] ) <EOL> self . assertIsNone ( photos [ <NUM_LIT:3> ] ) </s>
