コード例 #1
0
    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()
コード例 #2
0
    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()
コード例 #3
0
    def test_get_sharing_space_info_existing(self):

        servers = ['a', 'b', 'c']
        Properties.sharing_space_servers = servers
        collection_name = str(uuid.uuid4())
        subscriber_list = [self.__subscriber_id, self.__second_subscriber_id]
        sharing_secret, subscribers_collections =\
        self.__create_sharing_record(subscriber_list, collection_name)
        load_balancer = SharingLoadBalancer.get_instance()
        load_balancer.get_sharing_space_info(sharing_secret, callback=self.stop)
        server_info = self.wait()
        server_adrs = server_info['server']
        self.assertTrue(server_adrs in servers)

        load_balancer.get_sharing_space_info(sharing_secret, callback=self.stop)
        second_server_info = self.wait()
        second_server_adrs = second_server_info['server']
        self.assertEqual(server_adrs, second_server_adrs)

        #cleanup
        SharingController.remove_sharing_record_by_secret(sharing_secret, callback =self.stop)
        self.wait()
        StorageServer.remove_collection(self.__account_id, collection_name,
            callback=self.stop)
        for subscriber_id in subscribers_collections:
            subscriber_collection = subscribers_collections[subscriber_id]
            StorageServer.remove_collection(subscriber_id, subscriber_collection,
                callback=self.stop)
            self.wait()
コード例 #4
0
    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()
コード例 #5
0
    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()
コード例 #6
0
    def test_reshare_already_shared_collection(self):

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

        # create sharing record
        SharingController.create_sharing_record(self.__account_id, first_collection_name, callback=self.stop)
        sharing_secret = self.wait()
        self.assertTrue(sharing_secret is not None)

        # duplicate create sharing record
        SharingController.create_sharing_record(self.__account_id, first_collection_name, callback=self.stop)
        new_sharing_secret = self.wait()
        self.assertEqual(sharing_secret, new_sharing_secret)

        # verify that only one sharing record was added
        SharingController.get_sharing_record_by_owner_info(self.__account_id, first_collection_name, callback=self.stop)
        sharing_record = self.wait()
        subscribers_list = sharing_record.get_subscribers()
        self.assertEqual(1, len(subscribers_list))

        # cleanup
        SharingController.remove_sharing_record_by_secret(sharing_secret, callback=self.stop)
        self.wait()
        StorageServer.remove_collection(self.__account_id, first_collection_name, callback=self.stop)
        self.wait()
コード例 #7
0
    def test_get_sharing_space_server_existing(self):

        collection_name = str(uuid.uuid4())
        subscriber_list = [self.__subscriber_id, self.__second_subscriber_id]
        sharing_secret, subscribers_collections =\
        self.__create_sharing_record(subscriber_list, collection_name)

        joker = JokerHelper.get_instance()
        joker.get_sharing_space_server(sharing_secret, callback=self.stop)
        server_adrs1 = self.wait(timeout=10000)
        self.assertIn(server_adrs1, Properties.sharing_space_servers)
        print server_adrs1


        joker.get_sharing_space_server(sharing_secret, callback=self.stop)
        server_adrs2 = self.wait(timeout=10000)
        self.assertIn(server_adrs2, Properties.sharing_space_servers)
        self.assertEqual(server_adrs1, server_adrs2)
        print server_adrs2

        #cleanup
        SharingController.remove_sharing_record_by_secret(sharing_secret, callback =self.stop)
        self.wait()
        StorageServer.remove_collection(self.__account_id, collection_name,
            callback=self.stop)
        for subscriber_id in subscribers_collections:
            subscriber_collection = subscribers_collections[subscriber_id]
            StorageServer.remove_collection(subscriber_id, subscriber_collection,
                callback=self.stop)
            self.wait()
コード例 #8
0
    def test_remove_non_existing_note(self):

        collection_name = "dummy"
        note_name = "dummy"
        StorageServer.remove_note(self.__account_id, collection_name, note_name, callback=self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.NOT_FOUND, response)
コード例 #9
0
    def test_remove_all_subscribers(self):

        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)

        SharingController.create_sharing_record(self.__account_id, collection_name, callback=self.stop)
        sharing_secret = self.wait()

        SharingController.subscribe_to_sharing_space(self.__subscriber_id, sharing_secret, callback=self.stop)
        collection_name2 = self.wait(timeout=500)

        SharingController.remove_all_subscribers(sharing_secret, callback=self.stop)
        self.wait(timeout=10000)

        # busy wait for the results of remove all subscribers to become consistent
        try:
            self.wait(timeout=5)
        except Exception:
            pass

        SharingController.get_sharing_secret_from_subscriber_info(
            self.__account_id, collection_name, callback=self.stop
        )
        actual_sharing_secret = self.wait()
        self.assertTrue(actual_sharing_secret is None)
        SharingController.get_sharing_secret_from_subscriber_info("second_user", collection_name2, callback=self.stop)
        actual_sharing_secret = self.wait()
        self.assertTrue(actual_sharing_secret is None)
コード例 #10
0
    def __create_collection(self, account_id, collection_name):

        file = open('../test_resources/XooML.xml')
        StorageServer.add_collection(user_id= account_id,
            collection_name=collection_name, callback=self.stop, file= file)
        response = self.wait(timeout=100)
        self.assertEqual(StorageResponse.OK, response)
コード例 #11
0
    def test_copy_collections_between_accounts_different_name(self):

        first_collection_name = str(uuid.uuid1())
        file = open("../test_resources/XooML.xml")
        StorageServer.add_collection(
            user_id=self.__account_id, collection_name=first_collection_name, callback=self.stop, file=file
        )
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        second_collection_name = str(uuid.uuid1())
        StorageServer.copy_collection_between_accounts(
            self.__account_id,
            self.__second_account_id,
            first_collection_name,
            second_collection_name,
            callback=self.stop,
        )
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        StorageServer.list_collections(self.__second_account_id, callback=self.stop)
        col_list = self.wait()
        self.assertTrue(second_collection_name in col_list)
        # cleanup
        StorageServer.remove_collection(self.__account_id, first_collection_name, callback=self.stop)
        self.wait()
        StorageServer.remove_collection(self.__second_account_id, second_collection_name, callback=self.stop)
        self.wait()
コード例 #12
0
 def test_copy_non_existing_collection_to_another_account(self):
     collection_name = str(uuid.uuid1())
     StorageServer.copy_collection_between_accounts(
         self.__account_id, self.__second_account_id, collection_name, collection_name, callback=self.stop
     )
     response = self.wait()
     self.assertEqual(StorageResponse.NOT_FOUND, response)
コード例 #13
0
    def test_double_deleting_shared_note(self):

        note_name = 'note_name'
        collection_name = 'collection_name'
        #update note
        note_file = open('../test_resources/note2.xml')
        update_note_action = UpdateSharedNoteAction(self.__account_id, collection_name,
            note_name, note_file)
        update_note_action.execute(callback=self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        delete_action = DeleteSharedNoteAction(self.__account_id,
            collection_name, note_name)
        delete_action.execute(callback=self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        delete_action2 = DeleteSharedNoteAction(self.__account_id,
            collection_name, note_name)
        delete_action2.execute(callback=self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.NOT_FOUND, response)

        #cleanup
        StorageServer.remove_collection(self.__account_id, collection_name,
            callback=self.stop)
        self.wait()
コード例 #14
0
    def __create_sharing_record(self, subscriber_list, collection_name):

        #create 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)

        #create sharing record
        SharingController.create_sharing_record(self.__account_id,
            collection_name, callback = self.stop)
        sharing_secret = self.wait(timeout=10000)
        self.assertTrue(sharing_secret is not None)

        subscribers = {}
        for subscriber_id in subscriber_list:
            #subscribe
            SharingController.subscribe_to_sharing_space(subscriber_id,
                sharing_secret, callback = self.stop)
            subscribers_collection_name  = self.wait()
            self.assertTrue(subscribers_collection_name is not None)
            subscribers[subscriber_id] = subscribers_collection_name

        return sharing_secret, subscribers
コード例 #15
0
    def test_get_non_existing_note(self):

        collection_name = "col_name"
        note_name = "noteName"
        StorageServer.get_note_from_collection(self.__account_id, collection_name, note_name, callback=self.stop)
        response = self.wait()
        self.assertTrue(response is None)
コード例 #16
0
 def test_save_categories(self):
     collection_file = open("../test_resources/categories.xml")
     StorageServer.save_categories(self.__account_id, collection_file, callback=self.stop)
     response = self.wait()
     self.assertEqual(StorageResponse.OK, response)
     # clean up
     StorageServer.remove_categories(self.__account_id, callback=self.stop)
     self.wait()
コード例 #17
0
    def test_get_categories_without_existing_categories(self):
        StorageServer.get_categories(self.__account_id, callback=self.stop)
        response = self.wait()
        self.assertTrue(response is not None)

        # clean up
        StorageServer.remove_categories(self.__account_id, callback=self.stop)
        self.wait()
コード例 #18
0
 def test_add_thumbnail_invalid_collection(self):
     thumbnail = open("../test_resources/thumbnail.jpg")
     StorageServer.add_thumbnail(self.__account_id, "dummy", thumbnail, callback=self.stop)
     response = self.wait()
     # Accepted
     self.assertEqual(StorageResponse.OK, response)
     StorageServer.remove_collection(self.__account_id, "dummy", callback=self.stop)
     self.wait()
コード例 #19
0
 def test_remove_collection_with_no_file(self):
     collection_name = str(uuid.uuid1())
     StorageServer.add_collection(self.__account_id, collection_name, callback=self.stop)
     response = self.wait()
     self.assertEqual(StorageResponse.OK, response)
     StorageServer.remove_collection(self.__account_id, collection_name, callback=self.stop)
     response = self.wait()
     self.assertEqual(StorageResponse.OK, response)
コード例 #20
0
 def test_remove_collection_with_file(self):
     collection_name = str(uuid.uuid1())
     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(timeout=10)
     self.assertEqual(StorageResponse.OK, response)
     StorageServer.remove_collection(self.__account_id, collection_name, callback=self.stop)
     response = self.wait()
     self.assertEqual(StorageResponse.OK, response)
コード例 #21
0
    def test_add_note_img_to_invalid_collection(self):

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

        # clean up
        StorageServer.remove_collection(self.__account_id, "dummy", callback=self.stop)
        self.wait()
コード例 #22
0
    def test_save_collection_manifest_invalid_collection(self):

        collection_name = "non_existing"
        collection_file = open("../test_resources/collection.xml")
        StorageServer.save_collection_manifest(self.__account_id, collection_name, collection_file, callback=self.stop)
        response = self.wait()
        # Accepted
        self.assertEqual(StorageResponse.OK, response)
        # clean up
        StorageServer.remove_collection(self.__account_id, collection_name, callback=self.stop)
        self.wait()
コード例 #23
0
    def test_add_note_to_collection_no_file(self):

        collection_name = "col_name"
        note_name = "noteName"
        StorageServer.add_note_to_collection(
            self.__account_id, collection_name, note_name, note_file=None, callback=self.stop
        )
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)
        # clean up
        StorageServer.remove_collection(self.__account_id, collection_name, callback=self.stop)
        self.wait()
コード例 #24
0
    def test_find_best_collection_name_with_one_existing_collection(self):
        collection_name = "name"
        StorageServer.add_collection(self.__account_id, collection_name, callback=self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        StorageUtils.find_best_collection_name_for_user(collection_name, self.__account_id, callback=self.stop)
        new_name = self.wait()
        expected_new_name = collection_name + StorageUtils.SHARING_POSTFIX
        self.assertEqual(expected_new_name, new_name)

        # cleanup
        StorageServer.remove_collection(self.__account_id, collection_name, callback=self.stop)
        self.wait()
コード例 #25
0
    def test_add_note_to_non_existing_collection(self):

        collection_name = "col_name"
        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()
        # Accepted
        self.assertEqual(StorageResponse.OK, response)
        # clean up
        StorageServer.remove_collection(self.__account_id, collection_name, callback=self.stop)
        self.wait()
コード例 #26
0
    def test_update_sharing_manifest_non_existing_manifest(self):

        collection_name = 'collection_name'
        #update manifest
        file = open('../test_resources/XooML2.xml')
        update_manifest_action = UpdateSharedManifestAction(self.__account_id,
            collection_name, file)
        update_manifest_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()
コード例 #27
0
    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()
コード例 #28
0
    def test_update_same_note_repeatedly(self):

        note_name = 'note_name'
        collection_name = 'collection_name'
        #update note
        note_file = open('../test_resources/note2.xml')
        update_note_action = UpdateSharedNoteAction(self.__account_id, collection_name,
            note_name, note_file)
        for x in range(1,5):
            update_note_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()
コード例 #29
0
    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()
コード例 #30
0
 def __get_collection_manifest_content(self, account_id, collection_name):
     StorageServer.get_collection_manifest(account_id,
         collection_name, callback=self.stop)
     response = self.wait(timeout=100)
     if response is None:
         print 'GOT NONE; retrying'
         try:
             self.wait(timeout=10)
         except Exception:
             pass
         StorageServer.get_collection_manifest(account_id,
             collection_name, callback=self.stop)
         response = self.wait(timeout=100)
         if response is None:
             print 'Still None, failing'
             return None
         else:
             return response.read()
     else:
         return response.read()