1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00
gns3-server/tests/handlers/api/controller/test_shape.py

88 lines
2.9 KiB
Python
Raw Normal View History

2016-06-20 16:45:31 +00:00
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
This test suite check /project endpoint
"""
import uuid
import os
import asyncio
import aiohttp
import pytest
from tests.utils import asyncio_patch
from gns3server.handlers.api.controller.project_handler import ProjectHandler
from gns3server.controller import Controller
2016-06-21 07:49:16 +00:00
from gns3server.controller.shape import Shape
2016-06-20 16:45:31 +00:00
@pytest.fixture
def project(http_controller, async_run):
return async_run(Controller.instance().add_project())
2016-06-21 07:49:16 +00:00
def test_create_shape(http_controller, tmpdir, project, async_run):
2016-06-20 16:45:31 +00:00
2016-06-21 07:49:16 +00:00
response = http_controller.post("/projects/{}/shapes".format(project.id), {
2016-06-20 16:45:31 +00:00
"svg": '<svg height="210" width="500"><line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2" /></svg>',
"x": 10,
"y": 20,
"z": 0
}, example=True)
assert response.status == 201
2016-06-21 07:49:16 +00:00
assert response.json["shape_id"] is not None
2016-06-20 16:45:31 +00:00
2016-06-21 07:49:16 +00:00
def test_update_shape(http_controller, tmpdir, project, async_run):
2016-06-20 16:45:31 +00:00
2016-06-21 07:49:16 +00:00
response = http_controller.post("/projects/{}/shapes".format(project.id), {
2016-06-20 16:45:31 +00:00
"svg": '<svg height="210" width="500"><line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2" /></svg>',
"x": 10,
"y": 20,
"z": 0
},)
2016-06-21 07:49:16 +00:00
response = http_controller.put("/projects/{}/shapes/{}".format(project.id, response.json["shape_id"]), {
2016-06-20 16:45:31 +00:00
"x": 42,
}, example=True)
assert response.status == 201
assert response.json["x"] == 42
2016-06-21 07:49:16 +00:00
def test_list_shape(http_controller, tmpdir, project, async_run):
response = http_controller.post("/projects/{}/shapes".format(project.id), {
2016-06-20 16:45:31 +00:00
"svg": '<svg height="210" width="500"><line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2" /></svg>',
"x": 10,
"y": 20,
"z": 0
}, example=False)
2016-06-21 07:49:16 +00:00
response = http_controller.get("/projects/{}/shapes".format(project.id), example=True)
2016-06-20 16:45:31 +00:00
assert response.status == 200
assert len(response.json) == 1
2016-06-21 07:49:16 +00:00
def test_delete_shape(http_controller, tmpdir, project, async_run):
2016-06-20 16:45:31 +00:00
2016-06-21 07:49:16 +00:00
shape = Shape(project)
project._shapes = {shape.id: shape}
response = http_controller.delete("/projects/{}/shapes/{}".format(project.id, shape.id), example=True)
2016-06-20 16:45:31 +00:00
assert response.status == 204
2016-06-21 07:49:16 +00:00
assert shape.id not in project._shapes