Esempio n. 1
0
def test_update__update_then_get() -> None:
    resolution_a = Resolution.make(value="")
    resolution_b = Resolution.make(value="")
    cache = make_cache()
    cache.update(("alpha", ), resolution=resolution_a)
    cache.update(("alpha", ), resolution=resolution_b)
    assert len(cache.resolutions) == 1
    assert cache.get(("alpha", )) == resolution_b
Esempio n. 2
0
 def resolve(self, support: ResolutionSupport) -> Resolution:
     if self.raises_cannot_resolve_error:
         raise CannotResolveError("cannot reticulate splines")
     return Resolution.make(
         value=self.return_value,
         expires_at=self.return_expires_at,
     )
Esempio n. 3
0
 def resolve(self, support: ResolutionSupport) -> Resolution:
     return Resolution.make(
         value=Authoriser(
             domain=self.domain,
             account=self.account,
             profile=self.profile,
             region=self.region,
         ).token,
         expires_at=datetime.now() + timedelta(seconds=self.duration),
     )
Esempio n. 4
0
def test_write_then_read(cache_path: Path, logger: Logger) -> None:
    resolution = Resolution.make(value="bar")
    writer = make_cache(logger=logger, path=cache_path)
    writer.update(("foo", ), resolution=resolution)
    writer.save()

    reader = make_cache(path=cache_path)
    reader.load()
    assert len(reader.resolutions) == 1
    assert reader.get(("foo", )) == resolution
Esempio n. 5
0
    def resolve(self, support: ResolutionSupport) -> Resolution:
        """
        Resolves the environment variable.

        Args:
            logger: Logger. Do not log confidential information.

        Returns:
            Resolution.
        """
        value = (self.value if isinstance(self.value, str) else
                 self.separator.join(self.value))
        return Resolution.make(
            value=value,
            expires_at=datetime.now() + timedelta(seconds=60),
        )
Esempio n. 6
0
    with patch("wev.resolver.get_plugin", return_value=plugin) as patched:
        yield patched


@fixture
def get_plugin_cannot_resolve_error() -> Iterator[PluginBase]:
    plugin = MockPlugin({}, raises_cannot_resolve_error=True)
    with patch("wev.resolver.get_plugin", return_value=plugin) as patched:
        yield patched


@mark.parametrize(
    "resolution, expect",
    [
        (None, False),
        (Resolution.make(value=""), False),
        (
            Resolution.make(
                value=None, expires_at=datetime.now() - timedelta(seconds=60)
            ),
            False,
        ),
        (
            Resolution.make(
                value=None, expires_at=datetime.now() + timedelta(seconds=60)
            ),
            True,
        ),
    ],
)
def test_fresh_resolution(resolution: Optional[Resolution], expect: bool) -> None: