# Path: mqueue/tests/base.py
# class MqueueBaseTest(TestCase):
#     user: User
# 
#     def setUp(self):
#         self.factory = RequestFactory()
#         self.maxDiff = None
#         self.user = User.objects.create_user(  # type: ignore
#             "myuser", "myemail@test.com", "super_password"
#         )
# 
#     def reset(self):
#         for event in MEvent.objects.all():
#             event.delete()
# 
#     def create_mevent(
#         self,
#         name: str = "M event",
#         url: str = "/",
#         obj_pk: int = 1,
#         notes: str = "Notes",
#     ):
#         self._content_type = ContentType.objects.get_for_model(User)
#         return MEvent.objects.create(
#             name=name,
#             url=url,
#             obj_pk=obj_pk,
#             notes=notes,
#             model=User,
#             content_type=self._content_type,
#         )
# 
# Path: mqueue/watchers.py
# def send_msg(objclass, instance, event_str):
#     obj_name = get_object_name(instance, instance)
#     # try to get the admin url
#     admin_url = get_admin_url(instance)
#     event_class = instance.__class__.__name__ + " " + event_str
#     # create event
#     MEvent.objects.create(
#         model=instance.__class__,
#         name=obj_name,
#         obj_pk=instance.pk,
#         user=instance,
#         url=get_url(instance),
#         admin_url=admin_url,
#         event_class=event_class,
#     )
#     return
# 
# def login_action(sender, user, **kwargs):
#     send_msg(sender, user, "login")
# 
# def logout_action(sender, user, **kwargs):
#     send_msg(sender, user, "logout")
# 
# def login_failed(sender, credentials, **kwargs):
#     # create event
#     name = "Login failed"
#     event_class = "Warning"
#     MEvent.objects.create(name=name, event_class=event_class, notes=credentials)
#     return
# 
# def init_watchers(w):
#     for w in WATCH:
#         if w == "login":
#             user_logged_in.connect(login_action)
#         elif w == "logout":
#             user_logged_out.connect(logout_action)
#         elif w == "login_failed":
#             user_login_failed.connect(login_failed)
#     return


from unittest.mock import patch
from .base import MqueueBaseTest
from mqueue.watchers import (
    send_msg,
    login_action,
    logout_action,
    login_failed,
    init_watchers,
)


class MqueueTestWatchers(MqueueBaseTest):
    def test_send_msg(self):
        instance = self.user
        send_msg("test", instance, "Event string")


# Path: mqueue/tests/base.py
# class MqueueBaseTest(TestCase):
#     user: User
# 
#     def setUp(self):
#         self.factory = RequestFactory()
#         self.maxDiff = None
#         self.user = User.objects.create_user(  # type: ignore
#             "myuser", "myemail@test.com", "super_password"
#         )
# 
#     def reset(self):
#         for event in MEvent.objects.all():
#             event.delete()
# 
#     def create_mevent(
#         self,
#         name: str = "M event",
#         url: str = "/",
#         obj_pk: int = 1,
#         notes: str = "Notes",
#     ):
#         self._content_type = ContentType.objects.get_for_model(User)
#         return MEvent.objects.create(
#             name=name,
#             url=url,
#             obj_pk=obj_pk,
#             notes=notes,
#             model=User,
#             content_type=self._content_type,
#         )
# 
# Path: mqueue/watchers.py
# def send_msg(objclass, instance, event_str):
#     obj_name = get_object_name(instance, instance)
#     # try to get the admin url
#     admin_url = get_admin_url(instance)
#     event_class = instance.__class__.__name__ + " " + event_str
#     # create event
#     MEvent.objects.create(
#         model=instance.__class__,
#         name=obj_name,
#         obj_pk=instance.pk,
#         user=instance,
#         url=get_url(instance),
#         admin_url=admin_url,
#         event_class=event_class,
#     )
#     return
# 
# def login_action(sender, user, **kwargs):
#     send_msg(sender, user, "login")
# 
# def logout_action(sender, user, **kwargs):
#     send_msg(sender, user, "logout")
# 
# def login_failed(sender, credentials, **kwargs):
#     # create event
#     name = "Login failed"
#     event_class = "Warning"
#     MEvent.objects.create(name=name, event_class=event_class, notes=credentials)
#     return
# 
# def init_watchers(w):
#     for w in WATCH:
#         if w == "login":
#             user_logged_in.connect(login_action)
#         elif w == "logout":
#             user_logged_out.connect(logout_action)
#         elif w == "login_failed":
#             user_login_failed.connect(login_failed)
#     return


# Path: mqueue/tests/test_watchers.py
from unittest.mock import patch
from .base import MqueueBaseTest
from mqueue.watchers import (
    send_msg,
    login_action,
    logout_action,
    login_failed,
    init_watchers,
)



class MqueueTestWatchers(MqueueBaseTest):
    def test_send_msg(self):
        instance = self.user
        send_msg("test", instance, "Event string")


    def test_login_action(self):