# (c) cavaliba.com - tests / sirene / reopen

from django.test import TestCase

from app_data.data import Instance
from app_sirene.notify import reopen_message
from tests import helper


class SireneReopenTest(TestCase):
    def setUp(self):

        helper.add_instance(
            classname="sirene_message",
            keyname="msg01",
            fields={
                "is_enabled": "false",
                "category": "Incident",
                "severity": "Major",
                "content": "test content",
            },
        )

    def test_reopen_sets_updated_by(self):

        instance = Instance.from_keyname(classname="sirene_message", keyname="msg01", expand=True)
        result = reopen_message(instance=instance, aaa={"username": "operator01"})
        self.assertTrue(result)

        instance = Instance.from_keyname(classname="sirene_message", keyname="msg01", expand=True)
        self.assertTrue(instance.is_enabled)
        self.assertEqual(instance.fields["updated_by"].value[0], "operator01")

    def test_reopen_without_aaa_sets_auto(self):

        instance = Instance.from_keyname(classname="sirene_message", keyname="msg01", expand=True)
        result = reopen_message(instance=instance)
        self.assertTrue(result)

        instance = Instance.from_keyname(classname="sirene_message", keyname="msg01", expand=True)
        self.assertEqual(instance.fields["updated_by"].value[0], "auto")
