def test_created_related_actions_multiple_subscribers(self):

        collection_name = "sharing_collection"
        subscribers = [self.__subscriber_id, self.__second_subscriber]
        sharing_secret = self.__create_sharing_record(subscribers, collection_name)
        subscribers.append(self.__account_id)

        file = open("../test_resources/XooML.xml")
        manifest_action = UpdateSharedManifestAction(self.__account_id, collection_name, file)
        SharingActionFactory.create_related_sharing_actions(sharing_secret, manifest_action, callback=self.stop)
        sharing_action_list = self.wait()

        self.assertEqual(3, len(sharing_action_list))

        for sharing_action in sharing_action_list:
            user_id = sharing_action.get_user_id()
            self.assertTrue(user_id in subscribers)
            subscribers.remove(user_id)
            self.assertEqual(SharingEvent.UPDATE_MANIFEST, sharing_action.get_action_type())
        self.assertEqual(0, len(subscribers))

        # cleanup
        SharingController.remove_sharing_record_by_secret(sharing_secret, callback=self.stop)
        self.wait()
        for sharing_action in sharing_action_list:
            user_id = sharing_action.get_user_id()
            collection_name = sharing_action.get_collection_name()
            StorageServer.remove_collection(user_id, collection_name, callback=self.stop)
            self.wait()
    def test_create_related_actions_delete_note(self):

        collection_name = "sharing_collection"
        subscribers = [self.__subscriber_id]
        sharing_secret = self.__create_sharing_record(subscribers, collection_name)
        subscribers.append(self.__account_id)

        note_name = "lala note"
        delete_action = DeleteSharedNoteAction(self.__account_id, collection_name, note_name)

        SharingActionFactory.create_related_sharing_actions(sharing_secret, delete_action, callback=self.stop)
        sharing_action_list = self.wait()

        self.assertEqual(2, len(sharing_action_list))

        for sharing_action in sharing_action_list:
            user_id = sharing_action.get_user_id()
            actual_note_name = sharing_action.get_note_name()
            note_file = sharing_action.get_associated_file()
            self.assertTrue(note_file is None)
            self.assertEqual(note_name, actual_note_name)
            self.assertTrue(user_id in subscribers)
            subscribers.remove(user_id)
            self.assertEqual(SharingEvent.DELETE_NOTE, sharing_action.get_action_type())
        self.assertEqual(0, len(subscribers))

        # cleanup
        SharingController.remove_sharing_record_by_secret(sharing_secret, callback=self.stop)
        self.wait()
        for sharing_action in sharing_action_list:
            user_id = sharing_action.get_user_id()
            collection_name = sharing_action.get_collection_name()
            StorageServer.remove_collection(user_id, collection_name, callback=self.stop)
            self.wait()
    def test_create_related_actions_update_thumbnail(self):

        collection_name = "sharing_collection"
        subscribers = [self.__subscriber_id]
        sharing_secret = self.__create_sharing_record(subscribers, collection_name)
        subscribers.append(self.__account_id)

        file = open("../test_resources/XooML.xml")
        thumbnail_action = UpdateSharedThumbnailAction(self.__account_id, collection_name, file)
        SharingActionFactory.create_related_sharing_actions(sharing_secret, thumbnail_action, callback=self.stop)
        sharing_action_list = self.wait()

        self.assertEqual(2, len(sharing_action_list))

        for sharing_action in sharing_action_list:
            user_id = sharing_action.get_user_id()
            thumbnail_file = sharing_action.get_associated_file()
            self.assertTrue(thumbnail_file is not None)
            self.assertTrue(user_id in subscribers)
            subscribers.remove(user_id)
            self.assertEqual(SharingEvent.UPDATE_THUMBNAIL, sharing_action.get_action_type())
        self.assertEqual(0, len(subscribers))

        # cleanup
        SharingController.remove_sharing_record_by_secret(sharing_secret, callback=self.stop)
        self.wait()
        for sharing_action in sharing_action_list:
            user_id = sharing_action.get_user_id()
            collection_name = sharing_action.get_collection_name()
            StorageServer.remove_collection(user_id, collection_name, callback=self.stop)
            self.wait()
    def test_create_related_actions_update_note_img(self):

        collection_name = "sharing_collection"
        subscribers = [self.__subscriber_id]
        sharing_secret = self.__create_sharing_record(subscribers, collection_name)
        subscribers.append(self.__account_id)

        note_name = "lala_note"
        file = open("../test_resources/XooML.xml")
        note_img_action = UpdateSharedNoteImageAction(self.__account_id, collection_name, note_name, file)
        SharingActionFactory.create_related_sharing_actions(sharing_secret, note_img_action, callback=self.stop)
        sharing_action_list = self.wait()

        self.assertEqual(2, len(sharing_action_list))

        for sharing_action in sharing_action_list:
            user_id = sharing_action.get_user_id()
            actual_note_name = sharing_action.get_note_name()
            self.assertEqual(note_name, actual_note_name)
            self.assertTrue(user_id in subscribers)
            subscribers.remove(user_id)
            self.assertEqual(SharingEvent.UPDATE_NOTE_IMG, sharing_action.get_action_type())
        self.assertEqual(0, len(subscribers))

        # cleanup
        SharingController.remove_sharing_record_by_secret(sharing_secret, callback=self.stop)
        self.wait()
        for sharing_action in sharing_action_list:
            user_id = sharing_action.get_user_id()
            collection_name = sharing_action.get_collection_name()
            StorageServer.remove_collection(user_id, collection_name, callback=self.stop)
            self.wait()
    def test_create_related_actions_invalid_sharing_secret(self):

        collection_name = "dummy"
        file = open("../test_resources/XooML.xml")
        manifest_action = UpdateSharedManifestAction(self.__account_id, collection_name, file)
        SharingActionFactory.create_related_sharing_actions("dummy", manifest_action, callback=self.stop)
        sharing_action_list = self.wait()
        self.assertTrue(sharing_action_list is None)