Ejemplo n.º 1
0
 def test_create(self):
     parser = configparser.ConfigParser()
     parser.read_string('''[section]
                        xpath=/valid
                        url=nourl
                        timeout=20''')
     check = XPath.create('name', parser['section'])
     assert check._xpath == '/valid'
Ejemplo n.º 2
0
    def test_not_matching(self, mocker):
        mock_reply = mocker.MagicMock()
        content_property = mocker.PropertyMock()
        type(mock_reply).content = content_property
        content_property.return_value = "<a></a>"
        mocker.patch('requests.Session.get', return_value=mock_reply)

        assert XPath('foo', xpath='/b', url='nourl', timeout=5).check(
            datetime.now(timezone.utc)) is None
Ejemplo n.º 3
0
    def test_not_a_number(self, mocker):
        mock_reply = mocker.MagicMock()
        content_property = mocker.PropertyMock()
        type(mock_reply).content = content_property
        content_property.return_value = '<a value="narf"></a>'
        mocker.patch('requests.Session.get', return_value=mock_reply)

        with pytest.raises(TemporaryCheckError):
            XPath('foo', xpath='/a/@value', url='nourl',
                  timeout=5).check(datetime.now(timezone.utc))
Ejemplo n.º 4
0
    def test_not_a_string(self, mocker) -> None:
        mock_reply = mocker.MagicMock()
        content_property = mocker.PropertyMock()
        type(mock_reply).content = content_property
        content_property.return_value = "<a></a>"
        mocker.patch("requests.Session.get", return_value=mock_reply)

        with pytest.raises(TemporaryCheckError):
            XPath("foo", xpath="/a", url="nourl", timeout=5).check(
                datetime.now(timezone.utc)
            )
Ejemplo n.º 5
0
 def test_create(self) -> None:
     parser = configparser.ConfigParser()
     parser.read_string(
         """
         [section]
         xpath=/valid
         url=nourl
         timeout=20
         """
     )
     check: XPath = XPath.create("name", parser["section"])  # type: ignore
     assert check._xpath == "/valid"
Ejemplo n.º 6
0
    def test_not_matching(self, mocker) -> None:
        mock_reply = mocker.MagicMock()
        content_property = mocker.PropertyMock()
        type(mock_reply).content = content_property
        content_property.return_value = "<a></a>"
        mocker.patch("requests.Session.get", return_value=mock_reply)

        assert (
            XPath("foo", xpath="/b", url="nourl", timeout=5).check(
                datetime.now(timezone.utc)
            )
            is None
        )
Ejemplo n.º 7
0
    def test_matching(self, mocker) -> None:
        mock_reply = mocker.MagicMock()
        content_property = mocker.PropertyMock()
        type(mock_reply).content = content_property
        content_property.return_value = '<a value="42.3"></a>'
        mock_method = mocker.patch("requests.Session.get", return_value=mock_reply)

        url = "nourl"
        assert XPath("foo", xpath="/a/@value", url=url, timeout=5).check(
            datetime.now(timezone.utc)
        ) == datetime.fromtimestamp(42.3, timezone.utc)

        mock_method.assert_called_once_with(url, timeout=5)
        content_property.assert_called_once_with()
Ejemplo n.º 8
0
    def test_multiple_min(self, mocker):
        mock_reply = mocker.MagicMock()
        content_property = mocker.PropertyMock()
        type(mock_reply).content = content_property
        content_property.return_value = '''<root>
    <a value="40"></a>
    <a value="10"></a>
    <a value="20"></a>
</root>
'''
        mocker.patch('requests.Session.get', return_value=mock_reply)

        assert XPath('foo', xpath='//a/@value', url='nourl', timeout=5).check(
            datetime.now(timezone.utc)) == datetime.fromtimestamp(
                10, timezone.utc)
Ejemplo n.º 9
0
    def test_multiple_min(self, mocker) -> None:
        mock_reply = mocker.MagicMock()
        content_property = mocker.PropertyMock()
        type(mock_reply).content = content_property
        content_property.return_value = """
            <root>
                <a value="40"></a>
                <a value="10"></a>
                <a value="20"></a>
            </root>
        """
        mocker.patch("requests.Session.get", return_value=mock_reply)

        assert XPath("foo", xpath="//a/@value", url="nourl", timeout=5).check(
            datetime.now(timezone.utc)
        ) == datetime.fromtimestamp(10, timezone.utc)
Ejemplo n.º 10
0
 def create_instance(self, name):
     return XPath(name, xpath="/a", url="nourl", timeout=5)
Ejemplo n.º 11
0
 def create_instance(self, name):
     return XPath(name, xpath='/a', url='nourl', timeout=5)