# Path: statusboard/models.py
# class Service(TimeStampedModel):
#     name = models.CharField(
#         max_length=255, unique=True, verbose_name=_("name")
#     )
#     description = models.TextField(blank=True, verbose_name=_("description"))
#     href = models.URLField(blank=True)
#     status = models.IntegerField(
#         choices=SERVICE_STATUSES, verbose_name=_("status")
#     )
#     priority = models.PositiveIntegerField(
#         default=0, verbose_name=_("priority")
#     )
#     groups = models.ManyToManyField(
#         "ServiceGroup",
#         blank=True,
#         related_name="services",
#         related_query_name="service",
#         verbose_name=_("groups"),
#     )
#     objects = ServiceManager()
# 
#     def __str__(self):
#         return self.name
# 
#     def __init__(self, *args, **kwargs):
#         super(Service, self).__init__(*args, **kwargs)
#         self._status = self.status
# 
#     def save(self, *args, **kwargs):
#         # When the instance is saved, the original status is updated
#         super(Service, self).save(*args, **kwargs)
#         self._status = self.status
# 
#     class Meta:
#         verbose_name = _("service")
#         verbose_name_plural = _("services")
# 
# Path: statusboard/models.py
# class ServiceGroup(TimeStampedModel):
#     name = models.CharField(
#         max_length=255, unique=True, verbose_name=_("name")
#     )
#     priority = models.PositiveIntegerField(
#         default=0, verbose_name=_("priority")
#     )
#     collapse = models.IntegerField(
#         choices=SERVICEGROUP_COLLAPSE_OPTIONS, default=0
#     )
#     objects = ServiceGroupManager()
# 
#     def worst_service(self):
#         return self.services.all().latest("status")
# 
#     def collapsed(self):
#         """Check if the service group should collapse or not.
# 
#         Return true if a group doesn't have any service."""
#         if self.collapse == 0:
#             return False
#         elif self.collapse == 1:
#             return True
#         else:
#             return not self.services.exclude(status=0).exists()
# 
#     def is_empty_group(self):
#         return not self.services.all().exists()
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("service group")
#         verbose_name_plural = _("service groups")
# 
# Path: statusboard/models.py
# class Incident(TimeStampedModel):
#     name = models.CharField(max_length=255, verbose_name=_("name"))
#     services = models.ManyToManyField(
#         "Service",
#         blank=True,
#         related_name="incidents",
#         related_query_name="incident",
#         verbose_name=_("services"),
#     )
#     occurred = models.DateTimeField(
#         default=timezone.now, verbose_name=_("occurred")
#     )
#     closed = models.BooleanField(default=False)
#     objects = IncidentManager()
# 
#     def updates_by_ctime(self):
#         return self.updates.order_by("-created")
# 
#     def should_be_closed(self):
#         try:
#             return self.updates.latest("created").status == 3
#         except IncidentUpdate.DoesNotExist:
#             return False
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("incident")
#         verbose_name_plural = _("incidents")
# 
# Path: statusboard/models.py
# class IncidentUpdate(TimeStampedModel):
#     incident = models.ForeignKey(
#         Incident,
#         related_name="updates",
#         on_delete=models.deletion.CASCADE,
#         related_query_name="update",
#         verbose_name=_("incident"),
#     )
#     status = models.IntegerField(
#         choices=INCIDENT_STATUSES, verbose_name=_("status")
#     )
#     description = models.TextField(verbose_name=_("description"))
# 
#     def __str__(self):
#         return "Update {} {}".format(self.incident.name, self.modified)
# 
#     class Meta:
#         verbose_name = _("incident update")
#         verbose_name_plural = _("incident updates")
# 
# Path: statusboard/models.py
# class Maintenance(TimeStampedModel):
#     scheduled = models.DateTimeField(verbose_name=_("scheduled start"))
#     name = models.CharField(max_length=255, verbose_name=_("name"))
#     description = models.TextField(verbose_name=_("description"))
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("maintenance")
#         verbose_name_plural = _("maintenances")


from django.test import TestCase
from django.test import Client
from django.contrib.auth.models import User, Permission
from django.utils import timezone
from rest_framework.test import APIClient
from statusboard.models import Service
from statusboard.models import ServiceGroup
from statusboard.models import Incident
from statusboard.models import IncidentUpdate
from statusboard.models import Maintenance
        from statusboard.settings import statusconf
        from django.db.models.signals import post_save
        from statusboard.settings import statusconf
        from django.conf import settings
        from statusboard.settings import statusconf
        from statusboard.settings import statusconf
        from django.urls import reverse, resolve
        from django.urls import reverse
        from django.urls import reverse
                              statusconf.INCIDENT_DAYS_IN_INDEX)

    def test_missing_default(self):

        with self.assertRaises(RuntimeError):
            statusconf.THIS_IS_A_MISSING_APP_SETTING


class TestMaintenanceEdit(TestCase):
    def setUp(self):
        admin = User.objects.create_superuser(username="admin",
                                              password="admin",
                                              email="admin@admin")
        admin.save()

        m = Maintenance(scheduled=timezone.datetime.now(),
                        name="test",
                        description="test")
        m.full_clean()
        m.save()

    def test_edit(self):
        client = Client()
        client.login(username="admin", password="admin")
        dt = timezone.datetime.now()
        client.post('/statusboard/maintenance/1/edit/', {
            'scheduled': dt,
            'name': 'modified name',
            'description': 'modified description',
        })

# Path: statusboard/models.py
# class Service(TimeStampedModel):
#     name = models.CharField(
#         max_length=255, unique=True, verbose_name=_("name")
#     )
#     description = models.TextField(blank=True, verbose_name=_("description"))
#     href = models.URLField(blank=True)
#     status = models.IntegerField(
#         choices=SERVICE_STATUSES, verbose_name=_("status")
#     )
#     priority = models.PositiveIntegerField(
#         default=0, verbose_name=_("priority")
#     )
#     groups = models.ManyToManyField(
#         "ServiceGroup",
#         blank=True,
#         related_name="services",
#         related_query_name="service",
#         verbose_name=_("groups"),
#     )
#     objects = ServiceManager()
# 
#     def __str__(self):
#         return self.name
# 
#     def __init__(self, *args, **kwargs):
#         super(Service, self).__init__(*args, **kwargs)
#         self._status = self.status
# 
#     def save(self, *args, **kwargs):
#         # When the instance is saved, the original status is updated
#         super(Service, self).save(*args, **kwargs)
#         self._status = self.status
# 
#     class Meta:
#         verbose_name = _("service")
#         verbose_name_plural = _("services")
# 
# Path: statusboard/models.py
# class ServiceGroup(TimeStampedModel):
#     name = models.CharField(
#         max_length=255, unique=True, verbose_name=_("name")
#     )
#     priority = models.PositiveIntegerField(
#         default=0, verbose_name=_("priority")
#     )
#     collapse = models.IntegerField(
#         choices=SERVICEGROUP_COLLAPSE_OPTIONS, default=0
#     )
#     objects = ServiceGroupManager()
# 
#     def worst_service(self):
#         return self.services.all().latest("status")
# 
#     def collapsed(self):
#         """Check if the service group should collapse or not.
# 
#         Return true if a group doesn't have any service."""
#         if self.collapse == 0:
#             return False
#         elif self.collapse == 1:
#             return True
#         else:
#             return not self.services.exclude(status=0).exists()
# 
#     def is_empty_group(self):
#         return not self.services.all().exists()
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("service group")
#         verbose_name_plural = _("service groups")
# 
# Path: statusboard/models.py
# class Incident(TimeStampedModel):
#     name = models.CharField(max_length=255, verbose_name=_("name"))
#     services = models.ManyToManyField(
#         "Service",
#         blank=True,
#         related_name="incidents",
#         related_query_name="incident",
#         verbose_name=_("services"),
#     )
#     occurred = models.DateTimeField(
#         default=timezone.now, verbose_name=_("occurred")
#     )
#     closed = models.BooleanField(default=False)
#     objects = IncidentManager()
# 
#     def updates_by_ctime(self):
#         return self.updates.order_by("-created")
# 
#     def should_be_closed(self):
#         try:
#             return self.updates.latest("created").status == 3
#         except IncidentUpdate.DoesNotExist:
#             return False
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("incident")
#         verbose_name_plural = _("incidents")
# 
# Path: statusboard/models.py
# class IncidentUpdate(TimeStampedModel):
#     incident = models.ForeignKey(
#         Incident,
#         related_name="updates",
#         on_delete=models.deletion.CASCADE,
#         related_query_name="update",
#         verbose_name=_("incident"),
#     )
#     status = models.IntegerField(
#         choices=INCIDENT_STATUSES, verbose_name=_("status")
#     )
#     description = models.TextField(verbose_name=_("description"))
# 
#     def __str__(self):
#         return "Update {} {}".format(self.incident.name, self.modified)
# 
#     class Meta:
#         verbose_name = _("incident update")
#         verbose_name_plural = _("incident updates")
# 
# Path: statusboard/models.py
# class Maintenance(TimeStampedModel):
#     scheduled = models.DateTimeField(verbose_name=_("scheduled start"))
#     name = models.CharField(max_length=255, verbose_name=_("name"))
#     description = models.TextField(verbose_name=_("description"))
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("maintenance")
#         verbose_name_plural = _("maintenances")


# Path: tests/tests.py
from django.test import TestCase
from django.test import Client
from django.contrib.auth.models import User, Permission
from django.utils import timezone
from rest_framework.test import APIClient
from statusboard.models import Service
from statusboard.models import ServiceGroup
from statusboard.models import Incident
from statusboard.models import IncidentUpdate
from statusboard.models import Maintenance
        from statusboard.settings import statusconf
        from django.db.models.signals import post_save
        from statusboard.settings import statusconf
        from django.conf import settings
        from statusboard.settings import statusconf
        from statusboard.settings import statusconf
        from django.urls import reverse, resolve
        from django.urls import reverse
        from django.urls import reverse

                              statusconf.INCIDENT_DAYS_IN_INDEX)

    def test_missing_default(self):

        with self.assertRaises(RuntimeError):
            statusconf.THIS_IS_A_MISSING_APP_SETTING


class TestMaintenanceEdit(TestCase):
    def setUp(self):
        admin = User.objects.create_superuser(username="admin",
                                              password="admin",
                                              email="admin@admin")
        admin.save()

        m = Maintenance(scheduled=timezone.datetime.now(),
                        name="test",
                        description="test")
        m.full_clean()
        m.save()

    def test_edit(self):
        client = Client()
        client.login(username="admin", password="admin")
        dt = timezone.datetime.now()
        client.post('/statusboard/maintenance/1/edit/', {
            'scheduled': dt,
            'name': 'modified name',
            'description': 'modified description',
        })

        m = Maintenance.objects.get(pk=1)