update tests

This commit is contained in:
JensDiemer 2022-04-02 20:35:22 +02:00
parent 777bd7a449
commit c8ae8cbb22
4 changed files with 40 additions and 34 deletions

View file

@ -5,7 +5,7 @@
"description": {
"en": "Web based FritzBox management using Python/Django."
},
"version": "0.0.2.rc0~ynh1",
"version": "0.0.2.rc1~ynh1",
"url": "https://github.com/jedie/django-fritzconnection",
"upstream": {
"license": "GPL-3.0",

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "django-fritzconnection_ynh"
version = "0.0.2.rc0~ynh1"
version = "0.0.2.rc1~ynh1"
description = "Test django-fritzconnection_ynh via local_test.py"
authors = ["JensDiemer <git@jensdiemer.de>"]
license = "GPL"
@ -39,7 +39,7 @@ build-backend = "poetry.core.masonry.api"
[tool.darker]
src = ['.']
revision = "origin/master..."
line_length = 120
line_length = 100
verbose = true
skip_string_normalization = true
diff = false
@ -53,14 +53,14 @@ log_level = "INFO"
[tool.flynt]
line_length = 120
line_length = 100
[tool.isort]
# https://pycqa.github.io/isort/docs/configuration/config_files/#pyprojecttoml-preferred-format
atomic=true
profile='black'
line_length=120
line_length=100
skip_glob=["*/htmlcov/*","*/migrations/*"]
known_first_party=["djfritz","djfritz_project","djfritz_tests"]
lines_after_imports=2

View file

@ -1,6 +1,5 @@
from pathlib import Path
from axes.models import AccessLog
from bx_django_utils.test_utils.html_assertion import HtmlAssertionMixin
from django.conf import LazySettings, settings
from django.contrib.auth.models import User
@ -11,7 +10,7 @@ from django.urls.base import reverse
from django_yunohost_integration.test_utils import generate_basic_auth
from django_yunohost_integration.views import request_media_debug_view
import inventory
import djfritz
@override_settings(DEBUG=False)
@ -40,18 +39,12 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
assert settings.ROOT_URLCONF == 'urls'
def test_urls(self):
assert reverse('admin:index') == '/app_path/'
assert reverse('admin:index') == '/app_path/admin/'
# The django_yunohost_integration debug view should not be available:
with self.assertRaises(NoReverseMatch):
reverse(request_media_debug_view)
# 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):
# SecurityMiddleware should redirects all non-HTTPS requests to HTTPS:
assert settings.SECURE_SSL_REDIRECT is True
@ -64,7 +57,16 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
)
response = self.client.get('/app_path/', secure=True)
self.assertRedirects(response, expected_url='/app_path/login/?next=/app_path/', fetch_redirect_response=False)
self.assertRedirects(
response, expected_url='/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=/app_path/admin/',
fetch_redirect_response=False,
)
@override_settings(SECURE_SSL_REDIRECT=False)
def test_create_unknown_user(self):
@ -73,7 +75,7 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
self.client.cookies['SSOwAuthUser'] = 'test'
response = self.client.get(
path='/app_path/',
path='/app_path/admin/',
HTTP_REMOTE_USER='test',
HTTP_AUTH_USER='test',
HTTP_AUTHORIZATION='basic dGVzdDp0ZXN0MTIz',
@ -90,7 +92,10 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
self.assert_html_parts(
response,
parts=(
f'<title>Site administration | django-fritzconnection v{inventory.__version__}</title>',
(
'<title>Site administration | django-fritzconnection'
f' v{djfritz.__version__}</title>'
),
'<strong>test</strong>',
),
)
@ -98,12 +103,11 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
@override_settings(SECURE_SSL_REDIRECT=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/',
path='/app_path/admin/',
HTTP_REMOTE_USER='test',
HTTP_AUTH_USER='foobar', # <<< wrong user name
HTTP_AUTHORIZATION='basic dGVzdDp0ZXN0MTIz',
@ -116,19 +120,16 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
assert user.is_staff is True # Set by: django_yunohost_integration
assert user.is_superuser is False
assert AccessLog.objects.count() == 1
assert response.status_code == 403 # Forbidden
@override_settings(SECURE_SSL_REDIRECT=False)
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/',
path='/app_path/admin/',
HTTP_REMOTE_USER='test',
HTTP_AUTH_USER='test',
HTTP_AUTHORIZATION='basic dGVzdDp0ZXN0MTIz',
@ -141,8 +142,6 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
assert user.is_staff is True # Set by: django_yunohost_integration
assert user.is_superuser is False
assert AccessLog.objects.count() == 1
assert response.status_code == 403 # Forbidden
@override_settings(SECURE_SSL_REDIRECT=False)
@ -152,10 +151,12 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
self.client.cookies['SSOwAuthUser'] = 'test'
response = self.client.get(
path='/app_path/',
path='/app_path/admin/',
HTTP_REMOTE_USER='test',
HTTP_AUTH_USER='test',
HTTP_AUTHORIZATION=generate_basic_auth(username='foobar', password='test123'), # <<< wrong user name
HTTP_AUTHORIZATION=generate_basic_auth(
username='foobar', password='test123'
), # <<< wrong user name
)
assert User.objects.count() == 1
@ -165,6 +166,4 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
assert user.is_staff is True # Set by: django_yunohost_integration
assert user.is_superuser is False
assert AccessLog.objects.count() == 1
assert response.status_code == 403 # Forbidden

View file

@ -6,7 +6,7 @@ from pathlib import Path
from bx_py_utils.path import assert_is_file
import inventory
import djfritz
PACKAGE_ROOT = Path(__file__).parent.parent
@ -21,10 +21,14 @@ def assert_file_contains_string(file_path, string):
def test_version():
version = inventory.__version__
version = djfritz.__version__
assert_file_contains_string(file_path=Path(PACKAGE_ROOT, 'pyproject.toml'), string=f'version = "{version}~ynh')
assert_file_contains_string(file_path=Path(PACKAGE_ROOT, 'manifest.json'), string=f'"version": "{version}~ynh')
assert_file_contains_string(
file_path=Path(PACKAGE_ROOT, 'pyproject.toml'), string=f'version = "{version}~ynh'
)
assert_file_contains_string(
file_path=Path(PACKAGE_ROOT, 'manifest.json'), string=f'"version": "{version}~ynh'
)
def poetry_check_output(*args):
@ -57,7 +61,10 @@ def test_requirements_txt():
diff = '\n'.join(
difflib.unified_diff(
current_content.splitlines(), output.splitlines(), fromfile=str(requirements_txt), tofile='FRESH EXPORT'
current_content.splitlines(),
output.splitlines(),
fromfile=str(requirements_txt),
tofile='FRESH EXPORT',
)
)
print(diff)