root: early spring clean for linting (#8498)

* remove pyright

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* remove pylint

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* replace pylint with ruff

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* ruff fix

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>

* fix UP038

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix DJ012

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix default arg

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix UP031

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* rename stage type to view

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix DJ008

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix remaining upgrade

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix PLR2004

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix B904

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix PLW2901

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix remaining issues

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* prevent ruff from breaking the code

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* stages/prompt: refactor field building

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>

* fix tests

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix lint

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fully remove isort

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Jens L
2024-02-24 18:13:35 +01:00
committed by GitHub
parent 507f9b7ae2
commit b225b0200e
260 changed files with 1058 additions and 1352 deletions

View File

@ -71,7 +71,7 @@ class TestProviderLDAP(SeleniumTestCase):
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50:
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:

View File

@ -1,7 +1,7 @@
"""test OAuth Provider flow"""
from time import sleep
from typing import Any, Optional
from typing import Any
from docker.types import Healthcheck
from selenium.webdriver.common.by import By
@ -25,7 +25,7 @@ class TestProviderOAuth2Github(SeleniumTestCase):
self.client_secret = generate_key()
super().setUp()
def get_container_specs(self) -> Optional[dict[str, Any]]:
def get_container_specs(self) -> dict[str, Any] | None:
"""Setup client grafana container which we test OAuth against"""
return {
"image": "grafana/grafana:7.1.0",

View File

@ -1,7 +1,7 @@
"""test OAuth2 OpenID Provider flow"""
from time import sleep
from typing import Any, Optional
from typing import Any
from docker.types import Healthcheck
from selenium.webdriver.common.by import By
@ -33,7 +33,7 @@ class TestProviderOAuth2OAuth(SeleniumTestCase):
self.app_slug = generate_id(20)
super().setUp()
def get_container_specs(self) -> Optional[dict[str, Any]]:
def get_container_specs(self) -> dict[str, Any] | None:
return {
"image": "grafana/grafana:7.1.0",
"detach": True,

View File

@ -4,7 +4,7 @@ from base64 import b64encode
from dataclasses import asdict
from sys import platform
from time import sleep
from typing import Any, Optional
from typing import Any
from unittest.case import skip, skipUnless
from channels.testing import ChannelsLiveServerTestCase
@ -32,7 +32,7 @@ class TestProviderProxy(SeleniumTestCase):
self.output_container_logs(self.proxy_container)
self.proxy_container.kill()
def get_container_specs(self) -> Optional[dict[str, Any]]:
def get_container_specs(self) -> dict[str, Any] | None:
return {
"image": "traefik/whoami:latest",
"detach": True,
@ -101,7 +101,7 @@ class TestProviderProxy(SeleniumTestCase):
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50:
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:
@ -171,7 +171,7 @@ class TestProviderProxy(SeleniumTestCase):
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50:
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:
@ -212,7 +212,7 @@ class TestProviderProxyConnect(ChannelsLiveServerTestCase):
@reconcile_app("authentik_crypto")
def test_proxy_connectivity(self):
"""Test proxy connectivity over websocket"""
outpost_connection_discovery() # pylint: disable=no-value-for-parameter
outpost_connection_discovery()
proxy: ProxyProvider = ProxyProvider.objects.create(
name=generate_id(),
authorization_flow=Flow.objects.get(
@ -238,7 +238,7 @@ class TestProviderProxyConnect(ChannelsLiveServerTestCase):
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50:
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen and state.version:

View File

@ -66,7 +66,7 @@ class TestProviderRadius(SeleniumTestCase):
# Wait until outpost healthcheck succeeds
healthcheck_retries = 0
while healthcheck_retries < 50:
while healthcheck_retries < 50: # noqa: PLR2004
if len(outpost.state) > 0:
state = outpost.state[0]
if state.last_seen:

View File

@ -1,6 +1,6 @@
"""test LDAP Source"""
from typing import Any, Optional
from typing import Any
from django.db.models import Q
from ldap3.core.exceptions import LDAPSessionTerminatedByServerError
@ -23,7 +23,7 @@ class TestSourceLDAPSamba(SeleniumTestCase):
self.admin_password = generate_key()
super().setUp()
def get_container_specs(self) -> Optional[dict[str, Any]]:
def get_container_specs(self) -> dict[str, Any] | None:
return {
"image": "ghcr.io/beryju/test-samba-dc:latest",
"detach": True,

View File

@ -1,7 +1,7 @@
"""test OAuth Source"""
from time import sleep
from typing import Any, Optional
from typing import Any
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
@ -60,7 +60,7 @@ class TestSourceOAuth1(SeleniumTestCase):
self.source_slug = generate_id()
super().setUp()
def get_container_specs(self) -> Optional[dict[str, Any]]:
def get_container_specs(self) -> dict[str, Any] | None:
return {
"image": "ghcr.io/beryju/oauth1-test-server:v1.1",
"detach": True,

View File

@ -2,7 +2,7 @@
from pathlib import Path
from time import sleep
from typing import Any, Optional
from typing import Any
from docker.models.containers import Container
from docker.types import Healthcheck
@ -69,7 +69,7 @@ class TestSourceOAuth2(SeleniumTestCase):
with open(CONFIG_PATH, "w+", encoding="utf8") as _file:
safe_dump(config, _file)
def get_container_specs(self) -> Optional[dict[str, Any]]:
def get_container_specs(self) -> dict[str, Any] | None:
return {
"image": "ghcr.io/dexidp/dex:v2.28.1",
"detach": True,

View File

@ -1,7 +1,7 @@
"""test SAML Source"""
from time import sleep
from typing import Any, Optional
from typing import Any
from docker.types import Healthcheck
from selenium.webdriver.common.by import By
@ -77,7 +77,7 @@ class TestSourceSAML(SeleniumTestCase):
self.slug = generate_id()
super().setUp()
def get_container_specs(self) -> Optional[dict[str, Any]]:
def get_container_specs(self) -> dict[str, Any] | None:
return {
"image": "kristophjunge/test-saml-idp:1.15",
"detach": True,

View File

@ -3,11 +3,12 @@
import json
import os
import socket
from collections.abc import Callable
from functools import lru_cache, wraps
from os import environ
from sys import stderr
from time import sleep
from typing import Any, Callable, Optional
from typing import Any
from django.apps import apps
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
@ -66,7 +67,7 @@ class DockerTestCase:
return container
sleep(1)
attempt += 1
if attempt >= 30:
if attempt >= 30: # noqa: PLR2004
self.failureException("Container failed to start")
@ -74,7 +75,7 @@ class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
"""StaticLiveServerTestCase which automatically creates a Webdriver instance"""
host = get_local_ip()
container: Optional[Container] = None
container: Container | None = None
wait_timeout: int
user: User
@ -114,7 +115,7 @@ class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
self.wait_for_container(container)
return container
def output_container_logs(self, container: Optional[Container] = None):
def output_container_logs(self, container: Container | None = None):
"""Output the container logs to our STDOUT"""
_container = container or self.container
if IS_CI:
@ -124,7 +125,7 @@ class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
if IS_CI:
print("::endgroup::")
def get_container_specs(self) -> Optional[dict[str, Any]]:
def get_container_specs(self) -> dict[str, Any] | None:
"""Optionally get container specs which will launched on setup, wait for the container to
be healthy, and deleted again on tearDown"""
return None
@ -178,7 +179,7 @@ class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
return f"{self.live_server_url}/if/user/#{view}"
def get_shadow_root(
self, selector: str, container: Optional[WebElement | WebDriver] = None
self, selector: str, container: WebElement | WebDriver | None = None
) -> WebElement:
"""Get shadow root element's inner shadowRoot"""
if not container:
@ -245,12 +246,12 @@ def retry(max_retires=RETRIES, exceptions=None):
nonlocal count
try:
return func(self, *args, **kwargs)
# pylint: disable=catching-non-exception
except tuple(exceptions) as exc:
count += 1
if count > max_retires:
logger.debug("Exceeded retry count", exc=exc, test=self)
# pylint: disable=raising-non-exception
raise exc
logger.debug("Retrying on error", exc=exc, test=self)
self.tearDown()

View File

@ -54,7 +54,7 @@ class OutpostDockerTests(DockerTestCase, ChannelsLiveServerTestCase):
self.ssl_folder = mkdtemp()
self.container = self._start_container(self.ssl_folder)
# Ensure that local connection have been created
outpost_connection_discovery() # pylint: disable=no-value-for-parameter
outpost_connection_discovery()
self.provider: ProxyProvider = ProxyProvider.objects.create(
name="test",
internal_host="http://localhost",

View File

@ -23,7 +23,7 @@ class OutpostKubernetesTests(TestCase):
def setUp(self):
super().setUp()
# Ensure that local connection have been created
outpost_connection_discovery() # pylint: disable=no-value-for-parameter
outpost_connection_discovery()
self.provider: ProxyProvider = ProxyProvider.objects.create(
name="test",
internal_host="http://localhost",

View File

@ -54,7 +54,7 @@ class TestProxyDocker(DockerTestCase, ChannelsLiveServerTestCase):
self.ssl_folder = mkdtemp()
self.container = self._start_container(self.ssl_folder)
# Ensure that local connection have been created
outpost_connection_discovery() # pylint: disable=no-value-for-parameter
outpost_connection_discovery()
self.provider: ProxyProvider = ProxyProvider.objects.create(
name="test",
internal_host="http://localhost",

View File

@ -1,7 +1,5 @@
"""Test Controllers"""
from typing import Optional
import pytest
import yaml
from django.test import TestCase
@ -21,11 +19,11 @@ LOGGER = get_logger()
class TestProxyKubernetes(TestCase):
"""Test Controllers"""
controller: Optional[KubernetesController]
controller: KubernetesController | None
def setUp(self):
# Ensure that local connection have been created
outpost_connection_discovery() # pylint: disable=no-value-for-parameter
outpost_connection_discovery()
self.controller = None
def tearDown(self) -> None: