Пример #1
0
    def test_get_content_from_site_internal_server_error(self):
        soupMock = Mock()
        server.BeautifulSoup = Mock()
        server.BeautifulSoup.return_value = soupMock
        soupMock.find.return_value = None

        with patch("server.requests.get") as patched_get:
            type(patched_get.return_value).ok = PropertyMock(return_value=True)
            with pytest.raises(InternalServerError):
                server._get_content_from_site("randomURL")
Пример #2
0
    def test_get_content_from_site_not_found_error(self, mock_req):
        app = Flask(__name__)
        client = app.test_client()
        server.configure_routes(app)
        url = "/get-node-info/leafs"

        mock_page = mock_req.get(url)
        mock_page.ok = False

        with pytest.raises(NotFound):
            server._get_content_from_site(url)
Пример #3
0
    def test_get_content_from_site_internal_server_error(
            self, mock_bs, mock_req):
        app = Flask(__name__)
        client = app.test_client()
        server.configure_routes(app)
        url = "/get-node-info/leafs"

        mock_page = mock_req.get(url)
        mock_page.ok = True

        mock_bs.side_effect = InternalServerError()
        with pytest.raises(InternalServerError):
            server._get_content_from_site(url)
Пример #4
0
    def test_get_content_from_site_no_error(self):
        contentMock = Mock()
        contentMock.find.return_value = None
        contentMock.findAll.return_value = []

        soupMock = Mock()
        server.BeautifulSoup = Mock()
        server.BeautifulSoup.return_value = soupMock
        soupMock.find.return_value = contentMock

        with patch("server.requests.get") as patched_get:
            type(patched_get.return_value).ok = PropertyMock(return_value=True)
            assert (server._get_content_from_site("randomURL") !=
                    "mock_get_content_from_site_return_value")
Пример #5
0
 def test_get_content_from_site_not_found_error(self):
     with patch("server.requests.get") as patched_get:
         type(
             patched_get.return_value).ok = PropertyMock(return_value=False)
         with pytest.raises(NotFound):
             server._get_content_from_site("randomURL")