Refactor: modernize codebase by replacing deprecated patterns, simplifying imports, and applying type hinting refinements.
This commit is contained in:
parent
55d0d1a105
commit
62e5c054f4
18 changed files with 75 additions and 68 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
|
||||
from functions import Functions, ContainerEnv
|
||||
from functions import ContainerEnv, Functions
|
||||
|
||||
|
||||
def test_container_env_empty():
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import os
|
||||
|
||||
import psutil
|
||||
|
||||
from functions import DaemonizeHAProxy, Functions
|
||||
from functions import DaemonizeHAProxy
|
||||
|
||||
|
||||
def test_daemonize_haproxy():
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
import logging
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
from logging import Logger
|
||||
|
||||
from functions import Functions, loggerEasyHaproxy, loggerCertbot, loggerHaproxy
|
||||
|
||||
from io import StringIO
|
||||
|
||||
from functions import Functions, loggerCertbot, loggerEasyHaproxy, loggerHaproxy
|
||||
|
||||
log_stream = StringIO() # Create StringIO object
|
||||
log_handler = logging.StreamHandler(log_stream)
|
||||
log_formatter = logging.Formatter('%(levelname)s - %(message)s')
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ def test_label_data():
|
|||
|
||||
def test_label_complex_key():
|
||||
label = DockerLabelHandler("till")
|
||||
|
||||
|
||||
data = dict()
|
||||
data["till.definitions"] = "h2"
|
||||
data["till.host.h2"] = "fqdn.example.org"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ CERTBOT_EMAIL = "some@email.com"
|
|||
|
||||
def load_fixture(file):
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/fixtures/" + file, 'r') as content_file:
|
||||
with open(path + "/fixtures/" + file) as content_file:
|
||||
line_list = json.loads("".join(content_file.readlines()))
|
||||
|
||||
return line_list
|
||||
|
|
@ -33,7 +33,7 @@ def test_parser_doesnt_crash():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/no-services.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/no-services.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert [] == cfg.certbot_hosts
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ def test_parser_finds_services():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/services.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/services.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
|
||||
assert {"www.somehost.com.br.pem": "Some PEM Certificate"} == cfg.certs
|
||||
|
|
@ -86,7 +86,7 @@ def test_parser_finds_services_changed_label():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/services.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/services.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
|
||||
assert {"www.somehost.com.br.pem": "Some PEM Certificate"} == cfg.certs
|
||||
|
|
@ -232,21 +232,21 @@ def test_parser_finds_services_raw():
|
|||
|
||||
def test_parser_static():
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/fixtures/static.yml", 'r') as content_file:
|
||||
with open(path + "/fixtures/static.yml") as content_file:
|
||||
parsed = yaml.load(content_file.read(), Loader=yaml.FullLoader)
|
||||
|
||||
cfg = easymapping.HaproxyConfigGenerator(parsed)
|
||||
haproxy_config = cfg.generate()
|
||||
assert len(haproxy_config) > 0
|
||||
|
||||
with open(path + "/expected/static.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/static.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert [] == cfg.certbot_hosts
|
||||
|
||||
|
||||
def test_parser_static_raw():
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/fixtures/static.yml", 'r') as content_file:
|
||||
with open(path + "/fixtures/static.yml") as content_file:
|
||||
parsed = yaml.load(content_file.read(), Loader=yaml.FullLoader)
|
||||
|
||||
expected = {
|
||||
|
|
@ -319,7 +319,7 @@ def test_parser_tcp():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/services-tcp.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/services-tcp.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert [] == cfg.certbot_hosts
|
||||
|
||||
|
|
@ -339,7 +339,7 @@ def test_parser_multi_containers():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/services-multi-containers.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/services-multi-containers.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert [] == cfg.certbot_hosts
|
||||
|
||||
|
|
@ -361,7 +361,7 @@ def test_parser_multiple_hosts():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/services-multiple-hosts.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/services-multiple-hosts.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert [] == cfg.certbot_hosts
|
||||
|
||||
|
|
@ -382,7 +382,7 @@ def test_parser_redirect_ssl():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/services-redirect-ssl.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/services-redirect-ssl.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert [] == cfg.certbot_hosts
|
||||
|
||||
|
|
@ -403,7 +403,7 @@ def test_parser_ssl_strict():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/ssl-strict.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/ssl-strict.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert [] == cfg.certbot_hosts
|
||||
|
||||
|
|
@ -421,7 +421,7 @@ def test_parser_ssl_loose():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/ssl-loose.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/ssl-loose.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert [] == cfg.certbot_hosts
|
||||
|
||||
|
|
@ -444,7 +444,7 @@ def test_parser_ssl_letsencrypt():
|
|||
|
||||
assert len(haproxy_config) > 0
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/services-letsencrypt.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/services-letsencrypt.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert ["test.example.org"] == cfg.certbot_hosts
|
||||
|
||||
|
|
@ -561,7 +561,7 @@ def test_parser_fcgi():
|
|||
assert "172.17.0.3:9000" in haproxy_config
|
||||
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(path + "/expected/services-fcgi.txt", 'r') as expected_file:
|
||||
with open(path + "/expected/services-fcgi.txt") as expected_file:
|
||||
assert expected_file.read() == haproxy_config
|
||||
assert [] == cfg.certbot_hosts
|
||||
|
||||
|
|
|
|||
|
|
@ -7,29 +7,29 @@ Tests all builtin plugins:
|
|||
- DenyPagesPlugin (domain)
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
# Add src to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from plugins import PluginManager, PluginContext
|
||||
from plugins.builtin.cloudflare import CloudflarePlugin
|
||||
import easymapping
|
||||
from plugins import PluginContext, PluginManager
|
||||
from plugins.builtin.cleanup import CleanupPlugin
|
||||
from plugins.builtin.cloudflare import CloudflarePlugin
|
||||
from plugins.builtin.deny_pages import DenyPagesPlugin
|
||||
from plugins.builtin.fastcgi import FastcgiPlugin
|
||||
from plugins.builtin.ip_whitelist import IpWhitelistPlugin
|
||||
from plugins.builtin.jwt_validator import JwtValidatorPlugin
|
||||
from plugins.builtin.fastcgi import FastcgiPlugin
|
||||
import easymapping
|
||||
|
||||
|
||||
def load_fixture(file):
|
||||
"""Load a test fixture"""
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), "fixtures", file)
|
||||
with open(fixture_path, 'r') as content_file:
|
||||
with open(fixture_path) as content_file:
|
||||
line_list = json.loads("".join(content_file.readlines()))
|
||||
return line_list
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ class TestCloudflarePlugin:
|
|||
assert os.path.exists(ip_list_path)
|
||||
|
||||
# Verify file contains correct number of IPs
|
||||
with open(ip_list_path, 'r') as f:
|
||||
with open(ip_list_path) as f:
|
||||
lines = [line.strip() for line in f if line.strip()]
|
||||
assert len(lines) == 22
|
||||
# Verify some known Cloudflare IPs are in the file
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue