示例#1
0
 def test_creds_are_pulled_from_secret(self, monkeypatch):
     task = RedisSet()
     redis = MagicMock()
     monkeypatch.setattr("prefect.tasks.redis.redis_tasks.redis.Redis", redis)
     with set_temporary_config({"cloud.use_local_secrets": True}):
         with prefect.context(secrets=dict(REDIS_PASSWORD="******")):
             task.run(redis_key="foo", redis_val="bar")
     assert redis.call_args[1]["password"] == 42
示例#2
0
 def test_redis_params_passed_to_connection(self, monkeypatch):
     redis_params = {"custom_parameter": "value"}
     task = RedisSet(redis_connection_params=redis_params)
     redis = MagicMock()
     monkeypatch.setattr("prefect.tasks.redis.redis_tasks.redis.Redis", redis)
     with set_temporary_config({"cloud.use_local_secrets": True}):
         with prefect.context(secrets=dict(REDIS_PASSWORD="******")):
             task.run(redis_key="foo", redis_val="bar")
     assert redis.call_args[1]["custom_parameter"] == "value"
示例#3
0
    def test_raises_key_val_not_provided(self):
        task = RedisSet()

        ## raises if neither provided
        with pytest.raises(ValueError) as exc:
            task.run()
        assert "redis_key and redis_val must be provided" == str(exc.value)

        ## raises if only one arg is missing
        with pytest.raises(ValueError) as exc:
            task.run(redis_key="foo")
        assert "redis_key and redis_val must be provided" == str(exc.value)
        with pytest.raises(ValueError) as exc:
            task.run(redis_val="bar")
        assert "redis_key and redis_val must be provided" == str(exc.value)
示例#4
0
    def test_raises_key_val_not_provided(self):
        task = RedisSet()

        ## raises if neither provided
        with pytest.raises(ValueError,
                           match="redis_key and redis_val must be provided"):
            task.run()

        ## raises if only one arg is missing
        with pytest.raises(ValueError,
                           match="redis_key and redis_val must be provided"):
            task.run(redis_key="foo")
        with pytest.raises(ValueError,
                           match="redis_key and redis_val must be provided"):
            task.run(redis_val="bar")
示例#5
0
 def test_construction(self):
     task = RedisSet()
     assert task.host == "localhost"