Example #1
0
    def test_get_sharing_space_invalid_secret(self):

        sharing_secret = '00000000'
        joker = JokerHelper.get_instance()
        joker.get_sharing_space_server(sharing_secret, callback=self.stop)
        server_adrs1 = self.wait(timeout=10000)
        self.assertTrue(server_adrs1 is None)
Example #2
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()
    def post(self, user_id, collection_name):

        self.__log.info('%s - SET: set collection img for %s for user %s' % (str(self.__class__), collection_name, user_id))

        collection_name = urllib2.unquote(collection_name)
        #if there is an actual file
        if len(self.request.files) > 0:
            file = self.request.files['file'][0]

            sharing_secret = yield gen.Task(SharingController.get_sharing_secret_from_subscriber_info,
                user_id, collection_name)
            if sharing_secret is None:
                #its not shared
                result_code = yield gen.Task(StorageServer.add_thumbnail, user_id, collection_name, file)
                self.set_status(result_code)
            else:
                #its shared
                joker_helper = JokerHelper.get_instance()
                sharing_server =\
                yield gen.Task(joker_helper.get_sharing_space_server, sharing_secret)
                if sharing_server is None:
                    #sharing server could not be found just update it locally
                    self.__log.info('Collection Thumbnail Handler - POST: sharing server not found for %s; performing updates locally' % sharing_secret)
                    result_code = yield gen.Task(StorageServer.add_thumbnail, user_id, collection_name, file)
                    self.set_status(result_code)
                else:
                    result_code = yield gen.Task(joker_helper.update_thumbnail, sharing_server,
                        sharing_secret, user_id, collection_name, file)
                    self.set_status(result_code)
            self.finish()
        else:
            self.set_status(StorageResponse.BAD_REQUEST)
            self.finish()
Example #4
0
    def post(self, user_id, collection_name, note_name):

        self.__log.info('%s - POST: save note img for note %s for collection %s for user %s' % (str(self.__class__), note_name, collection_name, user_id))

        collection_name = urllib2.unquote(collection_name)
        note_name = urllib2.unquote(note_name)
        if len(self.request.files) < 1:
            self.set_status(StorageResponse.BAD_REQUEST)
        else:
            note_img = self.request.files['file'][0]

            sharing_secret = yield gen.Task(SharingController.get_sharing_secret_from_subscriber_info,
                user_id, collection_name)
            if sharing_secret is None:
                #its not shared
                result_code = yield gen.Task(StorageServer.add_image_to_note,
                    user_id, collection_name, note_name, note_img)
                self.set_status(result_code)
            else:

                joker_helper = JokerHelper.get_instance()
                sharing_server =\
                yield gen.Task(joker_helper.get_sharing_space_server, sharing_secret)
                if sharing_server is None:
                    #sharing server could not be found just update it locally
                    self.__log.info('Note img Handler - POST: sharing server not found for %s; performing updates locally' % sharing_secret)
                    result_code = yield gen.Task(StorageServer.add_image_to_note,
                        user_id, collection_name, note_name, note_img)
                    self.set_status(result_code)
                else:
                    result_code = yield gen.Task(joker_helper.update_note_image, sharing_server,
                        sharing_secret, user_id, collection_name, note_name, note_img)
                    self.set_status(result_code)
        self.finish()
Example #5
0
    def delete(self, user_id, collection_name, note_name):

        self.__log.info('%s - DELETE: delete note %s for collection %s for user %s' % (str(self.__class__), note_name, collection_name, user_id))

        collection_name = urllib2.unquote(collection_name)
        note_name = urllib2.unquote(note_name)

        sharing_secret = yield gen.Task(SharingController.get_sharing_secret_from_subscriber_info,
            user_id, collection_name)
        if sharing_secret is None:
            #its not shared
            result_code = yield gen.Task(StorageServer.remove_note, user_id, collection_name, note_name)
            self.set_status(result_code)
        else:
            #its shared
            joker_helper = JokerHelper.get_instance()
            sharing_server =\
            yield gen.Task(joker_helper.get_sharing_space_server, sharing_secret)
            if sharing_server is None:
                self.__log.info('Note Handler - DELETE: sharing server not found for %s; performing updates locally' % sharing_secret)
                result_code = yield gen.Task(StorageServer.remove_note, user_id, collection_name, note_name)
                self.set_status(result_code)
            else:
                result_code = yield gen.Task(joker_helper.delete_note, sharing_server,
                    sharing_secret, user_id, collection_name, note_name)
                self.set_status(result_code)

        self.finish()
    def post(self, user_id, collection_name):

        self.__log.info(
            "%s - POST: Save note for collection %s for user %s" % (str(self.__class__), collection_name, user_id)
        )

        collection_name = urllib2.unquote(collection_name)
        note_file = None
        note_name = self.get_argument("noteName")
        # if there is an actual file
        if len(self.request.files) > 0:
            note_file = self.request.files["file"][0]

        sharing_secret = yield gen.Task(
            SharingController.get_sharing_secret_from_subscriber_info, user_id, collection_name
        )
        if sharing_secret is None:
            # its not shared
            result_code = yield gen.Task(
                StorageServer.add_note_to_collection, user_id, collection_name, note_name, note_file
            )
            self.set_status(result_code)
        else:
            if note_file is None:
                self.__log.info(
                    "Collection Note Handler - POST: updating shared note with no file for %s" % sharing_secret
                )
                self.set_status(StorageResponse.BAD_REQUEST)

            else:
                # Its shared go the the corresponding sharing space
                joker_helper = JokerHelper.get_instance()
                sharing_server = yield gen.Task(joker_helper.get_sharing_space_server, sharing_secret)
                if sharing_server is None:
                    # sharing server could not be found just update it locally
                    self.__log.info(
                        "Collection Note Handler - POST: sharing server not found for %s; performing updates locally"
                        % sharing_secret
                    )
                    result_code = yield gen.Task(
                        StorageServer.add_note_to_collection, user_id, collection_name, note_name, note_file
                    )
                    self.set_status(result_code)
                else:
                    result_code = yield gen.Task(
                        joker_helper.update_note,
                        sharing_server,
                        sharing_secret,
                        user_id,
                        collection_name,
                        note_name,
                        note_file,
                    )
                    self.set_status(result_code)
        self.finish()
Example #7
0
    def test_delete_note(self):

        collection_name = str(uuid.uuid4())
        subscriber_list = [self.__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_adrs = self.wait(timeout=10000)
        self.assertIn(server_adrs, Properties.sharing_space_servers)

        note_file = open('../test_resources/sharing_template1.xml')
        note_name = str(uuid.uuid4())
        joker.update_note(server_adrs, sharing_secret,
            self.__account_id, collection_name, note_name, note_file, callback=self.stop)
        result = self.wait(timeout=1000)
        self.assertEqual(StorageResponse.OK,result)

        #wait for a while
        self.__wait(10)

        #now delete
        joker.delete_note(server_adrs, sharing_secret, self.__account_id,
            collection_name, note_name, callback=self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        #wait for a while
        self.__wait(10)

        #Now Try to retreive the note
        StorageServer.get_note_from_collection(self.__account_id,
            collection_name, note_name, callback=self.stop)
        response = self.wait()
        self.assertTrue(response is None)

        #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()
Example #8
0
    def test_update_manifest(self):

        collection_name = str(uuid.uuid4())
        subscriber_list = [self.__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_adrs = self.wait(timeout=10000)
        self.assertIn(server_adrs, Properties.sharing_space_servers)

        manifest_file = open('../test_resources/sharing_template1.xml')
        expected_manifest_body = manifest_file.read()
        joker.update_manifest(server_adrs, sharing_secret, self.__account_id,
            collection_name, manifest_file, callback=self.stop)
        response = self.wait(timeout=1000)
        self.assertEqual(StorageResponse.OK, response)

        #wait for a while
        self.__wait(10)

        #try to retrieve the file
        StorageServer.get_collection_manifest(self.__account_id, collection_name,
            callback=self.stop)
        actual_manifest_file = self.wait()
        actual_manifest_body = actual_manifest_file.read()
        self.assertEqual(actual_manifest_body, expected_manifest_body)

        #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()
Example #9
0
    def post(self, user_id, collection_name):

        self.__log.info('%s - POST: post collection %s for user %s' % (str(self.__class__), collection_name, user_id))

        collection_name = urllib2.unquote(collection_name)
        if len(self.request.files) > 0:
            collection_file = self.request.files['file'][0]

            sharing_secret = yield gen.Task(SharingController.get_sharing_secret_from_subscriber_info,
                user_id, collection_name)

            if sharing_secret is None:
                #Its not shared
                result_code = yield gen.Task(StorageServer.
                save_collection_manifest, user_id, collection_name, collection_file)
                self.set_status(result_code)
            else:
                #Its shared it has to go to the corresponding sharing space
                #first figure out the sharing space server
                joker_helper = JokerHelper.get_instance()
                sharing_server = \
                    yield gen.Task(joker_helper.get_sharing_space_server, sharing_secret)
                if sharing_server is None:
                    #sharing server could not be found just update it locally
                    self.__log.info('Collection Handler - POST: sharing server not found for %s; performing updates locally' % sharing_secret)

                    result_code = yield gen.Task(StorageServer.
                        save_collection_manifest, user_id, collection_name, collection_file)
                    self.set_status(result_code)
                else:
                    result_code = yield gen.Task(joker_helper.update_manifest,
                        sharing_server, sharing_secret, user_id, collection_name,
                        collection_file)
                    self.set_status(result_code)
            self.finish()

        else:
            self.set_status(StorageResponse.BAD_REQUEST)
        self.finish()
Example #10
0
    def test_update_thumbnail(self):

        collection_name = str(uuid.uuid4())
        subscriber_list = [self.__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_adrs = self.wait(timeout=10000)
        self.assertIn(server_adrs, Properties.sharing_space_servers)

        thumbnail_file = open('../test_resources/note_img.jpg')
        joker.update_thumbnail(server_adrs, sharing_secret, self.__account_id,
            collection_name, thumbnail_file, callback=self.stop)
        response = self.wait()
        self.assertEqual(StorageResponse.OK, response)

        #wait for a while
        self.__wait(10)

        #try to retreive the thumbnail
        StorageServer.get_thumbnail(self.__account_id, collection_name,
            callback=self.stop)
        response = self.wait()
        self.assertTrue(response is not None)

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