Exemplo n.º 1
0
 def test_collect_invalid_timeout(self):
     with pytest.raises(ConfigurationError,
                        match=r"^Configuration error .*"):
         parser = configparser.ConfigParser()
         parser.read_string('''[section]
                            url=nourl
                            timeout=xx''')
         NetworkMixin.collect_init_args(parser['section'])
Exemplo n.º 2
0
 def test_password_missing(self) -> None:
     with pytest.raises(ConfigurationError, match=r"^Username and.*"):
         parser = configparser.ConfigParser()
         parser.read_string(
             """
             [section]
             url=ok
             username=xxx
             """
         )
         NetworkMixin.collect_init_args(parser["section"])
Exemplo n.º 3
0
 def test_collect_timeout(self):
     parser = configparser.ConfigParser()
     parser.read_string('''[section]
                        url=nourl
                        timeout=42''')
     args = NetworkMixin.collect_init_args(parser['section'])
     assert args['timeout'] == 42
Exemplo n.º 4
0
 def test_invalid_authentication(self, datadir, serve_protected) -> None:
     with pytest.raises(TemporaryCheckError):
         NetworkMixin(
             serve_protected(datadir / "data.txt")[0],
             5,
             username="******",
             password="******",
         ).request()
Exemplo n.º 5
0
 def test_collect_default_timeout(self) -> None:
     parser = configparser.ConfigParser()
     parser.read_string(
         """
         [section]
         url=nourl
         """
     )
     args = NetworkMixin.collect_init_args(parser["section"])
     assert args["timeout"] == 5
Exemplo n.º 6
0
 def test_collect_missing_url(self) -> None:
     with pytest.raises(ConfigurationError, match=r"^Lacks 'url'.*"):
         parser = configparser.ConfigParser()
         parser.read_string("[section]")
         NetworkMixin.collect_init_args(parser["section"])
Exemplo n.º 7
0
 def test_file_url(self) -> None:
     NetworkMixin("file://" + __file__, 5).request()
Exemplo n.º 8
0
 def test_authentication(self, datadir, serve_protected) -> None:
     url, username, password = serve_protected(datadir / "data.txt")
     NetworkMixin(url, 5, username=username, password=password).request()
Exemplo n.º 9
0
 def test_exception_404(self, httpserver) -> None:
     with pytest.raises(TemporaryCheckError):
         NetworkMixin(httpserver.url_for("/does/not/exist"), timeout=5).request()
Exemplo n.º 10
0
 def test_smoke(self, datadir, serve_file) -> None:
     response = NetworkMixin(serve_file(datadir / "data.txt"), timeout=5).request()
     assert response is not None
     assert response.text == "iamhere\n"
Exemplo n.º 11
0
 def test_request(self, datadir, serve_file) -> None:
     reply = NetworkMixin(
         serve_file(datadir / "xml_with_encoding.xml"), 5,
     ).request()
     assert reply is not None
     assert reply.status_code == 200
Exemplo n.º 12
0
 def test_invalid_authentication(self, stub_auth_server):
     with pytest.raises(TemporaryCheckError):
         NetworkMixin(stub_auth_server.resource_address('data.txt'),
                      5, username='******', password='******').request()
Exemplo n.º 13
0
 def test_authentication(self, stub_auth_server):
     NetworkMixin(stub_auth_server.resource_address('data.txt'),
                  5, username='******', password='******').request()
Exemplo n.º 14
0
 def test_exception_404(self, stub_server):
     with pytest.raises(TemporaryCheckError):
         NetworkMixin(stub_server.resource_address('doesnotexist'),
                      timeout=5).request()
Exemplo n.º 15
0
 def test_smoke(self, stub_server):
     response = NetworkMixin(stub_server.resource_address('data.txt'),
                             timeout=5).request()
     assert response is not None
     assert response.text == 'iamhere\n'
Exemplo n.º 16
0
 def test_request(self, stub_server):
     address = stub_server.resource_address('xml_with_encoding.xml')
     reply = NetworkMixin(address, 5).request()
     assert reply is not None
     assert reply.status_code == 200
Exemplo n.º 17
0
    def test_requests_exception(self, mocker) -> None:
        with pytest.raises(TemporaryCheckError):
            mock_method = mocker.patch("requests.Session.get")
            mock_method.side_effect = requests.exceptions.ReadTimeout()

            NetworkMixin("url", timeout=5).request()
Exemplo n.º 18
0
 def test_file_url(self):
     NetworkMixin('file://' + __file__, 5).request()