Use mocked dir of web-ui for tests

This commit is contained in:
ziajka 2018-06-26 12:53:39 +02:00
parent 21780fa2ed
commit 7d75b6248d

View File

@ -17,10 +17,11 @@
import os import os
from unittest.mock import patch
from gns3server.version import __version__ from gns3server.version import __version__
from gns3server.controller import Controller from gns3server.controller import Controller
from gns3server.utils.static import get_static_path from gns3server.utils import static
def test_index(http_root): def test_index(http_root):
@ -50,12 +51,14 @@ def test_project(http_root, async_run):
def test_web_ui(http_root, tmpdir): def test_web_ui(http_root, tmpdir):
tmpfile = get_static_path('web-ui/testing.txt') with patch('gns3server.utils.static.get_static_dir') as mock:
with open(tmpfile, 'w+') as f: mock.return_value = str(tmpdir)
f.write('world') os.makedirs(str(tmpdir / 'web-ui'))
response = http_root.get('/static/web-ui/testing.txt') tmpfile = static.get_static_path('web-ui/testing.txt')
assert response.status == 200 with open(tmpfile, 'w+') as f:
os.remove(tmpfile) f.write('world')
response = http_root.get('/static/web-ui/testing.txt')
assert response.status == 200
def test_web_ui_not_found(http_root, tmpdir): def test_web_ui_not_found(http_root, tmpdir):