mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
The server has now 2 notification streams
* A new one for controller related events (compute, appliance templates etc.) * The existing one for project related events (links, nodes etc.)
This commit is contained in:
1 parent
dac3ba19b7
commit
7f72b90b0e
364 files changed
+12364
-9923
No files matched your search
@@ -111,7 +111,7 @@ def test_compute_httpQueryNotConnected(compute, controller, async_run):
|
||||
mock.assert_any_call("POST", "https://example.com:84/v2/compute/projects", data=b'{"a": "b"}', headers={'content-type': 'application/json'}, auth=None, chunked=None, timeout=20)
|
||||
assert compute._connected
|
||||
assert compute._capabilities["version"] == __version__
|
||||
controller.notification.emit.assert_called_with("compute.updated", compute.__json__())
|
||||
controller.notification.controller_emit.assert_called_with("compute.updated", compute.__json__())
|
||||
|
||||
|
||||
def test_compute_httpQueryNotConnectedGNS3vmNotRunning(compute, controller, async_run):
|
||||
@@ -135,7 +135,7 @@ def test_compute_httpQueryNotConnectedGNS3vmNotRunning(compute, controller, asyn
|
||||
assert controller.gns3vm.start.called
|
||||
assert compute._connected
|
||||
assert compute._capabilities["version"] == __version__
|
||||
controller.notification.emit.assert_called_with("compute.updated", compute.__json__())
|
||||
controller.notification.controller_emit.assert_called_with("compute.updated", compute.__json__())
|
||||
|
||||
|
||||
def test_compute_httpQueryNotConnectedInvalidVersion(compute, async_run):
|
||||
@@ -259,7 +259,7 @@ def test_connectNotificationPing(compute, async_run):
|
||||
async_run(compute._connect_notification())
|
||||
|
||||
assert not compute._controller.notification.dispatch.called
|
||||
args, _ = compute._controller.notification.emit.call_args_list[0]
|
||||
args, _ = compute._controller.notification.controller_emit.call_args_list[0]
|
||||
assert args[0] == "compute.updated"
|
||||
assert args[1]["memory_usage_percent"] == 80.7
|
||||
assert args[1]["cpu_usage_percent"] == 35.7
|
||||
@@ -322,7 +322,7 @@ def test_update(compute, controller, async_run):
|
||||
async_run(compute.update(name="Test 2"))
|
||||
assert compute.name == "Test 2"
|
||||
assert compute.host == "example.org"
|
||||
controller.notification.emit.assert_called_with("compute.updated", compute.__json__())
|
||||
controller.notification.controller_emit.assert_called_with("compute.updated", compute.__json__())
|
||||
assert compute.connected is False
|
||||
assert compute._controller.save.called
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ def test_import_remote_gns3vm_1_x(controller, controller_config_path, async_run)
|
||||
def test_settings(controller):
|
||||
controller._notification = MagicMock()
|
||||
controller.settings = {"a": 1}
|
||||
controller._notification.emit.assert_called_with("settings.updated", controller.settings)
|
||||
controller._notification.controller_emit.assert_called_with("settings.updated", controller.settings)
|
||||
assert controller.settings["modification_uuid"] is not None
|
||||
|
||||
|
||||
@@ -220,10 +220,10 @@ def test_load_projects(controller, projects_dir, async_run):
|
||||
def test_add_compute(controller, controller_config_path, async_run):
|
||||
controller._notification = MagicMock()
|
||||
c = async_run(controller.add_compute(compute_id="test1", connect=False))
|
||||
controller._notification.emit.assert_called_with("compute.created", c.__json__())
|
||||
controller._notification.controller_emit.assert_called_with("compute.created", c.__json__())
|
||||
assert len(controller.computes) == 1
|
||||
async_run(controller.add_compute(compute_id="test1", connect=False))
|
||||
controller._notification.emit.assert_called_with("compute.updated", c.__json__())
|
||||
controller._notification.controller_emit.assert_called_with("compute.updated", c.__json__())
|
||||
assert len(controller.computes) == 1
|
||||
async_run(controller.add_compute(compute_id="test2", connect=False))
|
||||
assert len(controller.computes) == 2
|
||||
@@ -244,7 +244,7 @@ def test_deleteCompute(controller, controller_config_path, async_run):
|
||||
c._connected = True
|
||||
async_run(controller.delete_compute("test1"))
|
||||
assert len(controller.computes) == 0
|
||||
controller._notification.emit.assert_called_with("compute.deleted", c.__json__())
|
||||
controller._notification.controller_emit.assert_called_with("compute.deleted", c.__json__())
|
||||
with open(controller_config_path) as f:
|
||||
data = json.load(f)
|
||||
assert len(data["computes"]) == 0
|
||||
@@ -271,7 +271,7 @@ def test_deleteComputeProjectOpened(controller, controller_config_path, async_ru
|
||||
c._connected = True
|
||||
async_run(controller.delete_compute("test1"))
|
||||
assert len(controller.computes) == 0
|
||||
controller._notification.emit.assert_called_with("compute.deleted", c.__json__())
|
||||
controller._notification.controller_emit.assert_called_with("compute.deleted", c.__json__())
|
||||
with open(controller_config_path) as f:
|
||||
data = json.load(f)
|
||||
assert len(data["computes"]) == 0
|
||||
|
||||
@@ -75,7 +75,7 @@ def test_update(drawing, project, async_run, controller):
|
||||
|
||||
async_run(drawing.update(x=42, svg="<svg><rect></rect></svg>"))
|
||||
assert drawing.x == 42
|
||||
args, kwargs = controller._notification.emit.call_args
|
||||
args, kwargs = controller._notification.project_emit.call_args
|
||||
assert args[0] == "drawing.updated"
|
||||
# JSON
|
||||
assert args[1]["x"] == 42
|
||||
@@ -83,7 +83,7 @@ def test_update(drawing, project, async_run, controller):
|
||||
|
||||
async_run(drawing.update(x=12, svg="<svg><rect></rect></svg>"))
|
||||
assert drawing.x == 12
|
||||
args, kwargs = controller._notification.emit.call_args
|
||||
args, kwargs = controller._notification.project_emit.call_args
|
||||
assert args[0] == "drawing.updated"
|
||||
# JSON
|
||||
assert args[1]["x"] == 12
|
||||
|
||||
@@ -68,7 +68,7 @@ def test_add_node(async_run, project, compute):
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
link._project.controller.notification.emit = MagicMock()
|
||||
link._project.controller.notification.project_emit = MagicMock()
|
||||
project.dump = AsyncioMagicMock()
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
assert link._nodes == [
|
||||
@@ -87,7 +87,7 @@ def test_add_node(async_run, project, compute):
|
||||
}
|
||||
]
|
||||
assert project.dump.called
|
||||
assert not link._project.controller.notification.emit.called
|
||||
assert not link._project.controller.notification.project_emit.called
|
||||
|
||||
assert not link.create.called
|
||||
|
||||
@@ -97,7 +97,7 @@ def test_add_node(async_run, project, compute):
|
||||
async_run(link.add_node(node2, 0, 4))
|
||||
|
||||
assert link.create.called
|
||||
link._project.controller.notification.emit.assert_called_with("link.created", link.__json__())
|
||||
link._project.controller.notification.project_emit.assert_called_with("link.created", link.__json__())
|
||||
assert link in node2.links
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ def test_add_node_already_connected(async_run, project, compute):
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
link._project.controller.notification.emit = MagicMock()
|
||||
link._project.controller.notification.project_emit = MagicMock()
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
node2 = Node(project, compute, "node2", node_type="qemu")
|
||||
node2._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
@@ -133,7 +133,7 @@ def test_add_node_cloud(async_run, project, compute):
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
link._project.controller.notification.emit = MagicMock()
|
||||
link._project.controller.notification.project_emit = MagicMock()
|
||||
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
async_run(link.add_node(node2, 0, 4))
|
||||
@@ -150,7 +150,7 @@ def test_add_node_cloud_to_cloud(async_run, project, compute):
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
link._project.controller.notification.emit = MagicMock()
|
||||
link._project.controller.notification.project_emit = MagicMock()
|
||||
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||
@@ -166,7 +166,7 @@ def test_add_node_same_node(async_run, project, compute):
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
link._project.controller.notification.emit = MagicMock()
|
||||
link._project.controller.notification.project_emit = MagicMock()
|
||||
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||
@@ -184,7 +184,7 @@ def test_add_node_serial_to_ethernet(async_run, project, compute):
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
link._project.controller.notification.emit = MagicMock()
|
||||
link._project.controller.notification.project_emit = MagicMock()
|
||||
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||
@@ -323,7 +323,7 @@ def test_start_capture(link, async_run, tmpdir, project, controller):
|
||||
async_run(link.start_capture(capture_file_name="test.pcap"))
|
||||
assert link._capturing
|
||||
assert link._capture_file_name == "test.pcap"
|
||||
controller._notification.emit.assert_called_with("link.updated", link.__json__())
|
||||
controller._notification.project_emit.assert_called_with("link.updated", link.__json__())
|
||||
|
||||
|
||||
def test_stop_capture(link, async_run, tmpdir, project, controller):
|
||||
@@ -331,7 +331,7 @@ def test_stop_capture(link, async_run, tmpdir, project, controller):
|
||||
controller._notification = MagicMock()
|
||||
async_run(link.stop_capture())
|
||||
assert link._capturing is False
|
||||
controller._notification.emit.assert_called_with("link.updated", link.__json__())
|
||||
controller._notification.project_emit.assert_called_with("link.updated", link.__json__())
|
||||
|
||||
|
||||
def test_delete(async_run, project, compute):
|
||||
@@ -340,7 +340,7 @@ def test_delete(async_run, project, compute):
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
link._project.controller.notification.emit = MagicMock()
|
||||
link._project.controller.notification.project_emit = MagicMock()
|
||||
project.dump = AsyncioMagicMock()
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
|
||||
@@ -360,7 +360,7 @@ def test_update_filters(async_run, project, compute):
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
link._project.controller.notification.emit = MagicMock()
|
||||
link._project.controller.notification.project_emit = MagicMock()
|
||||
project.dump = AsyncioMagicMock()
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
|
||||
|
||||
@@ -363,12 +363,12 @@ def test_update_only_controller(node, controller, compute, project, async_run):
|
||||
async_run(node.update(x=42))
|
||||
assert not compute.put.called
|
||||
assert node.x == 42
|
||||
controller._notification.emit.assert_called_with("node.updated", node.__json__())
|
||||
controller._notification.project_emit.assert_called_with("node.updated", node.__json__())
|
||||
|
||||
# If nothing change a second notif should not be send
|
||||
controller._notification = AsyncioMagicMock()
|
||||
async_run(node.update(x=42))
|
||||
assert not controller._notification.emit.called
|
||||
assert not controller._notification.project_emit.called
|
||||
|
||||
|
||||
def test_update_no_changes(node, compute, project, async_run):
|
||||
|
||||
@@ -45,14 +45,14 @@ def test_emit_to_all(async_run, controller, project):
|
||||
Send an event to all if we don't have a project id in the event
|
||||
"""
|
||||
notif = controller.notification
|
||||
with notif.queue(project) as queue:
|
||||
assert len(notif._listeners[project.id]) == 1
|
||||
with notif.project_queue(project) as queue:
|
||||
assert len(notif._project_listeners[project.id]) == 1
|
||||
async_run(queue.get(0.1)) # ping
|
||||
notif.emit('test', {})
|
||||
notif.project_emit('test', {})
|
||||
msg = async_run(queue.get(5))
|
||||
assert msg == ('test', {}, {})
|
||||
|
||||
assert len(notif._listeners[project.id]) == 0
|
||||
assert len(notif._project_listeners[project.id]) == 0
|
||||
|
||||
|
||||
def test_emit_to_project(async_run, controller, project):
|
||||
@@ -60,22 +60,22 @@ def test_emit_to_project(async_run, controller, project):
|
||||
Send an event to a project listeners
|
||||
"""
|
||||
notif = controller.notification
|
||||
with notif.queue(project) as queue:
|
||||
assert len(notif._listeners[project.id]) == 1
|
||||
with notif.project_queue(project) as queue:
|
||||
assert len(notif._project_listeners[project.id]) == 1
|
||||
async_run(queue.get(0.1)) # ping
|
||||
# This event has not listener
|
||||
notif.emit('ignore', {"project_id": 42})
|
||||
notif.emit('test', {"project_id": project.id})
|
||||
notif.project_emit('ignore', {"project_id": 42})
|
||||
notif.project_emit('test', {"project_id": project.id})
|
||||
msg = async_run(queue.get(5))
|
||||
assert msg == ('test', {"project_id": project.id}, {})
|
||||
|
||||
assert len(notif._listeners[project.id]) == 0
|
||||
assert len(notif._project_listeners[project.id]) == 0
|
||||
|
||||
|
||||
def test_dispatch(async_run, controller, project):
|
||||
notif = controller.notification
|
||||
with notif.queue(project) as queue:
|
||||
assert len(notif._listeners[project.id]) == 1
|
||||
with notif.project_queue(project) as queue:
|
||||
assert len(notif._project_listeners[project.id]) == 1
|
||||
async_run(queue.get(0.1)) # ping
|
||||
async_run(notif.dispatch("test", {}, compute_id=1))
|
||||
msg = async_run(queue.get(5))
|
||||
@@ -84,8 +84,8 @@ def test_dispatch(async_run, controller, project):
|
||||
|
||||
def test_dispatch_ping(async_run, controller, project):
|
||||
notif = controller.notification
|
||||
with notif.queue(project) as queue:
|
||||
assert len(notif._listeners[project.id]) == 1
|
||||
with notif.project_queue(project) as queue:
|
||||
assert len(notif._project_listeners[project.id]) == 1
|
||||
async_run(queue.get(0.1)) # ping
|
||||
async_run(notif.dispatch("ping", {}, compute_id=12))
|
||||
msg = async_run(queue.get(5))
|
||||
@@ -99,8 +99,8 @@ def test_dispatch_node_updated(async_run, controller, node, project):
|
||||
"""
|
||||
|
||||
notif = controller.notification
|
||||
with notif.queue(project) as queue:
|
||||
assert len(notif._listeners[project.id]) == 1
|
||||
with notif.project_queue(project) as queue:
|
||||
assert len(notif._project_listeners[project.id]) == 1
|
||||
async_run(queue.get(0.1)) # ping
|
||||
async_run(notif.dispatch("node.updated", {
|
||||
"node_id": node.id,
|
||||
@@ -118,7 +118,7 @@ def test_dispatch_node_updated(async_run, controller, node, project):
|
||||
|
||||
def test_various_notification(controller, node):
|
||||
notif = controller.notification
|
||||
notif.emit("log.info", {"message": "Image uploaded"})
|
||||
notif.emit("log.warning", {"message": "Warning ASA 8 is not officialy supported by GNS3"})
|
||||
notif.emit("log.error", {"message": "Permission denied on /tmp"})
|
||||
notif.emit("node.updated", node.__json__())
|
||||
notif.project_emit("log.info", {"message": "Image uploaded"})
|
||||
notif.project_emit("log.warning", {"message": "Warning ASA 8 is not officialy supported by GNS3"})
|
||||
notif.project_emit("log.error", {"message": "Permission denied on /tmp"})
|
||||
notif.project_emit("node.updated", node.__json__())
|
||||
@@ -89,7 +89,7 @@ def test_update(controller, async_run):
|
||||
assert project.name == "Hello"
|
||||
async_run(project.update(name="World"))
|
||||
assert project.name == "World"
|
||||
controller.notification.emit.assert_any_call("project.updated", project.__json__())
|
||||
controller.notification.project_emit.assert_any_call("project.updated", project.__json__())
|
||||
|
||||
|
||||
def test_update_on_compute(controller, async_run):
|
||||
@@ -173,7 +173,7 @@ def test_add_node_local(async_run, controller):
|
||||
'name': 'test'},
|
||||
timeout=1200)
|
||||
assert compute in project._project_created_on_compute
|
||||
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
||||
controller.notification.project_emit.assert_any_call("node.created", node.__json__())
|
||||
|
||||
|
||||
def test_add_node_non_local(async_run, controller):
|
||||
@@ -201,7 +201,7 @@ def test_add_node_non_local(async_run, controller):
|
||||
'name': 'test'},
|
||||
timeout=1200)
|
||||
assert compute in project._project_created_on_compute
|
||||
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
||||
controller.notification.project_emit.assert_any_call("node.created", node.__json__())
|
||||
|
||||
|
||||
def test_add_node_from_appliance(async_run, controller):
|
||||
@@ -242,7 +242,7 @@ def test_add_node_from_appliance(async_run, controller):
|
||||
},
|
||||
timeout=1200)
|
||||
assert compute in project._project_created_on_compute
|
||||
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
||||
controller.notification.project_emit.assert_any_call("node.created", node.__json__())
|
||||
|
||||
# Make sure we can call twice the node creation
|
||||
node = async_run(project.add_node_from_appliance(appliance.id, x=13, y=12))
|
||||
@@ -272,7 +272,7 @@ def test_delete_node(async_run, controller):
|
||||
assert node.id not in project._nodes
|
||||
|
||||
compute.delete.assert_any_call('/projects/{}/vpcs/nodes/{}'.format(project.id, node.id))
|
||||
controller.notification.emit.assert_any_call("node.deleted", node.__json__())
|
||||
controller.notification.project_emit.assert_any_call("node.deleted", node.__json__())
|
||||
|
||||
|
||||
def test_delete_node_delete_link(async_run, controller):
|
||||
@@ -297,8 +297,8 @@ def test_delete_node_delete_link(async_run, controller):
|
||||
assert link.id not in project._links
|
||||
|
||||
compute.delete.assert_any_call('/projects/{}/vpcs/nodes/{}'.format(project.id, node.id))
|
||||
controller.notification.emit.assert_any_call("node.deleted", node.__json__())
|
||||
controller.notification.emit.assert_any_call("link.deleted", link.__json__())
|
||||
controller.notification.project_emit.assert_any_call("node.deleted", node.__json__())
|
||||
controller.notification.project_emit.assert_any_call("link.deleted", link.__json__())
|
||||
|
||||
|
||||
def test_get_node(async_run, controller):
|
||||
@@ -355,7 +355,7 @@ def test_add_link(async_run, project, controller):
|
||||
async_run(link.add_node(vm2, 4, 2))
|
||||
assert mock_udp_create.called
|
||||
assert len(link._nodes) == 2
|
||||
controller.notification.emit.assert_any_call("link.created", link.__json__())
|
||||
controller.notification.project_emit.assert_any_call("link.created", link.__json__())
|
||||
|
||||
|
||||
def test_list_links(async_run, project):
|
||||
@@ -398,16 +398,16 @@ def test_delete_link(async_run, project, controller):
|
||||
assert len(project._links) == 1
|
||||
controller._notification = MagicMock()
|
||||
async_run(project.delete_link(link.id))
|
||||
controller.notification.emit.assert_any_call("link.deleted", link.__json__())
|
||||
controller.notification.project_emit.assert_any_call("link.deleted", link.__json__())
|
||||
assert len(project._links) == 0
|
||||
|
||||
|
||||
def test_add_drawing(async_run, project, controller):
|
||||
controller.notification.emit = MagicMock()
|
||||
controller.notification.project_emit = MagicMock()
|
||||
|
||||
drawing = async_run(project.add_drawing(None, svg="<svg></svg>"))
|
||||
assert len(project._drawings) == 1
|
||||
controller.notification.emit.assert_any_call("drawing.created", drawing.__json__())
|
||||
controller.notification.project_emit.assert_any_call("drawing.created", drawing.__json__())
|
||||
|
||||
|
||||
def test_get_drawing(async_run, project):
|
||||
@@ -432,7 +432,7 @@ def test_delete_drawing(async_run, project, controller):
|
||||
assert len(project._drawings) == 1
|
||||
controller._notification = MagicMock()
|
||||
async_run(project.delete_drawing(drawing.id))
|
||||
controller.notification.emit.assert_any_call("drawing.deleted", drawing.__json__())
|
||||
controller.notification.project_emit.assert_any_call("drawing.deleted", drawing.__json__())
|
||||
assert len(project._drawings) == 0
|
||||
|
||||
|
||||
@@ -498,7 +498,7 @@ def test_open_close(async_run, controller):
|
||||
controller._notification = MagicMock()
|
||||
async_run(project.close())
|
||||
assert project.status == "closed"
|
||||
controller.notification.emit.assert_any_call("project.closed", project.__json__())
|
||||
controller.notification.project_emit.assert_any_call("project.closed", project.__json__())
|
||||
|
||||
|
||||
def test_open_auto_start(async_run, controller):
|
||||
|
||||
@@ -94,9 +94,9 @@ def test_restore(project, controller, async_run):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
async_run(snapshot.restore())
|
||||
|
||||
assert "snapshot.restored" in [c[0][0] for c in controller.notification.emit.call_args_list]
|
||||
assert "snapshot.restored" in [c[0][0] for c in controller.notification.project_emit.call_args_list]
|
||||
# project.closed notification should not be send when restoring snapshots
|
||||
assert "project.closed" not in [c[0][0] for c in controller.notification.emit.call_args_list]
|
||||
assert "project.closed" not in [c[0][0] for c in controller.notification.project_emit.call_args_list]
|
||||
|
||||
project = controller.get_project(project.id)
|
||||
assert not os.path.exists(test_file)
|
||||
|
||||
@@ -174,7 +174,7 @@ def test_notification(http_controller, project, controller, loop, async_run):
|
||||
connector = aiohttp.TCPConnector()
|
||||
response = yield from aiohttp.request("GET", http_controller.get_url("/projects/{project_id}/notifications".format(project_id=project.id)), connector=connector)
|
||||
response.body = yield from response.content.read(200)
|
||||
controller.notification.emit("node.created", {"a": "b"})
|
||||
controller.notification.project_emit("node.created", {"a": "b"})
|
||||
response.body += yield from response.content.readany()
|
||||
response.close()
|
||||
return response
|
||||
@@ -198,7 +198,7 @@ def test_notification_ws(http_controller, controller, project, async_run):
|
||||
answer = json.loads(answer.data)
|
||||
assert answer["action"] == "ping"
|
||||
|
||||
controller.notification.emit("test", {})
|
||||
controller.notification.project_emit("test", {})
|
||||
|
||||
answer = async_run(ws.receive())
|
||||
answer = json.loads(answer.data)
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
# -*- 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/>.
|
||||
|
||||
import logging
|
||||
|
||||
from gns3server.web.logger import init_logger
|
||||
|
||||
|
||||
def test_init_logger(caplog):
|
||||
|
||||
logger = init_logger(logging.DEBUG)
|
||||
logger.debug("DEBUG1")
|
||||
assert "DEBUG1" in caplog.text
|
||||
logger.info("INFO1")
|
||||
assert "INFO1" in caplog.text
|
||||
logger.warn("WARN1")
|
||||
assert "WARN1" in caplog.text
|
||||
logger.error("ERROR1")
|
||||
assert "ERROR1" in caplog.text
|
||||
logger.critical("CRITICAL1")
|
||||
assert "CRITICAL1" in caplog.text
|
||||
|
||||
|
||||
def test_init_logger_quiet(caplog):
|
||||
|
||||
logger = init_logger(logging.DEBUG, quiet=True)
|
||||
logger.debug("DEBUG1")
|
||||
assert "DEBUG1" not in caplog.text
|
||||
logger.info("INFO1")
|
||||
assert "INFO1" not in caplog.text
|
||||
logger.warn("WARN1")
|
||||
assert "WARN1" not in caplog.text
|
||||
logger.error("ERROR1")
|
||||
assert "ERROR1" not in caplog.text
|
||||
logger.critical("CRITICAL1")
|
||||
assert "CRITICAL1" not in caplog.text
|
||||
Reference in new issue
Block a user