示例#1
0
async def reset():
    storage = BlobStorage(BLOB_STORAGE_SETTINGS)
    try:
        await storage.client.delete_container(
            container_name=BLOB_STORAGE_SETTINGS.container_name)
    except Exception:
        pass
示例#2
0
    async def test_blob_storage_write_should_add_new_value(self):
        storage = BlobStorage(BLOB_STORAGE_SETTINGS)
        await storage.write({"user": SimpleStoreItem(counter=1)})

        data = await storage.read(["user"])
        assert "user" in data
        assert data["user"].counter == "1"
示例#3
0
    async def test_blob_storage_write_should_overwrite_when_new_e_tag_is_an_asterisk(
            self):
        storage = BlobStorage(BLOB_STORAGE_SETTINGS)
        await storage.write({"user": SimpleStoreItem()})

        await storage.write({"user": SimpleStoreItem(counter=10, e_tag="*")})
        data = await storage.read(["user"])
        assert data["user"].counter == "10"
示例#4
0
    async def test_blob_storage_read_should_return_data_with_valid_key(self):
        storage = BlobStorage(BLOB_STORAGE_SETTINGS)
        await storage.write({"user": SimpleStoreItem()})

        data = await storage.read(["user"])
        assert "user" in data
        assert data["user"].counter == "1"
        assert len(data.keys()) == 1
示例#5
0
    async def test_blob_storage_delete_invalid_keys_should_do_nothing_and_not_affect_cached_data(
            self):
        storage = BlobStorage(BLOB_STORAGE_SETTINGS)
        await storage.write({"test": SimpleStoreItem()})

        await storage.delete(["foo", "bar"])
        data = await storage.read(["test"])
        assert len(data.keys()) == 1
示例#6
0
 async def test_blob_storage_read_update_should_return_new_etag(self):
     storage = BlobStorage(BLOB_STORAGE_SETTINGS)
     await storage.write({"test": SimpleStoreItem(counter=1)})
     data_result = await storage.read(["test"])
     data_result["test"].counter = 2
     await storage.write(data_result)
     data_updated = await storage.read(["test"])
     assert data_updated["test"].counter == "2"
     assert data_updated["test"].e_tag != data_result["test"].e_tag
    async def test_blob_storage_delete_should_delete_multiple_values_when_given_multiple_valid_keys(
        self,
    ):
        storage = BlobStorage(BLOB_STORAGE_SETTINGS)
        await storage.write({"test": SimpleStoreItem(), "test2": SimpleStoreItem(2)})

        await storage.delete(["test", "test2"])
        data = await storage.read(["test", "test2"])
        assert not data.keys()
示例#8
0
    async def test_blob_storage_delete_should_delete_values_when_given_multiple_valid_keys_and_ignore_other_data(
            self):
        storage = BlobStorage(BLOB_STORAGE_SETTINGS)
        await storage.write({
            "test": SimpleStoreItem(),
            "test2": SimpleStoreItem(counter=2),
            "test3": SimpleStoreItem(counter=3),
        })

        await storage.delete(["test", "test2"])
        data = await storage.read(["test", "test2", "test3"])
        assert len(data.keys()) == 1
    async def test_blob_storage_delete_should_delete_according_cached_data(self):
        storage = BlobStorage(BLOB_STORAGE_SETTINGS)
        await storage.write({"test": SimpleStoreItem()})
        try:
            await storage.delete(["test"])
        except Exception as error:
            raise error
        else:
            data = await storage.read(["test"])

            assert isinstance(data, dict)
            assert not data.keys()
示例#10
0
 async def test_blob_storage_write_batch_operation(self):
     storage = BlobStorage(BLOB_STORAGE_SETTINGS)
     await storage.write({
         "batch1": SimpleStoreItem(counter=1),
         "batch2": SimpleStoreItem(counter=1),
         "batch3": SimpleStoreItem(counter=1),
     })
     data = await storage.read(["batch1", "batch2", "batch3"])
     assert len(data.keys()) == 3
     assert data["batch1"]
     assert data["batch2"]
     assert data["batch3"]
     assert data["batch1"].counter == "1"
     assert data["batch2"].counter == "1"
     assert data["batch3"].counter == "1"
     assert data["batch1"].e_tag
     assert data["batch2"].e_tag
     assert data["batch3"].e_tag
     await storage.delete(["batch1", "batch2", "batch3"])
     data = await storage.read(["batch1", "batch2", "batch3"])
     assert not data.keys()
示例#11
0
    def __init__(self, conversation_state: ConversationState, user_state: UserState, configuration: DefaultConfig):
        if conversation_state is None:
            raise TypeError(
                "[MyBot]: Missing parameter. conversation_state is required but None was given"
            )
        if user_state is None:
            raise TypeError("[MyBot]: Missing parameter. user_state is required but None was given"
                            )
        self.conversation_state = conversation_state
        self.user_state = user_state
        self.user_state_accessor = self.user_state.create_property("WelcomeUserState")
        self.conversation_data_accessor = self.conversation_state.create_property(
            "ConversationData"
        )
        self.user_profile_accessor = self.user_state.create_property("UserProfile")
        self.WELCOME_MESSAGE = """Welcome to your favorite Dairy bot"""

        blob_settings = BlobStorageSettings(
            container_name='EnterContainerName',
            connection_string="EnterConnectionString"
        )
        self.storage = BlobStorage(blob_settings)
        self._recognizer = None

        luis_is_configured = (
                configuration.LUIS_APP_ID
                and configuration.LUIS_API_KEY
                and configuration.LUIS_API_HOST_NAME
        )
        if luis_is_configured:
            # Set the recognizer options depending on which endpoint version you want to use e.g v2 or v3.
            # More details can be found in https://docs.microsoft.com/azure/cognitive-services/luis/luis-migration-api-v3
            luis_application = LuisApplication(
                configuration.LUIS_APP_ID,
                configuration.LUIS_API_KEY,
                "https://" + configuration.LUIS_API_HOST_NAME,
            )

            self._recognizer = LuisRecognizer(luis_application)
示例#12
0
 async def test_blob_storage_read_no_key_should_throw(self):
     try:
         storage = BlobStorage(BLOB_STORAGE_SETTINGS)
         await storage.read([])
     except Exception as error:
         assert error
示例#13
0
 async def test_blob_storage_init_should_error_without_cosmos_db_config(
         self):
     try:
         BlobStorage(BlobStorageSettings())  # pylint: disable=no-value-for-parameter
     except Exception as error:
         assert error
示例#14
0
def get_storage():
    return BlobStorage(BLOB_STORAGE_SETTINGS)