Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
    def test_add_action_missing_file(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)

        header, post_body = HTTPHelper.create_multipart_request_with_parameters({'action':json_str})

        sharing_space_url = '/'.join(['', 'SharingSpace', sharing_secret])
        response = self.fetch(path=sharing_space_url, method = 'POST',
            headers=header, body=post_body)
        self.assertEqual(400, response.code)

        self.__wait(10)

        self.__cleanup(owner_id, collection_name, subscriber_list)
        SharingSpaceStorage.get_instance().stop_cleanup_service()
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
 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')
Exemplo n.º 8
0
    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')
Exemplo n.º 9
0
    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()