From 30d6297c89e66ffd8f811a4aeb011c9f0ef5ce49 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 11 Aug 2019 11:31:19 -0700 Subject: [PATCH] tests: Fix flake8 warning about unused imports Signed-off-by: Sunil Mohan Adapa --- plinth/tests/conftest.py | 57 +++++++++++++++++++++++++++ plinth/tests/test_custom_shortcuts.py | 34 +--------------- plinth/tests/test_frontpage.py | 3 -- 3 files changed, 58 insertions(+), 36 deletions(-) create mode 100644 plinth/tests/conftest.py diff --git a/plinth/tests/conftest.py b/plinth/tests/conftest.py new file mode 100644 index 000000000..1542dc7c2 --- /dev/null +++ b/plinth/tests/conftest.py @@ -0,0 +1,57 @@ +# +# This file is part of FreedomBox. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +""" +pytest configuration for all tests in the plinth/tests/ directory. +""" + +import json + +import pytest + +NEXTCLOUD_SHORTCUT = { + 'name': + 'NextCloud', + 'short_description': + 'File Hosting Service', + 'description': [ + 'Nextcloud is a suite of client-server software for creating ' + 'and using file hosting services.' + ], + 'icon_url': + '/plinth/custom/static/themes/default/icons/nextcloud.png', + 'clients': [{ + 'name': 'nextcloud', + 'platforms': [{ + 'type': 'web', + 'url': '/nextcloud' + }] + }] +} + + +@pytest.fixture(name='custom_shortcuts_file') +def fixture_custom_shortcuts_file(load_cfg, tmp_path): + """Fixture to set path for a custom shortcuts file.""" + load_cfg.config_file = str(tmp_path / 'plinth.conf') + return tmp_path / 'custom-shortcuts.json' + + +@pytest.fixture(name='nextcloud_shortcut') +def fixture_nextcloud_shortcut(custom_shortcuts_file): + """Create a custom_shortcuts file with NextCloud shortcut.""" + shortcuts = {'shortcuts': [NEXTCLOUD_SHORTCUT]} + custom_shortcuts_file.write_text(json.dumps(shortcuts)) diff --git a/plinth/tests/test_custom_shortcuts.py b/plinth/tests/test_custom_shortcuts.py index 9e848c387..c0aaae145 100644 --- a/plinth/tests/test_custom_shortcuts.py +++ b/plinth/tests/test_custom_shortcuts.py @@ -24,32 +24,7 @@ import pytest from plinth.modules.api.views import get_shortcuts_as_json -NEXTCLOUD_SHORTCUT = { - 'name': - 'NextCloud', - 'short_description': - 'File Hosting Service', - 'description': [ - 'Nextcloud is a suite of client-server software for creating ' - 'and using file hosting services.' - ], - 'icon_url': - '/plinth/custom/static/themes/default/icons/nextcloud.png', - 'clients': [{ - 'name': 'nextcloud', - 'platforms': [{ - 'type': 'web', - 'url': '/nextcloud' - }] - }] -} - - -@pytest.fixture(name='custom_shortcuts_file') -def fixture_custom_shortcuts_file(load_cfg, tmp_path): - """Fixture to set path for a custom shortcuts file.""" - load_cfg.config_file = str(tmp_path / 'plinth.conf') - return tmp_path / 'custom-shortcuts.json' +from .conftest import NEXTCLOUD_SHORTCUT @pytest.fixture(name='no_custom_shortcuts_file') @@ -71,13 +46,6 @@ def fixture_empty_custom_shortcuts(custom_shortcuts_file): custom_shortcuts_file.write_text(json.dumps({'shortcuts': []})) -@pytest.fixture(name='nextcloud_shortcut') -def fixture_nextcloud_shortcut(custom_shortcuts_file): - """Create a custom_shortcuts file with NextCloud shortcut.""" - shortcuts = {'shortcuts': [NEXTCLOUD_SHORTCUT]} - custom_shortcuts_file.write_text(json.dumps(shortcuts)) - - @pytest.mark.usefixtures('no_custom_shortcuts_file') def test_shortcuts_api_with_no_custom_shortcuts_file(): get_shortcuts_as_json() diff --git a/plinth/tests/test_frontpage.py b/plinth/tests/test_frontpage.py index 4cce42b2d..764cc14b3 100644 --- a/plinth/tests/test_frontpage.py +++ b/plinth/tests/test_frontpage.py @@ -24,9 +24,6 @@ import pytest from plinth.frontpage import Shortcut, add_custom_shortcuts -from .test_custom_shortcuts import (fixture_custom_shortcuts_file, - fixture_nextcloud_shortcut) - # pylint: disable=protected-access