def test_get_temp_img_invalid_secret(self): collection_name = 'share_api_col_name' + str(random.randint(0,100)) owner_id = self.account_id subscribers = [self.subscriber_id] sharing_secret, subscriber_list =\ self.__create_shared_collection(owner_id, subscribers, collection_name) #add primary and secondary listeners sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret, 'Listen']) sharing_space_url = self.get_url(sharing_space_url) details = {'user_id': owner_id} json_str = json.dumps(details) headers, post_body = HTTPHelper.create_multipart_request_with_parameters({'details' : json_str}) #owner listens as primary listener self.http_client.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, callback=self.primary_listener_returned, request_timeout = 100, connect_timeout = 100) self.__wait(5) #owner listeners as backup listener self.http_client.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, callback=self.backup_listener_returned, request_timeout = 100, connect_timeout = 100) self.__primary_listener_returned = False self.__backup_listener_returned = False #subscriber adds an action note_name = 'name' + str(random.randint(0,100)) note_img_file = open('../../test_resources/note_img.jpg') json_str = self.__make_update_note_img_action(self.subscriber_id, collection_name, note_name) header, post_body = HTTPHelper.create_multipart_request_with_file_and_params({'action' : json_str}, 'file', note_img_file) sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret]) response = self.fetch(path=sharing_space_url, method = 'POST', headers=header, body=post_body, request_timeout = 100, connect_timeout = 100) self.assertEqual(200, response.code) self.__wait(15) self.assertTrue(self.__primary_listener_returned) details = self.__primary_listener_json_obj[SharingEvent.UPDATE_NOTE_IMG] for note_name in details: secret = 'dummy'+ str(random.randint(0,100)) temp_url = sharing_space_url + '/'+ owner_id + '/' +\ collection_name + '/' + note_name + '/' + secret response = self.fetch(path=temp_url, method = 'GET') #we still should get the image because the secret is used to revive #the temp image from the cache and if its not there we discard #and use otheri nformation to get the image self.assertEqual(StorageResponse.OK, response.code) self.assertTrue(response.body is not None) self.__cleanup(owner_id, collection_name, subscriber_list) SharingSpaceStorage.get_instance().stop_cleanup_service()
def test_get_temp_img_thumbnail(self): collection_name = 'share_api_col_name' + str(random.randint(0,100)) owner_id = self.account_id subscribers = [self.subscriber_id] sharing_secret, subscriber_list =\ self.__create_shared_collection(owner_id, subscribers, collection_name) #add primary and secondary listeners sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret, 'Listen']) sharing_space_url = self.get_url(sharing_space_url) details = {'user_id': owner_id} json_str = json.dumps(details) headers, post_body = HTTPHelper.create_multipart_request_with_parameters({'details' : json_str}) #owner listens as primary listener self.http_client.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, callback=self.primary_listener_returned, request_timeout = 100, connect_timeout = 100) self.__wait(5) #owner listeners as backup listener self.http_client.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, callback=self.backup_listener_returned, request_timeout = 100, connect_timeout = 100) self.__primary_listener_returned = False self.__backup_listener_returned = False #subscriber adds an action thumbnail = open('../../test_resources/note_img.jpg') json_str = self.__make_update_thumbnail_action(self.subscriber_id, collection_name) header, post_body = HTTPHelper.create_multipart_request_with_file_and_params({'action' : json_str}, 'file', thumbnail) sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret]) response = self.fetch(path=sharing_space_url, method = 'POST', headers=header, body=post_body) self.assertEqual(200, response.code) self.__wait(10) self.assertTrue(self.__primary_listener_returned) secret = self.__primary_listener_json_obj[SharingEvent.UPDATE_THUMBNAIL] temp_url = sharing_space_url + '/'+ owner_id + '/' +\ collection_name + '/Thumbnail/' + secret response = self.fetch(path=temp_url, method = 'GET') self.assertEqual(StorageResponse.OK, response.code) self.assertTrue(response.body is not None) self.__cleanup(owner_id, collection_name, subscriber_list) SharingSpaceStorage.get_instance().stop_cleanup_service()
def test_add_categories(self): categories_file = open('../../test_resources/categories.xml') url = '/' + self.account_id + '/Categories' headers, post_data = HTTPHelper.create_multipart_request_with_single_file('file', categories_file) response = self.fetch(path=url, headers=headers, method='POST', body=post_data) self.assertEqual(200, response.code)
def test_add_action(self): collection_name = 'share_api_col_name' + str(random.randint(0,100)) owner_id = self.account_id subscribers = [self.subscriber_id] sharing_secret, subscriber_list =\ self.__create_shared_collection(owner_id, subscribers, collection_name) note_name = 'note' + str(random.randint(0,100)) json_str = self.__make_update_not_action(self.subscriber_id, collection_name, note_name) note_file = open('../../test_resources/XooML.xml') header, post_body = HTTPHelper.create_multipart_request_with_file_and_params({'action' : json_str}, 'file', note_file) sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret]) response = self.fetch(path=sharing_space_url, method = 'POST', headers=header, body=post_body) self.__wait(10) self.assertEqual(200, response.code) self.__cleanup(owner_id, collection_name, subscriber_list) SharingSpaceStorage.get_instance().stop_cleanup_service()
def test_add_listener_missing_parameter(self): collection_name = 'share_api_col_name' + str(random.randint(0,100)) owner_id = self.account_id subscribers = [self.subscriber_id] sharing_secret, subscriber_list =\ self.__create_shared_collection(owner_id, subscribers, collection_name) #add primary and secondary listeners sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret, 'Listen']) details = {'liliuser_id': owner_id} json_str = json.dumps(details) SharingSpaceStorage.get_instance().stop_cleanup_service() headers, post_body = HTTPHelper.create_multipart_request_with_parameters({'details' : json_str}) #owner listens as primary listener #owner listens as primary listener response1 = self.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, request_timeout = 100, connect_timeout = 100) self.__wait(5) #owner listeners as backup listener response2 = self.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, request_timeout = 100, connect_timeout = 100) self.assertEqual(StorageResponse.BAD_REQUEST, response1.code) self.assertEqual(StorageResponse.BAD_REQUEST, response2.code) self.__cleanup(owner_id, collection_name, subscriber_list) SharingSpaceStorage.get_instance().stop_cleanup_service()
def test_add_listener_invalid_sharing_secret(self): owner_id = self.account_id sharing_secret = 'XXXXXXXX' #add primary and secondary listeners sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret, 'Listen']) details = {'user_id': owner_id} json_str = json.dumps(details) headers, post_body = HTTPHelper.create_multipart_request_with_parameters({'details' : json_str}) #owner listens as primary listener response1 = self.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, request_timeout = 100, connect_timeout = 100) self.__wait(5) #owner listeners as backup listener response2 = self.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, request_timeout = 100, connect_timeout = 100) self.assertEqual(StorageResponse.NOT_FOUND, response1.code) self.assertEqual(StorageResponse.NOT_FOUND, response2.code) SharingSpaceStorage.get_instance().stop_cleanup_service()
def test_delete_listener(self): collection_name = 'share_api_col_name' + str(random.randint(0,100)) owner_id = self.account_id subscribers = [self.subscriber_id] sharing_secret, subscriber_list =\ self.__create_shared_collection(owner_id, subscribers, collection_name) #add primary and secondary listeners sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret, 'Listen']) sharing_space_url = self.get_url(sharing_space_url) details = {'user_id': owner_id} json_str = json.dumps(details) headers, post_body = HTTPHelper.create_multipart_request_with_parameters({'details' : json_str}) #owner listens as primary listener self.http_client.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, callback=self.primary_listener_returned, request_timeout = 100, connect_timeout = 100) self.__wait(5) #owner listeners as backup listener self.http_client.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, callback=self.backup_listener_returned, request_timeout = 100, connect_timeout = 100) self.__primary_listener_returned = False self.__backup_listener_returned = False self.__wait(5) remove_listener_url = '/'.join(['', 'SharingSpace', sharing_secret, 'Listen', owner_id]) headers, post_body = HTTPHelper.create_multipart_request_with_parameters({'details' : json_str}) #owner listens as primary listener response = self.fetch(remove_listener_url, method='DELETE', headers=headers, request_timeout = 100, connect_timeout = 100) self.assertEqual(StorageResponse.OK, response.code) self.__wait(10) self.assertTrue(self.__primary_listener_returned) self.assertTrue(self.__backup_listener_returned) self.__cleanup(owner_id, collection_name, subscriber_list) SharingSpaceStorage.get_instance().stop_cleanup_service()
def test_set_thumbnail(self): collection_name = 'collName' params = {'collectionName':collection_name} url = '/'+self.account_id + '/Collections' response = self.fetch(path=url, method='POST', body=urllib.urlencode(params)) self.assertEqual(200, response.code) thumbnail = open('../../test_resources/thumbnail.jpg') url += '/' + collection_name + '/Thumbnail' headers, post_data = HTTPHelper.create_multipart_request_with_single_file('file', thumbnail) response = self.fetch(path=url, headers=headers, method='POST', body=post_data) self.assertEqual(200, response.code) #cleanu url = '/'.join(['',self.account_id, 'Collections', collection_name]) self.fetch(path=url, method='DELETE')
def test_rename_collection(self): collection_name = 'collName1' params = {'collectionName':collection_name} url = '/'+self.account_id + '/Collections' response = self.fetch(path=url, method='POST', body=urllib.urlencode(params)) self.assertEqual(200, response.code) url = '/'.join(['',self.account_id, 'Collections', collection_name]) collection_name = 'newColName' params = {'collectionName':collection_name} headers, postData = HTTPHelper.create_multipart_request_with_parameters(params) response = self.fetch(path=url, headers=headers, method='PUT', body=postData) self.assertEquals(200, response.code) #cleanup url = '/'.join(['',self.account_id, 'Collections', collection_name]) self.fetch(path=url, method='DELETE')
def test_rename_shared_collection_by_owner(self): #initialize collection_name = 'fcolName' params = {'collectionName':collection_name} url = '/'+self.account_id + '/Collections' response = self.fetch(path=url, method='POST', body=urllib.urlencode(params)) self.assertEqual(200, response.code) url += "/" + collection_name + '/Share' response = self.fetch(path=url, method='POST', body="") json_obj = json.loads(response.body) sharing_secret = json_obj['sharing_secret'] self.assertEqual(200, response.code) subscription_url = '/'.join(['', self.subscriber_id, 'Collections','ShareSpaces', 'Subscribe']) headers, postData =\ HTTPHelper.create_multipart_request_with_parameters\ ({'sharing_secret': sharing_secret}) response = self.fetch(path=subscription_url, method='POST', headers=headers, body=postData) self.assertEqual(200, response.code) json_obj = json.loads(response.body) subscriber_collection_name = json_obj['collection_name'] #rename rename_collection_name = 'new_name' rename_url = '/'.join(['',self.account_id, 'Collections', collection_name]) params = {'collectionName':rename_collection_name} headers, postData = HTTPHelper.create_multipart_request_with_parameters(params) response = self.fetch(path=rename_url, headers=headers, method='PUT', body=postData) self.assertEquals(200, response.code) response = self.fetch(path=url, method='GET') self.assertEqual(404, response.code) url = '/'.join(['', self.account_id, 'Collections', rename_collection_name, 'Share']) print url response = self.fetch(path=url, method='GET') self.assertEqual(200, response.code) json_obj = json.loads(response.body) actual_collection_name = json_obj['collection_name'] self.assertEqual(rename_collection_name, actual_collection_name) #cleanup url = '/'.join(['',self.account_id, 'Collections', rename_collection_name]) self.fetch(path=url, method='DELETE') url = '/'.join(['',self.subscriber_id, 'Collections', subscriber_collection_name]) self.fetch(path=url, method='DELETE')
def test_save_manifest(self): collection_name = 'collName1' params = {'collectionName':collection_name} url = '/'+self.account_id + '/Collections' response = self.fetch(path=url, method='POST', body=urllib.urlencode(params)) self.assertEqual(200, response.code) url = '/'.join(['', self.account_id, 'Collections', collection_name]) collection_file = open('../../test_resources/collection.xml') headers, postData = HTTPHelper.create_multipart_request_with_single_file('file', collection_file) response = self.fetch(path=url, headers=headers, method='POST', body=postData) self.assertEquals(200, response.code) #cleanup url = '/'.join(['',self.account_id, 'Collections', collection_name]) self.fetch(path=url, method='DELETE')
def test_add_action_invalid_sharing_secret(self): collection_name = 'collection' + str(random.randint(0,100)) note_name = 'note' + str(random.randint(0,100)) json_str = self.__make_update_not_action(self.subscriber_id, collection_name, note_name) sharing_secret = 'XXXXXXXX' note_file = open('../../test_resources/XooML.xml') header, post_body = HTTPHelper.create_multipart_request_with_file_and_params({'action' : json_str}, 'file', note_file) sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret]) response = self.fetch(path=sharing_space_url, method = 'POST', headers=header, body=post_body) self.assertEqual(404, response.code)
def test_set_shared_thumbnail(self): #initialize collection_name = 'fcolName-shared-update_thumbnail' params = {'collectionName':collection_name} url = '/'+self.account_id + '/Collections' response = self.fetch(path=url, method='POST', body=urllib.urlencode(params)) self.assertEqual(200, response.code) url += "/" + collection_name + '/Share' response = self.fetch(path=url, method='POST', body="") json_obj = json.loads(response.body) sharing_secret = json_obj['sharing_secret'] self.assertEqual(200, response.code) #subscribe subscription_url = '/'.join(['', self.subscriber_id, 'Collections','ShareSpaces', 'Subscribe']) headers, postData =\ HTTPHelper.create_multipart_request_with_parameters\ ({'sharing_secret': sharing_secret}) response = self.fetch(path=subscription_url, method='POST', headers=headers, body=postData) self.assertEqual(200, response.code) json_obj = json.loads(response.body) subscriber_collection_name = json_obj['collection_name'] thumbnail = open('../../test_resources/thumbnail.jpg') url = '/'+self.account_id + '/Collections/' + collection_name + '/Thumbnail' headers, post_data = HTTPHelper.create_multipart_request_with_single_file('file', thumbnail) response = self.fetch(path=url, headers=headers, method='POST', body=post_data) self.assertEqual(200, response.code) try: self.wait(timeout=10) except Exception: pass #cleanup url = '/'.join(['',self.account_id, 'Collections', collection_name]) self.fetch(path=url, method='DELETE') url = '/'.join(['',self.subscriber_id, 'Collections', subscriber_collection_name]) self.fetch(path=url, method='DELETE')
def test_save_manifest_shared_collection(self): #initialize collection_name = 'fcolName-shared-update_manifest' params = {'collectionName':collection_name} url = '/'+self.account_id + '/Collections' response = self.fetch(path=url, method='POST', body=urllib.urlencode(params)) self.assertEqual(200, response.code) url += "/" + collection_name + '/Share' response = self.fetch(path=url, method='POST', body="") json_obj = json.loads(response.body) sharing_secret = json_obj['sharing_secret'] self.assertEqual(200, response.code) #subscribe subscription_url = '/'.join(['', self.subscriber_id, 'Collections','ShareSpaces', 'Subscribe']) headers, postData =\ HTTPHelper.create_multipart_request_with_parameters\ ({'sharing_secret': sharing_secret}) response = self.fetch(path=subscription_url, method='POST', headers=headers, body=postData) self.assertEqual(200, response.code) json_obj = json.loads(response.body) subscriber_collection_name = json_obj['collection_name'] url = '/'.join(['', self.subscriber_id, 'Collections', collection_name]) collection_file = open('../../test_resources/collection.xml') headers, postData = HTTPHelper.create_multipart_request_with_single_file('file', collection_file) response = self.fetch(path=url, headers=headers, method='POST', body=postData) self.assertEquals(200, response.code) #cleanup url = '/'.join(['',self.account_id, 'Collections', collection_name]) self.fetch(path=url, method='DELETE')
def test_add_listener(self): collection_name = 'share_api_col_name' + str(random.randint(0,100)) owner_id = self.account_id subscribers = [self.subscriber_id] sharing_secret, subscriber_list =\ self.__create_shared_collection(owner_id, subscribers, collection_name) #add primary and secondary listeners sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret, 'Listen']) sharing_space_url = self.get_url(sharing_space_url) details = {'user_id': owner_id} json_str = json.dumps(details) headers, post_body = HTTPHelper.create_multipart_request_with_parameters({'details' : json_str}) #owner listens as primary listener self.http_client.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, callback=self.primary_listener_returned, request_timeout = 100, connect_timeout = 100) self.__wait(5) #owner listeners as backup listener self.http_client.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, callback=self.backup_listener_returned, request_timeout = 100, connect_timeout = 100) self.__primary_listener_returned = False self.__backup_listener_returned = False #subscriber adds an action note_name = 'name' + str(random.randint(0,100)) note_img_file = open('../../test_resources/note_img.jpg') json_str = self.__make_update_note_img_action(self.subscriber_id, collection_name, note_name) header, post_body = HTTPHelper.create_multipart_request_with_file_and_params({'action' : json_str}, 'file', note_img_file) sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret]) response = self.fetch(path=sharing_space_url, method = 'POST', headers=header, body=post_body) self.__wait(10) self.assertEqual(200, response.code) self.assertTrue(self.__primary_listener_returned) #now the primary listener is returned so add another action for #backup listener to record note_name = 'name' + str(random.randint(0,100)) note_img_file = open('../../test_resources/note_img.jpg') json_str = self.__make_update_note_img_action(self.subscriber_id, collection_name, note_name) header, post_body = HTTPHelper.create_multipart_request_with_file_and_params({'action' : json_str}, 'file', note_img_file) sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret]) response = self.fetch(path=sharing_space_url, method = 'POST', headers=header, body=post_body) self.__wait(5) self.assertEqual(200, response.code) #now send back the primary listener sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret, 'Listen']) sharing_space_url = self.get_url(sharing_space_url) details = {'user_id': owner_id} json_str = json.dumps(details) headers, post_body = HTTPHelper.create_multipart_request_with_parameters({'details' : json_str}) #owner listens as primary listener self.http_client.fetch(sharing_space_url, method='POST', headers=headers, body=post_body, callback=self.primary_listener_returned, request_timeout = 100, connect_timeout = 100) self.__wait(5) self.assertTrue(self.__backup_listener_returned) self.__cleanup(owner_id, collection_name, subscriber_list) SharingSpaceStorage.get_instance().stop_cleanup_service()