Exemplo n.º 1
0
def test_base_route():
    app = Flask(__name__)
    client = app.test_client()
    server.configure_routes(app)
    url = "/"

    response = client.get(url)
    print(response.get_data())
    assert response.get_data() == b"Hello World!"
    assert response.status_code == 200
Exemplo n.º 2
0
    def test_get_tree_by_id_db_returns_system_error(self):
        app = Flask(__name__)
        client = app.test_client()
        server.configure_routes(app)
        url = "/get-tree-by-id/1"

        server.db_interface.get_tree_by_id = Mock()
        server.db_interface.get_tree_by_id.side_effect = SystemError(
            Mock(status=500), "System Error")
        response = client.get(url)
        assert response.status_code == 500
Exemplo n.º 3
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)
Exemplo n.º 4
0
    def test_get_tree_by_id_exists(self):
        app = Flask(__name__)
        client = app.test_client()
        server.configure_routes(app)
        url = "/get-tree-by-id/1"

        fake_tree = {"children": []}
        server.db_interface.get_tree_by_id = Mock()
        server.db_interface.get_tree_by_id.return_value = fake_tree
        response = client.get(url)
        assert response.status_code == 200
        assert response.json == fake_tree
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def test_get_node_info_exists(self):
        app = Flask(__name__)
        client = app.test_client()
        server.configure_routes(app)
        url = "/get-node-info/maple-leafs"

        server._get_content_from_site = Mock()
        server._get_content_from_site.return_value = (
            "mock_get_content_from_site_return_value")

        response = client.get(url)
        assert response.status_code == 200
        assert response.json == {
            "content": "mock_get_content_from_site_return_value"
        }