예제 #1
0
 def test_simplified_literal_str(self) -> None:
     """Test simplified literal str."""
     assert (VariableValueConcatenation([VariableValueLiteral("foo")
                                         ]).simplified.value == "foo")
     assert (VariableValueConcatenation(
         [VariableValueLiteral("foo"),
          VariableValueLiteral("bar")]).simplified.value == "foobar")
예제 #2
0
 def test_init_find_handler_unknown_lookup_type(self) -> None:
     """Test __init__ fund handler UnknownLookupType."""
     with pytest.raises(UnknownLookupType):
         VariableValueLookup(
             VariableValueLiteral("invalid"),
             VariableValueLiteral("query"),
         )
예제 #3
0
 def test_init_find_handler_value_error(self) -> None:
     """Test __init__ fund handler ValueError."""
     with pytest.raises(ValueError):
         VariableValueLookup(
             VariableValueLiteral("test"),
             VariableValueLiteral("query"),
             variable_type="invalid",  # type: ignore
         )
예제 #4
0
 def test_simplified_concat(self) -> None:
     """Test simplified concatenation."""
     assert (VariableValueConcatenation([
         VariableValueLiteral("foo"),
         VariableValueConcatenation(
             [VariableValueLiteral("bar"),
              VariableValueLiteral("foo")]),
     ]).simplified.value == "foobarfoo")
예제 #5
0
 def test_init_find_handler_runway(self, mocker: MockerFixture) -> None:
     """Test __init__ find handler runway."""
     mocker.patch.dict(RUNWAY_LOOKUP_HANDLERS, {"test": "success"})
     obj = VariableValueLookup(
         VariableValueLiteral("test"),
         VariableValueLiteral("query"),
         variable_type="runway",
     )
     assert obj.handler == "success"
예제 #6
0
 def test_init(self) -> None:
     """Test __init__."""
     name = VariableValueLiteral("test")
     query = VariableValueLiteral("query")
     obj = VariableValueLookup(name, query, MockLookupHandler, "runway")
     assert obj.handler == MockLookupHandler
     assert obj.lookup_name == name
     assert obj.lookup_query == query
     assert obj.variable_type == "runway"
예제 #7
0
 def test_resolve_exception(self, mocker: MockerFixture) -> None:
     """Test resolve raise Exception."""
     mocker.patch.object(MockLookupHandler, "handle", side_effect=Exception)
     obj = VariableValueLookup(VariableValueLiteral("test"), "query")
     with pytest.raises(FailedLookup) as excinfo:
         obj.resolve(MagicMock(), MagicMock())
     assert isinstance(excinfo.value.cause, Exception)
     assert excinfo.value.lookup == obj
예제 #8
0
 def test_dependencies(self, mocker: MockerFixture) -> None:
     """Test dependencies."""
     mocker.patch.object(MockLookupHandler,
                         "dependencies",
                         return_value={"test"})
     obj = VariableValueLookup(VariableValueLiteral("test"), "query",
                               MockLookupHandler)
     assert obj.dependencies == {"test"}
예제 #9
0
 def test_value(self) -> None:
     """Test value."""
     obj = VariableValueLookup(VariableValueLiteral("test"), "query")
     assert obj.resolved is False
     with pytest.raises(UnresolvedVariableValue):
         obj.value  # pylint: disable=pointless-statement
     obj._resolve("success")
     assert obj.resolved is True
     assert obj.value == "success"
예제 #10
0
    def test_dependencies_no_attr(self) -> None:
        """Test dependencies class has no attr."""
        class FakeLookup:
            """Fake lookup."""

        obj = VariableValueLookup(
            VariableValueLiteral("test"),
            "query",
            FakeLookup  # type: ignore
        )
        assert obj.dependencies == set()
예제 #11
0
 def test_resolve(self, mocker: MockerFixture) -> None:
     """Test resolve."""
     kwargs = {
         "context": MagicMock(),
         "provider": MagicMock(),
         "variables": MagicMock(),
         "kwarg": "something",
     }
     mock_handle = mocker.patch.object(MockLookupHandler,
                                       "handle",
                                       return_value="resolved")
     mock_resolve = mocker.patch.object(VariableValueLookup,
                                        "_resolve",
                                        return_value=None)
     mock_resolve_query = mocker.patch.object(VariableValueLiteral,
                                              "resolve")
     obj = VariableValueLookup(VariableValueLiteral("test"),
                               VariableValueLiteral("query"))
     assert not obj.resolve(**kwargs)  # type: ignore
     mock_resolve_query.assert_called_once_with(**kwargs)
     mock_handle.assert_called_once_with("query", **kwargs)
     mock_resolve.assert_called_once_with("resolved")
예제 #12
0
 def test_value_multiple(self) -> None:
     """Test multiple."""
     assert (VariableValueConcatenation(
         [VariableValueLiteral("foo"),
          VariableValueLiteral("bar")]).value == "foobar")
     assert (VariableValueConcatenation(
         [VariableValueLiteral(13),
          VariableValueLiteral("/test")]  # type: ignore
     ).value == "13/test")
     assert (VariableValueConcatenation(
         [VariableValueLiteral(5),
          VariableValueLiteral(13)]).value == "513")
     with pytest.raises(InvalidLookupConcatenation):
         VariableValueConcatenation(
             [VariableValueLiteral(True),
              VariableValueLiteral("test")]  # type: ignore
         ).value
예제 #13
0
 def test_resolve(self, cfngin_context: MockCFNginContext,
                  mocker: MockerFixture) -> None:
     """Test resolve."""
     mock_provider = MagicMock()
     mock_resolve = mocker.patch.object(VariableValueLiteral,
                                        "resolve",
                                        return_value=None)
     obj = VariableValueConcatenation([VariableValueLiteral("val0")])
     assert not obj.resolve(
         cfngin_context,
         provider=mock_provider,
         variables={"var": "something"},  # type: ignore
         kwarg="test",
     )
     mock_resolve.assert_called_once_with(
         cfngin_context,
         provider=mock_provider,
         variables={"var": "something"},
         kwarg="test",
     )
예제 #14
0
 def test_repr(self, value: Union[int, str]) -> None:
     """Test __repr__."""
     obj = VariableValueLiteral(value)  # type: ignore
     assert repr(obj) == f"Literal[{value}]"  # type: ignore
예제 #15
0
 def test_simplified(self) -> None:
     """Test simplified."""
     obj = VariableValueLookup(VariableValueLiteral("test"), "query")
     assert obj.simplified == obj
예제 #16
0
 def test_resolved(self) -> None:
     """Test resolved."""
     obj = VariableValueLookup(VariableValueLiteral("test"), "query")
     assert obj.resolved is False
     obj._resolved = True
     assert obj.resolved is True
예제 #17
0
 def test_simplified_literal_bool(self) -> None:
     """Test simplified literal bool."""
     assert (VariableValueConcatenation([VariableValueLiteral(True)
                                         ]).simplified.value is True)
     assert (VariableValueConcatenation([VariableValueLiteral(False)
                                         ]).simplified.value is False)
예제 #18
0
 def test_iter(self) -> None:
     """Test __iter__."""
     obj = VariableValueLookup(VariableValueLiteral("test"), "query")
     assert list(iter(obj)) == [obj]
예제 #19
0
 def test_repr(self) -> None:
     """Test __repr__."""
     obj = VariableValueLookup(VariableValueLiteral("test"), "query")
     assert repr(obj) == "Lookup[Literal[test] Literal[query]]"
     obj._resolve("resolved")
     assert repr(obj) == "Lookup[resolved (Literal[test] Literal[query])]"
예제 #20
0
 def test_simplified_literal_int(self) -> None:
     """Test simplified literal int."""
     assert (VariableValueConcatenation([VariableValueLiteral(13)
                                         ]).simplified.value == 13)
예제 #21
0
 def test_resolved(self, value: Union[int, str]) -> None:
     """Test resolved."""
     obj = VariableValueLiteral(value)  # type: ignore
     assert obj.resolved
예제 #22
0
 def test_value_single(self) -> None:
     """Test value single."""
     assert VariableValueConcatenation([VariableValueLiteral("foo")
                                        ]).value == "foo"
     assert VariableValueConcatenation([VariableValueLiteral(13)
                                        ]).value == 13
예제 #23
0
 def test_iter(self, value: Union[int, str]) -> None:
     """Test __iter__."""
     obj = VariableValueLiteral(value)  # type: ignore
     assert list(iter(obj)) == [obj]  # type: ignore
예제 #24
0
 def test_init_find_handler_cfngin(self, mocker: MockerFixture) -> None:
     """Test __init__ find handler cfngin."""
     mocker.patch.dict(CFNGIN_LOOKUP_HANDLERS, {"test": "success"})
     obj = VariableValueLookup(VariableValueLiteral("test"),
                               VariableValueLiteral("query"))
     assert obj.handler == "success"
예제 #25
0
 def test_init_convert_query(self) -> None:
     """Test __init__ convert query."""
     obj = VariableValueLookup(VariableValueLiteral("test"), "query",
                               MockLookupHandler, "runway")
     assert isinstance(obj.lookup_query, VariableValueLiteral)
     assert obj.lookup_query.value == "query"
예제 #26
0
 def test_insert(self) -> None:
     """Test insert."""
     obj = VariableValueList(["val0", "val1"])
     obj.insert(1, VariableValueLiteral("val2"))
     assert [i.value for i in obj] == ["val0", "val2", "val1"]
예제 #27
0
 def test_str(self) -> None:
     """Test __str__."""
     assert (str(VariableValueLookup(VariableValueLiteral("test"),
                                     "query")) == "${test query}")
예제 #28
0
 def test_simplified_literal_empty(self) -> None:
     """Test simplified literal empty."""
     assert (VariableValueConcatenation([VariableValueLiteral("")
                                         ]).simplified.value == "")
예제 #29
0
 def test_init(self, value: Union[int, str]) -> None:
     """Test __init__."""
     obj = VariableValueLiteral(value)  # type: ignore
     assert obj._data == value
예제 #30
0
 def test_value(self, value: Union[int, str]) -> None:
     """Test value."""
     obj = VariableValueLiteral(value)  # type: ignore
     assert obj.value == value