def test_update_note_img_non_existing_img(self):

        collection_name = 'collection_name'
        note_name = 'note_name'
        #update note image
        img_file2 = open('../test_resources/note_img2.jpg')
        update_not_img_action = UpdateSharedNoteImageAction(self.__account_id, collection_name,
            note_name, img_file2)
        update_not_img_action.execute(callback=self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        #cleanup
        StorageServer.remove_collection(self.__account_id, collection_name,
            callback=self.stop)
        self.wait()
    def test_update_different_note_imgs_repeatedly(self):

        collection_name = 'collection_name'
        note_name = 'note_name'
        #update note image
        for x in range(1,5):

            img_file2 = open('../test_resources/note_img2.jpg')
            note_name += str(x)
            update_not_img_action = UpdateSharedNoteImageAction(self.__account_id, collection_name,
                note_name, img_file2)
            update_not_img_action.execute(callback=self.stop)
            response = self.wait()
            self.assertEqual(StorageResponse.OK, response)

        #cleanup
        StorageServer.remove_collection(self.__account_id, collection_name,
            callback=self.stop)
        self.wait()
    def test_update_note_img(self):

        #create collection
        collection_name = 'shareable_collection'
        file = open('../test_resources/XooML.xml')
        StorageServer.add_collection(user_id=self.__account_id,
            collection_name=collection_name, callback=self.stop, file= file)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        #add note
        note_name = "noteName"
        note_file = open('../test_resources/note.xml')
        StorageServer.add_note_to_collection(self.__account_id,
            collection_name, note_name, note_file, callback = self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        #add note image
        img_file = open('../test_resources/note_img.jpg')
        StorageServer.add_image_to_note(self.__account_id, collection_name,
            note_name, img_file, callback= self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        #update note image
        img_file2 = open('../test_resources/note_img2.jpg')
        update_not_img_action = UpdateSharedNoteImageAction(self.__account_id, collection_name,
            note_name, img_file2)
        update_not_img_action.execute(callback=self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        #cleanup
        StorageServer.remove_collection(self.__account_id, collection_name,
            callback=self.stop)
        self.wait()
    def __load_test(self, sharing_space, manifest_count, note_count, busy_wait_cycle, acceptable_invalids):

        self.__load_finished = False
        collection_name1 = 'sharing_col1'
        collection_name2 = 'sharing_col2'
        self.__create_collection(self.__account_id, collection_name1)
        self.__create_collection(self.__subscriber_id, collection_name2)

        action_list = []
        sharing_template_file = open('../test_resources/sharing_template1.xml')
        sharing_template_str = sharing_template_file.read()
        manifest_str_list = MockFactory.get_list_of_different_strings(manifest_count,
            sharing_template_str)
        counter = 0
        last_manifest = None

        for x in range(manifest_count):
            for manifest_str in manifest_str_list:
                last_manifest = manifest_str + str(x)
                manifest_file1 = cStringIO.StringIO(last_manifest)
                manifest_file2 = cStringIO.StringIO(last_manifest)
                name = str(counter)
                counter += 1
                action1 = UpdateSharedManifestAction(self.__account_id,
                    collection_name1, manifest_file1)
                action1.name = 'user1-manifest-' + name
                action2 = UpdateSharedManifestAction(self.__subscriber_id,
                    collection_name2, manifest_file2)
                action2.name = 'user2-manifest-' + name
                action_list.append(action1)
                action_list.append(action2)

        #add some notes and images
        note_str_list = MockFactory.get_list_of_different_strings(note_count,
            sharing_template_str)
        file_name_counter = 0
        note_names = []
        for note_str in note_str_list :
            note_name = 'note' + str(file_name_counter)
            file_name_counter += 1
            note_names.append(note_name)
            file_obj1 = cStringIO.StringIO(note_str)
            file_obj2 = cStringIO.StringIO(note_str)
            action1 = UpdateSharedNoteAction(self.__account_id,
                collection_name1, note_name, file_obj1)
            action1.name = 'user1-update-note-' + note_name
            action2 = UpdateSharedNoteAction(self.__subscriber_id,
                collection_name2, note_name, file_obj2)
            action2.name = 'user2-update-note-' + note_name
            action_list.append(action1)
            action_list.append(action2)
            img_file1 = open('../test_resources/sharing_note_img1.jpg', 'rb')
            img_file_like1 = cStringIO.StringIO(img_file1.read())
            img_file2 = open('../test_resources/sharing_note_img2.jpg', 'rb')
            img_file_like2 = cStringIO.StringIO(img_file2.read())
            action3 = UpdateSharedNoteImageAction(self.__account_id,
                collection_name1, note_name, img_file_like1)
            action3.name = 'user1-update-img-' + note_name
            action4 = UpdateSharedNoteImageAction(self.__subscriber_id,
                collection_name2, note_name, img_file_like2)
            action4.name = 'user2-update-img-' + note_name
            action_list.append(action3)
            action_list.append(action4)

        for action in action_list:
            sharing_space.add_action(action)

        #cleanup
        self.__remove_collection(self.__account_id, collection_name1)
        self.__remove_collection(self.__subscriber_id, collection_name2)