Merge pull request #69 from YunoHost-Apps/cleanup

Cleanup: Remove obsolete test files
This commit is contained in:
Jens Diemer 2024-08-25 20:01:57 +02:00 committed by GitHub
commit da5f30831c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 0 additions and 434 deletions

View file

View file

@ -1,43 +0,0 @@
"""
Special pytest init:
- Build a "local_test" YunoHost installation
- init Django with this local test installation
So the pytests will run against this local test installation
"""
import os
import sys
from pathlib import Path
import django
from django_yunohost_integration.local_test import CreateResults, create_local_test
BASE_PATH = Path(__file__).parent.parent
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
def pytest_configure():
print('Compile YunoHost files...')
result: CreateResults = create_local_test(
django_settings_path=BASE_PATH / 'conf' / 'settings.py',
destination=BASE_PATH / 'local_test',
runserver=False,
extra_replacements={
'__DEBUG_ENABLED__': '0', # "1" or "0" string
'__LOG_LEVEL__': 'INFO',
'__ADMIN_EMAIL__': 'foo-bar@test.tld',
'__DEFAULT_FROM_EMAIL__': 'django_app@test.tld',
},
)
print('Local test files created:')
print(result)
os.chdir(result.data_dir_path)
data_dir = str(result.data_dir_path)
if data_dir not in sys.path:
sys.path.insert(0, data_dir)
django.setup()

View file

@ -1,176 +0,0 @@
from unittest.mock import patch
import for_runners
from axes.models import AccessLog
from bx_django_utils.test_utils.html_assertion import HtmlAssertionMixin, assert_html_response_snapshot
from django.conf import LazySettings, settings
from django.contrib.auth.models import User
from django.template.defaulttags import CsrfTokenNode
from django.test import override_settings
from django.test.testcases import TestCase
from django.urls.base import reverse
from django_yunohost_integration.test_utils import generate_basic_auth
@override_settings(DEBUG=False)
class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
def setUp(self):
super().setUp()
# Always start a fresh session:
self.client = self.client_class()
def test_settings(self):
assert isinstance(settings, LazySettings)
assert settings.configured is True
assert settings.PATH_URL == 'app_path'
assert str(settings.DATA_DIR_PATH).endswith('/local_test/opt_yunohost')
assert str(settings.INSTALL_DIR_PATH).endswith('/local_test/var_www')
assert str(settings.LOG_FILE_PATH).endswith('/local_test/var_log_django-for-runners.log')
assert settings.ROOT_URLCONF == 'urls'
def test_config_panel_settings(self):
# config_panel.toml settings, set via tests.conftest.pytest_configure():
assert settings.DEBUG_ENABLED == '0' and settings.DEBUG is False
assert settings.LOG_LEVEL == 'INFO'
assert settings.ADMIN_EMAIL == 'foo-bar@test.tld'
assert settings.DEFAULT_FROM_EMAIL == 'django_app@test.tld'
def test_urls(self):
assert reverse('admin:index') == '/app_path/'
# TODO: https://github.com/jedie/django-for-runners/issues/25
# Serve user uploads via django_tools.serve_media_app:
# assert settings.MEDIA_URL == '/app_path/media/'
# assert reverse(
# 'serve_media_app:serve-media', kwargs={'user_token': 'token', 'path': 'foo/bar/'}
# ) == ('/app_path/media/token/foo/bar/')
def test_auth(self):
assert settings.PATH_URL == 'app_path'
assert reverse('admin:index') == '/app_path/'
# SecurityMiddleware should redirects all non-HTTPS requests to HTTPS:
assert settings.SECURE_SSL_REDIRECT is True
response = self.client.get('/app_path/', secure=False)
self.assertRedirects(
response,
status_code=301, # permanent redirect
expected_url='https://testserver/app_path/',
fetch_redirect_response=False,
)
response = self.client.get('/app_path/', secure=True)
self.assertRedirects(
response, expected_url='/app_path/login/?next=/app_path/', fetch_redirect_response=False
)
def test_create_unknown_user(self):
assert User.objects.count() == 0
self.client.cookies['SSOwAuthUser'] = 'test'
with patch.object(CsrfTokenNode, 'render', return_value='MockedCsrfTokenNode'):
response = self.client.get(
path='/app_path/',
HTTP_REMOTE_USER='test',
HTTP_AUTH_USER='test',
HTTP_AUTHORIZATION='basic dGVzdDp0ZXN0MTIz',
secure=True,
)
assert User.objects.count() == 1
user = User.objects.first()
assert user.username == 'test'
assert user.is_active is True
assert user.is_staff is True # Set by: conf.setup_user.setup_project_user
assert user.is_superuser is False
self.assert_html_parts(
response,
parts=(
f'<title>Site administration | Django-ForRunners v{for_runners.__version__}</title>',
'<strong>test</strong>',
),
)
assert_html_response_snapshot(response, query_selector='#container', validate=False)
def test_wrong_auth_user(self):
assert User.objects.count() == 0
assert AccessLog.objects.count() == 0
self.client.cookies['SSOwAuthUser'] = 'test'
response = self.client.get(
path='/app_path/',
HTTP_REMOTE_USER='test',
HTTP_AUTH_USER='foobar', # <<< wrong user name
HTTP_AUTHORIZATION='basic dGVzdDp0ZXN0MTIz',
secure=True,
)
assert User.objects.count() == 1
user = User.objects.first()
assert user.username == 'test'
assert user.is_active is True
assert user.is_staff is True # Set by: conf.setup_user.setup_project_user
assert user.is_superuser is False
assert AccessLog.objects.count() == 1
assert response.status_code == 403 # Forbidden
def test_wrong_cookie(self):
assert User.objects.count() == 0
assert AccessLog.objects.count() == 0
self.client.cookies['SSOwAuthUser'] = 'foobar' # <<< wrong user name
response = self.client.get(
path='/app_path/',
HTTP_REMOTE_USER='test',
HTTP_AUTH_USER='test',
HTTP_AUTHORIZATION='basic dGVzdDp0ZXN0MTIz',
secure=True,
)
assert User.objects.count() == 1
user = User.objects.first()
assert user.username == 'test'
assert user.is_active is True
assert user.is_staff is True # Set by: conf.setup_user.setup_project_user
assert user.is_superuser is False
assert AccessLog.objects.count() == 1
assert response.status_code == 403 # Forbidden
def test_wrong_authorization_user(self):
assert User.objects.count() == 0
self.client.cookies['SSOwAuthUser'] = 'test'
response = self.client.get(
path='/app_path/',
HTTP_REMOTE_USER='test',
HTTP_AUTH_USER='test',
HTTP_AUTHORIZATION=generate_basic_auth(
username='foobar', # <<< wrong user name
password='test123',
),
secure=True,
)
assert User.objects.count() == 1
user = User.objects.first()
assert user.username == 'test'
assert user.is_active is True
assert user.is_staff is True # Set by: conf.setup_user.setup_project_user
assert user.is_superuser is False
assert AccessLog.objects.count() == 1
assert response.status_code == 403 # Forbidden

View file

@ -1,90 +0,0 @@
<div id="container">
<!-- Header -->
<div id="header">
<div id="branding">
<h1 id="site-name">
<a href="/app_path/">
<img alt="Logo" height="40px" src="/app_path/static/Django-ForRunners.svg"/>
Django-ForRunners v0.19.0
</a>
</h1>
</div>
<div id="user-tools">
Welcome,
<strong>
test
</strong>
.
<a href="/">
View site
</a>
/
<a href="/app_path/password_change/">
Change password
</a>
/
<form action="/app_path/logout/" id="logout-form" method="post">
MockedCsrfTokenNode
<button type="submit">
Log out
</button>
</form>
<button class="theme-toggle">
<div class="visually-hidden theme-label-when-auto">
Toggle theme (current theme: auto)
</div>
<div class="visually-hidden theme-label-when-light">
Toggle theme (current theme: light)
</div>
<div class="visually-hidden theme-label-when-dark">
Toggle theme (current theme: dark)
</div>
<svg aria-hidden="true" class="theme-icon-when-auto">
<use xlink:href="#icon-auto">
</use>
</svg>
<svg aria-hidden="true" class="theme-icon-when-dark">
<use xlink:href="#icon-moon">
</use>
</svg>
<svg aria-hidden="true" class="theme-icon-when-light">
<use xlink:href="#icon-sun">
</use>
</svg>
</button>
</div>
</div>
<!-- END Header -->
<div class="main" id="main">
<div class="content" id="content-start" tabindex="-1">
<!-- Content -->
<div class="colMS" id="content">
<h1>
Site administration
</h1>
<div id="content-main">
<p>
You dont have permission to view or edit anything.
</p>
</div>
<div id="content-related">
<div class="module" id="recent-actions-module">
<h2>
Recent actions
</h2>
<h3>
My actions
</h3>
<p>
None available
</p>
</div>
</div>
<br class="clear"/>
</div>
<!-- END Content -->
<div id="footer">
</div>
</div>
</div>
</div>

View file

@ -1,17 +0,0 @@
import subprocess
from unittest import TestCase
from bx_py_utils.path import assert_is_file
from django_yunohost_integration.path_utils import get_project_root
class ManageLocalTestTestCase(TestCase):
def test_manage_local_test_check(self):
manage_local_test_bin = get_project_root() / 'manage_local_test.py'
assert_is_file(manage_local_test_bin)
output = subprocess.check_output([manage_local_test_bin, 'check'], text=True)
self.assertIn('Setup local YunoHost package', output)
self.assertIn('django-for-runners_ynh/local_test/', output)

View file

@ -1,100 +0,0 @@
import os
import tomllib
from pathlib import Path
from unittest import TestCase
from bx_django_utils.filename import clean_filename
from bx_py_utils.path import assert_is_dir, assert_is_file
from django_tools.unittest_utils.project_setup import check_editor_config
from django_yunohost_integration.path_utils import get_project_root
from django_yunohost_integration.test_utils import assert_project_version
from for_runners import __version__ as upstream_version
from for_runners_ynh import __version__
def assert_file_contains_string(file_path, string):
with file_path.open('r') as f:
for line in f:
if string in line:
return
raise AssertionError(f'File {file_path} does not contain {string!r} !')
def test_version():
assert '+ynh' in __version__, f'{__version__!r} does not contain "+ynh"'
assert upstream_version in __version__, f'{__version__!r} does not contain {upstream_version!r}'
# pyproject.toml needs a PEP 440 conform version and used "+ynh"
# the YunoHost syntax is: "~ynh", just "convert this:
manifest_version = __version__.replace('+', '~')
assert_file_contains_string(
file_path=Path(get_project_root(), 'manifest.toml'),
string=f'version = "{manifest_version}"',
)
if 'GITHUB_ACTION' not in os.environ:
# Github has a rate-limiting... So don't fetch the API if we run as GitHub action
assert_project_version(
current_version=__version__,
github_project_url='https://github.com/jedie/django-for-runners',
)
def test_screenshot_filenames():
"""
https://forum.yunohost.org/t/yunohost-bot-cant-handle-spaces-in-screenshots/19483
"""
screenshot_path = get_project_root() / 'doc' / 'screenshots'
assert_is_dir(screenshot_path)
renamed = []
for file_path in screenshot_path.iterdir():
file_name = file_path.name
if file_name.startswith('.'):
continue
cleaned_name = clean_filename(file_name)
if cleaned_name != file_name:
new_path = file_path.with_name(cleaned_name)
file_path.rename(new_path)
renamed.append(f'{file_name!r} renamed to {cleaned_name!r}')
assert not renamed, f'Bad screenshots file names found: {", ".join(renamed)}'
def test_check_editor_config():
check_editor_config(package_root=get_project_root())
class ManifestTestCase(TestCase):
def test_manifest_toml(self):
manifest_path = get_project_root() / 'manifest.toml'
assert_is_file(manifest_path)
cfg = tomllib.loads(manifest_path.read_text(encoding='UTF-8'))
self.assertEqual(cfg['packaging_format'], 2)
self.assertEqual(
set(cfg['install'].keys()),
{
'admin',
'admin_email',
'debug_enabled',
'default_from_email',
'domain',
'init_main_permission',
'log_level',
'path',
},
)
self.assertEqual(
set(cfg['resources'].keys()),
{
'apt',
'data_dir',
'database',
'install_dir',
'permissions',
'ports',
'system_user',
},
)

View file

@ -1,8 +0,0 @@
from unittest.case import TestCase
from django_yunohost_integration.test_utils import generate_basic_auth
class TestUtilsTestCase(TestCase):
def test_generate_basic_auth(self):
assert generate_basic_auth(username='test', password='test123') == 'basic dGVzdDp0ZXN0MTIz'