Add additional configuration and tests
This commit is contained in:
@@ -7,4 +7,34 @@ from .middleware import load_backing_class
|
||||
class BackerConfigTestCase(TestCase):
|
||||
def test_config_produces_object(self):
|
||||
obj = load_backing_class("ai_blocker.ualist_backers.ConfigBackedUAList")
|
||||
self.assertIs(obj, ConfigBackedUAList)
|
||||
self.assertIs(obj, ConfigBackedUAList)
|
||||
|
||||
|
||||
class BackerTestCase(TestCase):
|
||||
def test_config_backer_produces_list(self):
|
||||
backer = ConfigBackedUAList()
|
||||
self.assertIsInstance(backer.get_ua_list(), list)
|
||||
|
||||
def test_config_backer_reads_config(self):
|
||||
backer = ConfigBackedUAList()
|
||||
from django.conf import settings
|
||||
|
||||
if not settings.configured:
|
||||
raise Exception("Django settings not configured")
|
||||
|
||||
if not hasattr(settings, "AI_BLOCKER_CONF"):
|
||||
raise Exception("AI_BLOCKER_CONF not configured")
|
||||
|
||||
if not "ua_list" in settings.AI_BLOCKER_CONF or not len(settings.AI_BLOCKER_CONF['ua_list']) > 0:
|
||||
raise Exception("AI_BLOCKER_CONF.ua_list not configured")
|
||||
|
||||
self.assertGreater(len(backer.get_ua_list()), 0)
|
||||
|
||||
def test_user_agents_match(self):
|
||||
good_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1546.72 Googlebot"
|
||||
bad_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
|
||||
|
||||
backer = ConfigBackedUAList()
|
||||
|
||||
self.assertTrue(good_agent in backer)
|
||||
self.assertFalse(bad_agent in backer)
|
||||
Reference in New Issue
Block a user