mirror of
https://github.com/YunoHost-Apps/scovie_ynh.git
synced 2024-09-03 20:16:29 +02:00
update 5 files and delete 6 files
This commit is contained in:
parent
f5b93d1ba3
commit
3f57681829
11 changed files with 1129 additions and 1587 deletions
|
@ -7,12 +7,6 @@ async-timeout==4.0.2 ; python_version >= "3.9" and python_full_version < "4.0.0"
|
||||||
bleach==5.0.1 ; python_version >= "3.9" and python_full_version < "4.0.0" \
|
bleach==5.0.1 ; python_version >= "3.9" and python_full_version < "4.0.0" \
|
||||||
--hash=sha256:085f7f33c15bd408dd9b17a4ad77c577db66d76203e5984b1bd59baeee948b2a \
|
--hash=sha256:085f7f33c15bd408dd9b17a4ad77c577db66d76203e5984b1bd59baeee948b2a \
|
||||||
--hash=sha256:0d03255c47eb9bd2f26aa9bb7f2107732e7e8fe195ca2f64709fcf3b0a4a085c
|
--hash=sha256:0d03255c47eb9bd2f26aa9bb7f2107732e7e8fe195ca2f64709fcf3b0a4a085c
|
||||||
bx-django-utils==36 ; python_version >= "3.9" and python_full_version < "4.0.0" \
|
|
||||||
--hash=sha256:98f900da91e3cdb22d2f386863fe05e58cfc18ff2d7c0ee656e7d551a135f529 \
|
|
||||||
--hash=sha256:badb8d7fb04ce449cac7896ee435e69d2786eebc3e8c756e99e9379be816cd5f
|
|
||||||
bx-py-utils==69 ; python_version >= "3.9" and python_full_version < "4.0.0" \
|
|
||||||
--hash=sha256:728fd575c4d5048e114b502a97d19679f9abcda90889a6896534c48348320460 \
|
|
||||||
--hash=sha256:b25419e020c9c5ea16938a45cf5120086a5ac29648be78a8eb98ae202515fee1
|
|
||||||
colorama==0.4.5 ; python_version >= "3.9" and python_full_version < "4.0.0" and sys_platform == "win32" \
|
colorama==0.4.5 ; python_version >= "3.9" and python_full_version < "4.0.0" and sys_platform == "win32" \
|
||||||
--hash=sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da \
|
--hash=sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da \
|
||||||
--hash=sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4
|
--hash=sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4
|
||||||
|
|
|
@ -11,11 +11,14 @@
|
||||||
|
|
||||||
from pathlib import Path as __Path
|
from pathlib import Path as __Path
|
||||||
|
|
||||||
|
from django.contrib.admin.sites import AdminSite
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from django_yunohost_integration.base_settings import * # noqa:F401,F403
|
from django_yunohost_integration.base_settings import * # noqa:F401,F403
|
||||||
from django_yunohost_integration.secret_key import get_or_create_secret as __get_or_create_secret
|
from django_yunohost_integration.secret_key import get_or_create_secret as __get_or_create_secret
|
||||||
|
|
||||||
|
|
||||||
from django_example.settings.prod import * # noqa:F401,F403 isort:skip
|
from scovie.settings.prod import * # noqa:F401,F403 isort:skip
|
||||||
|
|
||||||
|
|
||||||
from django_yunohost_integration.base_settings import LOGGING # noqa:F401 isort:skip
|
from django_yunohost_integration.base_settings import LOGGING # noqa:F401 isort:skip
|
||||||
|
@ -159,13 +162,32 @@ MEDIA_ROOT = str(PUBLIC_PATH / 'media')
|
||||||
LOGGING['handlers']['log_file']['filename'] = str(LOG_FILE)
|
LOGGING['handlers']['log_file']['filename'] = str(LOG_FILE)
|
||||||
|
|
||||||
# Example how to add logging to own app:
|
# Example how to add logging to own app:
|
||||||
LOGGING['loggers']['django_example'] = {
|
LOGGING['loggers']['scovie'] = {
|
||||||
'handlers': ['syslog', 'log_file', 'mail_admins'],
|
'handlers': ['syslog', 'log_file', 'mail_admins'],
|
||||||
'level': 'INFO',
|
'level': 'INFO',
|
||||||
'propagate': False,
|
'propagate': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
# Internationalization
|
||||||
|
AdminSite.site_title = _("Scovie")
|
||||||
|
AdminSite.site_header = _("Scovie - Information management software")
|
||||||
|
AdminSite.index_title = _("Administration of Scovie")
|
||||||
|
|
||||||
|
LANGUAGES = [
|
||||||
|
('en', 'English'),
|
||||||
|
('fr', 'Français'),
|
||||||
|
]
|
||||||
|
|
||||||
|
LANGUAGE_CODE = "en"
|
||||||
|
|
||||||
|
LOCALE_PATHS = [BASE_PATH / 'locale']
|
||||||
|
|
||||||
|
TIME_ZONE = "UTC"
|
||||||
|
|
||||||
|
USE_I18N = True
|
||||||
|
|
||||||
|
USE_TZ = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from local_settings import * # noqa:F401,F403
|
from local_settings import * # noqa:F401,F403
|
||||||
|
|
|
@ -21,9 +21,9 @@ if settings.PATH_URL:
|
||||||
# Prefix all urls with "PATH_URL":
|
# Prefix all urls with "PATH_URL":
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', RedirectView.as_view(url=f'{settings.PATH_URL}/')),
|
path('', RedirectView.as_view(url=f'{settings.PATH_URL}/')),
|
||||||
path(f'{settings.PATH_URL}/', include('django_example.urls')),
|
path(f'{settings.PATH_URL}/', include('scovie.urls')),
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
# Installed to domain root, without a path prefix
|
# Installed to domain root, without a path prefix
|
||||||
# Just use the default project urls.py
|
# Just use the default project urls.py
|
||||||
from django_example.urls import urlpatterns # noqa
|
from scovie.urls import urlpatterns # noqa
|
||||||
|
|
2145
poetry.lock
generated
2145
poetry.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -12,7 +12,7 @@ homepage = "https://github.com/eldertek/scovie_ynh"
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = ">=3.9,<4.0.0" # Stay with 3.9 until YunoHost used >=Debian 11 (Bullseye)
|
python = ">=3.9,<4.0.0" # Stay with 3.9 until YunoHost used >=Debian 11 (Bullseye)
|
||||||
|
|
||||||
scovie = ">=0.1.0rc0" # https://github.com/eldertek/scovie
|
scovie = ">=0.0.2" # https://github.com/eldertek/scovie
|
||||||
|
|
||||||
# extras "ynh" will install: gunicorn, psycopg2, django-redis and django-axes
|
# extras "ynh" will install: gunicorn, psycopg2, django-redis and django-axes
|
||||||
# see: https://github.com/YunoHost-Apps/django_yunohost_integration/blob/main/pyproject.toml
|
# see: https://github.com/YunoHost-Apps/django_yunohost_integration/blob/main/pyproject.toml
|
||||||
|
@ -20,8 +20,6 @@ django_yunohost_integration = {version = ">=0.5.0rc1", extras = ["ynh"]} # http
|
||||||
|
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
bx_py_utils = "*" # https://github.com/boxine/bx_py_utils
|
|
||||||
bx_django_utils = "*" # https://github.com/boxine/bx_django_utils
|
|
||||||
tox = "*"
|
tox = "*"
|
||||||
pytest = "*"
|
pytest = "*"
|
||||||
pytest-cov = "*"
|
pytest-cov = "*"
|
||||||
|
|
|
@ -1,44 +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 create_local_test
|
|
||||||
|
|
||||||
|
|
||||||
BASE_PATH = Path(__file__).parent.parent
|
|
||||||
|
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure():
|
|
||||||
print('Compile YunoHost files...')
|
|
||||||
final_path = create_local_test(
|
|
||||||
django_settings_path=BASE_PATH / 'conf' / 'settings.py',
|
|
||||||
destination=BASE_PATH / 'local_test',
|
|
||||||
runserver=False,
|
|
||||||
extra_replacements={
|
|
||||||
'__DEBUG_ENABLED__': '0',
|
|
||||||
'__LOG_LEVEL__': 'INFO',
|
|
||||||
'__ADMIN_EMAIL__': 'foo-bar@test.tld',
|
|
||||||
'__DEFAULT_FROM_EMAIL__': 'django_app@test.tld',
|
|
||||||
},
|
|
||||||
)
|
|
||||||
print('Local test files created here:')
|
|
||||||
print(f'"{final_path}"')
|
|
||||||
|
|
||||||
os.chdir(final_path)
|
|
||||||
final_home_str = str(final_path)
|
|
||||||
if final_home_str not in sys.path:
|
|
||||||
sys.path.insert(0, final_home_str)
|
|
||||||
|
|
||||||
django.setup()
|
|
|
@ -1,160 +0,0 @@
|
||||||
from axes.models import AccessLog
|
|
||||||
from bx_django_utils.test_utils.html_assertion import HtmlAssertionMixin
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
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 settings.PATH_URL == 'app_path'
|
|
||||||
|
|
||||||
assert str(settings.FINALPATH).endswith('/local_test/opt_yunohost')
|
|
||||||
assert str(settings.PUBLIC_PATH).endswith('/local_test/var_www')
|
|
||||||
assert str(settings.LOG_FILE).endswith('/local_test/var_log_scovie_ynh.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_auth(self):
|
|
||||||
assert settings.PATH_URL == 'app_path'
|
|
||||||
assert reverse('admin:index') == '/app_path/admin/'
|
|
||||||
|
|
||||||
# SecurityMiddleware should redirects all non-HTTPS requests to HTTPS:
|
|
||||||
assert settings.SECURE_SSL_REDIRECT is True
|
|
||||||
response = self.client.get('/app_path/admin/', secure=False)
|
|
||||||
self.assertRedirects(
|
|
||||||
response,
|
|
||||||
status_code=301, # permanent redirect
|
|
||||||
expected_url='https://testserver/app_path/admin/',
|
|
||||||
fetch_redirect_response=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
response = self.client.get('/app_path/admin/', secure=True)
|
|
||||||
self.assertRedirects(
|
|
||||||
response,
|
|
||||||
expected_url='/app_path/admin/login/?next=%2Fapp_path%2Fadmin%2F',
|
|
||||||
fetch_redirect_response=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_create_unknown_user(self):
|
|
||||||
assert User.objects.count() == 0
|
|
||||||
|
|
||||||
self.client.cookies['SSOwAuthUser'] = 'test'
|
|
||||||
|
|
||||||
response = self.client.get(
|
|
||||||
path='/app_path/admin/',
|
|
||||||
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=(
|
|
||||||
'<h1 id="site-name"><a href="/app_path/admin/">Django administration</a></h1>',
|
|
||||||
'<strong>test</strong>',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
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/admin/',
|
|
||||||
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
|
|
|
@ -1,66 +0,0 @@
|
||||||
import os
|
|
||||||
|
|
||||||
from bx_django_utils.test_utils.html_assertion import (
|
|
||||||
HtmlAssertionMixin,
|
|
||||||
assert_html_response_snapshot,
|
|
||||||
)
|
|
||||||
from django.conf import settings
|
|
||||||
from django.test.testcases import TestCase
|
|
||||||
from django.urls.base import reverse
|
|
||||||
from django_example import __version__
|
|
||||||
|
|
||||||
|
|
||||||
class ExampleProjectTestCase(HtmlAssertionMixin, TestCase):
|
|
||||||
def test_urls(self):
|
|
||||||
assert settings.PATH_URL == 'app_path'
|
|
||||||
assert reverse('admin:index') == '/app_path/admin/'
|
|
||||||
assert reverse('debug-view') == '/app_path/'
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Test as anonymous user
|
|
||||||
|
|
||||||
with self.assertLogs('django_example') as logs:
|
|
||||||
response = self.client.get(
|
|
||||||
path='/app_path/',
|
|
||||||
secure=True,
|
|
||||||
)
|
|
||||||
self.assert_html_parts(
|
|
||||||
response,
|
|
||||||
parts=(
|
|
||||||
f'<h2>YunoHost Django Example Project v{__version__}</h2>',
|
|
||||||
'<p>Go to <a href="/app_path/admin/">Django Admin</a>.</p>',
|
|
||||||
'<p>Log in to see more information</p>',
|
|
||||||
'<tr><td>User:</td><td>AnonymousUser</td></tr>',
|
|
||||||
'<tr><td>META:</td><td></td></tr>',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
logs.output, ['INFO:django_example.views:DebugView request from user: AnonymousUser']
|
|
||||||
)
|
|
||||||
assert_html_response_snapshot(response, query_selector='#container', validate=False)
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Test as SSO user
|
|
||||||
|
|
||||||
self.client.cookies['SSOwAuthUser'] = 'test'
|
|
||||||
|
|
||||||
with self.assertLogs('django_example') as logs:
|
|
||||||
response = self.client.get(
|
|
||||||
path='/app_path/',
|
|
||||||
HTTP_REMOTE_USER='test',
|
|
||||||
HTTP_AUTH_USER='test',
|
|
||||||
HTTP_AUTHORIZATION='basic dGVzdDp0ZXN0MTIz',
|
|
||||||
secure=True,
|
|
||||||
)
|
|
||||||
self.assert_html_parts(
|
|
||||||
response,
|
|
||||||
parts=(
|
|
||||||
f'<h2>YunoHost Django Example Project v{__version__}</h2>',
|
|
||||||
'<p>Go to <a href="/app_path/admin/">Django Admin</a>.</p>',
|
|
||||||
'<tr><td>User:</td><td>test</td></tr>',
|
|
||||||
f'<tr><td>Process ID:</td><td>{os.getpid()}</td></tr>',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
logs.output, ['INFO:django_example.views:DebugView request from user: test']
|
|
||||||
)
|
|
|
@ -1,143 +0,0 @@
|
||||||
<div id="container">
|
|
||||||
<!-- Header -->
|
|
||||||
<div id="header">
|
|
||||||
<div id="branding">
|
|
||||||
<h1 id="site-name">
|
|
||||||
<a href="/">
|
|
||||||
Debug View
|
|
||||||
</a>
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- END Header -->
|
|
||||||
<div class="breadcrumbs">
|
|
||||||
<a href="/app_path/admin/">
|
|
||||||
Home
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="main" id="main">
|
|
||||||
<div class="content">
|
|
||||||
<!-- Content -->
|
|
||||||
<div class="colM" id="content">
|
|
||||||
<h2>
|
|
||||||
YunoHost Django Example Project v0.1.0rc0
|
|
||||||
</h2>
|
|
||||||
<p>
|
|
||||||
Go to
|
|
||||||
<a href="/app_path/admin/">
|
|
||||||
Django Admin
|
|
||||||
</a>
|
|
||||||
.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Log in to see more information
|
|
||||||
</p>
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<code>
|
|
||||||
settings.SETTINGS_MODULE
|
|
||||||
</code>
|
|
||||||
:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<code>
|
|
||||||
settings
|
|
||||||
</code>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
Env. type:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<code>
|
|
||||||
None
|
|
||||||
</code>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
User:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
AnonymousUser
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
Process User:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
(ID: :)
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
Executable:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
Process ID:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
Python Version:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
Sys prefix:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
Current work dir:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
OS uname:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
OS Environment:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
META:
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<br class="clear"/>
|
|
||||||
</div>
|
|
||||||
<!-- END Content -->
|
|
||||||
<hr/>
|
|
||||||
<p>
|
|
||||||
<a href="https://github.com/eldertek/scovie">
|
|
||||||
github.com/eldertek/scovie
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
|
@ -1,110 +0,0 @@
|
||||||
import difflib
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import tomli
|
|
||||||
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
|
|
||||||
|
|
||||||
import django_yunohost_integration
|
|
||||||
from django_yunohost_integration.test_utils import assert_project_version
|
|
||||||
|
|
||||||
|
|
||||||
PACKAGE_ROOT = Path(__file__).parent.parent
|
|
||||||
|
|
||||||
|
|
||||||
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():
|
|
||||||
upstream_version = django_yunohost_integration.__version__
|
|
||||||
|
|
||||||
assert_project_version(
|
|
||||||
current_version=upstream_version,
|
|
||||||
github_project_url='https://github.com/eldertek/django_yunohost_integration',
|
|
||||||
)
|
|
||||||
|
|
||||||
pyproject_toml_path = Path(PACKAGE_ROOT, 'pyproject.toml')
|
|
||||||
pyproject_toml = tomli.loads(pyproject_toml_path.read_text(encoding='UTF-8'))
|
|
||||||
pyproject_version = pyproject_toml['tool']['poetry']['version']
|
|
||||||
assert pyproject_version.startswith(f'{upstream_version}+ynh')
|
|
||||||
|
|
||||||
# pyproject.toml needs a PEP 440 conform version and used "+ynh"
|
|
||||||
# the YunoHost syntax is: "~ynh", just "convert this:
|
|
||||||
manifest_version = pyproject_version.replace('+', '~')
|
|
||||||
|
|
||||||
assert_file_contains_string(
|
|
||||||
file_path=Path(PACKAGE_ROOT, 'manifest.json'),
|
|
||||||
string=f'"version": "{manifest_version}"',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def poetry_check_output(*args):
|
|
||||||
poerty_bin = shutil.which('poetry')
|
|
||||||
|
|
||||||
output = subprocess.check_output(
|
|
||||||
(poerty_bin,) + args,
|
|
||||||
text=True,
|
|
||||||
env=os.environ,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
cwd=str(PACKAGE_ROOT),
|
|
||||||
)
|
|
||||||
print(output)
|
|
||||||
return output
|
|
||||||
|
|
||||||
|
|
||||||
def test_poetry_check():
|
|
||||||
output = poetry_check_output('check')
|
|
||||||
assert output == 'All set!\n'
|
|
||||||
|
|
||||||
|
|
||||||
def test_requirements_txt():
|
|
||||||
requirements_txt = PACKAGE_ROOT / 'conf' / 'requirements.txt'
|
|
||||||
assert_is_file(requirements_txt)
|
|
||||||
|
|
||||||
output = poetry_check_output('export', '-f', 'requirements.txt')
|
|
||||||
assert 'Warning' not in output
|
|
||||||
|
|
||||||
current_content = requirements_txt.read_text()
|
|
||||||
|
|
||||||
diff = '\n'.join(
|
|
||||||
difflib.unified_diff(
|
|
||||||
current_content.splitlines(),
|
|
||||||
output.splitlines(),
|
|
||||||
fromfile=str(requirements_txt),
|
|
||||||
tofile='FRESH EXPORT',
|
|
||||||
)
|
|
||||||
)
|
|
||||||
print(diff)
|
|
||||||
assert diff == '', f'{requirements_txt} is not up-to-date! (Hint: call: "make update")'
|
|
||||||
|
|
||||||
|
|
||||||
def test_screenshot_filenames():
|
|
||||||
"""
|
|
||||||
https://forum.yunohost.org/t/yunohost-bot-cant-handle-spaces-in-screenshots/19483
|
|
||||||
"""
|
|
||||||
screenshot_path = PACKAGE_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=PACKAGE_ROOT)
|
|
|
@ -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'
|
|
Loading…
Add table
Reference in a new issue