from django.test import RequestFactory, TestCase

from apps.core.context_processors import site_branding
from apps.core.models import SiteBranding


class SiteBrandingModelTests(TestCase):
    def test_load_creates_singleton(self):
        branding = SiteBranding.load()
        self.assertEqual(branding.pk, 1)
        self.assertEqual(SiteBranding.objects.count(), 1)

    def test_icon_style_includes_border_when_enabled(self):
        branding = SiteBranding.load()
        branding.show_border = True
        branding.border_color = "#ffffff"
        branding.border_width = 2
        branding.navbar_icon_size = 30
        style = branding.navbar_icon_style
        self.assertIn("width:30px", style)
        self.assertIn("border:2px solid #ffffff", style)

    def test_icon_style_omits_border_when_disabled(self):
        branding = SiteBranding.load()
        branding.show_border = False
        self.assertNotIn("border:", branding.navbar_icon_style)


class SiteBrandingContextProcessorTests(TestCase):
    def test_site_branding_in_context(self):
        SiteBranding.load()
        request = RequestFactory().get("/")
        ctx = site_branding(request)
        self.assertIn("site_branding", ctx)
        self.assertIsInstance(ctx["site_branding"], SiteBranding)
