mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Added base_sld_domains filter
This commit is contained in:
48
tests/unit/test_domain_filters_all_domains.py
Normal file
48
tests/unit/test_domain_filters_all_domains.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import unittest
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Ensure filter_plugins directory is on the path
|
||||
sys.path.insert(
|
||||
0,
|
||||
os.path.abspath(os.path.join(os.path.dirname(__file__), '../../filter_plugins'))
|
||||
)
|
||||
|
||||
from domain_filters import FilterModule
|
||||
|
||||
class TestGenerateAllDomains(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.filter = FilterModule().generate_all_domains
|
||||
|
||||
def test_simple_string_values(self):
|
||||
domains = {'app': 'example.com'}
|
||||
result = self.filter(domains)
|
||||
expected = ['example.com', 'www.example.com']
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_list_and_dict_values(self):
|
||||
domains = {
|
||||
'app1': ['one.com', 'two.com'],
|
||||
'app2': {'x': 'x.com', 'y': 'y.com'}
|
||||
}
|
||||
result = self.filter(domains)
|
||||
expected = sorted([
|
||||
'one.com', 'two.com', 'x.com', 'y.com',
|
||||
'www.one.com', 'www.two.com', 'www.x.com', 'www.y.com'
|
||||
])
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_include_www_false(self):
|
||||
domains = {'app': 'no-www.com'}
|
||||
result = self.filter(domains, include_www=False)
|
||||
self.assertEqual(result, ['no-www.com'])
|
||||
|
||||
def test_deduplicate_and_sort(self):
|
||||
domains = {
|
||||
'a': 'dup.com',
|
||||
'b': 'dup.com',
|
||||
'c': ['b.com', 'a.com'],
|
||||
}
|
||||
result = self.filter(domains)
|
||||
expected = ['a.com', 'b.com', 'dup.com', 'www.a.com', 'www.b.com', 'www.dup.com']
|
||||
self.assertEqual(result, expected)
|
49
tests/unit/test_domain_filters_base_sld_domains.py
Normal file
49
tests/unit/test_domain_filters_base_sld_domains.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import unittest
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Ensure filter_plugins directory is on the path
|
||||
sys.path.insert(
|
||||
0,
|
||||
os.path.abspath(os.path.join(os.path.dirname(__file__), '../../filter_plugins'))
|
||||
)
|
||||
|
||||
from domain_filters import FilterModule
|
||||
|
||||
class TestGenerateBaseSldDomains(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.filter = FilterModule().generate_base_sld_domains
|
||||
|
||||
def test_simple_string_and_redirect(self):
|
||||
domains = {'app': 'sub.example.com'}
|
||||
redirects = [{'source': 'alias.example.com'}]
|
||||
result = self.filter(domains, redirects)
|
||||
self.assertEqual(result, ['example.com'])
|
||||
|
||||
def test_without_redirect_mappings(self):
|
||||
domains = {
|
||||
'a': 'a.co',
|
||||
'b': ['b.co', 'sub.c.co'],
|
||||
'c': {'x': 'x.co'}
|
||||
}
|
||||
result = self.filter(domains, None)
|
||||
self.assertEqual(result, ['a.co', 'b.co', 'c.co', 'x.co'])
|
||||
|
||||
def test_redirect_list_sources(self):
|
||||
domains = {'app': 'app.domain.org'}
|
||||
redirects = [{'source': ['alias.domain.org', 'deep.sub.example.net']}]
|
||||
result = self.filter(domains, redirects)
|
||||
self.assertEqual(result, ['domain.org', 'example.net'])
|
||||
|
||||
def test_duplicate_entries_and_sorting(self):
|
||||
domains = {
|
||||
'x': ['one.com', 'sub.one.com'],
|
||||
'y': 'two.com',
|
||||
'z': {'k': 'one.com'}
|
||||
}
|
||||
redirects = [{'source': 'deep.two.com'}]
|
||||
result = self.filter(domains, redirects)
|
||||
self.assertEqual(result, ['one.com', 'two.com'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@@ -1,52 +0,0 @@
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from filter_plugins.generate_all_domains import FilterModule
|
||||
|
||||
@pytest.fixture
|
||||
def generate_filter():
|
||||
"""
|
||||
Fixture to return the generate_all_domains filter function.
|
||||
"""
|
||||
fm = FilterModule()
|
||||
return fm.generate_all_domains
|
||||
|
||||
def test_simple_string_values(generate_filter):
|
||||
domains = {'app': 'example.com'}
|
||||
result = generate_filter(domains)
|
||||
# Expect original and www-prefixed, deduped and sorted
|
||||
expected = ['example.com', 'www.example.com']
|
||||
assert result == expected
|
||||
|
||||
def test_list_and_dict_values(generate_filter):
|
||||
domains = {
|
||||
'app1': ['one.com', 'two.com'],
|
||||
'app2': {'x': 'x.com', 'y': 'y.com'}
|
||||
}
|
||||
result = generate_filter(domains)
|
||||
expected = sorted([
|
||||
'one.com', 'two.com', 'x.com', 'y.com',
|
||||
'www.one.com', 'www.two.com', 'www.x.com', 'www.y.com'
|
||||
])
|
||||
assert result == expected
|
||||
|
||||
def test_include_www_false(generate_filter):
|
||||
domains = {'app': 'no-www.com'}
|
||||
result = generate_filter(domains, include_www=False)
|
||||
# Only the original domain
|
||||
assert result == ['no-www.com']
|
||||
|
||||
def test_deduplicate_and_sort(generate_filter):
|
||||
domains = {
|
||||
'a': 'dup.com',
|
||||
'b': 'dup.com',
|
||||
'c': ['b.com', 'a.com'],
|
||||
}
|
||||
result = generate_filter(domains)
|
||||
# Should contain unique domains sorted alphabetically
|
||||
expected = ['a.com', 'b.com', 'dup.com', 'www.a.com', 'www.b.com', 'www.dup.com']
|
||||
assert result == expected
|
||||
|
||||
if __name__ == '__main__':
|
||||
pytest.main()
|
Reference in New Issue
Block a user