# Path: baobab/utils/test.py
# class ResourceTestCase(TastypieResourceTestCase):
# 
#     def setUp(self, *args, **kwargs):
#         super(ResourceTestCase, self).setUp(*args, **kwargs)
#         self._mock = []
# 
#         cls_path = 'baobab.socialnetwork.base.LOG'
#         self._mock.append(patch(cls_path, new_callable=MockLOG))
#         self.log = self._mock[0].start()
# 
#         cls_path = 'baobab.socialnetwork.base.SocialNetworkBase.__subclasses__'
#         self._mock.append(patch(cls_path, return_value=[MockSN, ]))
#         self._mock[1].start()
# 
#     def tearDown(self, *args, **kwargs):
#         super(ResourceTestCase, self).tearDown(*args, **kwargs)
#         for mock in self._mock:
#             mock.stop()
# 
# Path: baobab/backoffice/models.py
# class Event(models.Model):
#     objects = EventManager()  # override the default manager
# 
#     # Used for <pubDate> in RSS Feed
#     last_update = models.DateTimeField(default=now)
# 
#     date_start = models.DateTimeField(default=now)
#     date_end = models.DateTimeField(null=True, blank=True, default=None)
#     estimate_date_end = models.DateTimeField()
#     duration = models.PositiveIntegerField(help_text='Duration (in minutes)')
# 
#     # XXX to remove at the next release
#     title = models.CharField(max_length=255,
#                              help_text='A short description of the event')
# 
#     # XXX to remove at the next release
#     summary = models.TextField(null=True, blank=True, default=None)
#     services = models.ManyToManyField('Service', related_name='events',
#                                       blank=True)
#     MAINTENANCE = 0
#     INCIDENT = 1
#     CATEGORY_CHOICES = (
#         (MAINTENANCE, 'Maintenance'),
#         (INCIDENT, 'Incident'),
#     )
#     category = models.PositiveSmallIntegerField(choices=CATEGORY_CHOICES,
#                                                 help_text='Type of the Event')
#     msg = models.CharField('Social Network', max_length=255,
#                            null=True, blank=True, default=None)
# 
#     def __unicode__(self):
#         return self.title
# 
#     def save(self, *args, **kwargs):
#         if not self.id and self.date_end and self.date_end > now():
#             # create an event with a date_end in future: need to be converted
#             # to the estimate_date_end
#             delta = self.date_end - self.date_start
#             self.duration = delta.total_seconds() / 60
#             self.date_end = None
#         if self.date_end:
#             delta = self.date_end - self.date_start
#             self.duration = delta.total_seconds() / 60
#             if not self.estimate_date_end or \
#                self.date_start >= self.estimate_date_end:
#                 self.estimate_date_end = self.date_end
#             if self.date_end <= now():
#                 if self.eventlogs.exists() and \
#                    self.eventlogs.all()[0].date < self.date_end:
#                     self.last_update = self.date_end
#         else:
#             delta = timedelta(minutes=self.duration)
#             self.estimate_date_end = self.date_start + delta
#         super(Event, self).save(*args, **kwargs)
# 
#     class Meta:
#         # XXX avoid the admin to override the right order: see EventQuerySet
#         ordering = ['id', 'pk']


from datetime import timedelta
from django.utils.timezone import now
from tastypie.http import HttpMethodNotAllowed
from baobab.utils.test import ResourceTestCase
from baobab.backoffice.models import Event as BOEvent
        event.save()
        event.services.add(*services)

        def _end_event(event=event):
            event.date_end = now()
            event.save()

        event.end = _end_event
        return event

    def test_01_get_list(self):
        resp = self.api_client.get(self.url)
        self.assertValidJSONResponse(resp)

    def test_02_get_detail(self):
        resp = self.api_client.get('%s/1' % self.url)
        self.assertEqual(type(resp), HttpMethodNotAllowed)

    def test_03_OK(self):
        resp = self.api_client.get(self.url)
        data = self.deserialize(resp)
        self.assertEqual(data, {'status': u'SUNNY'})

    def test_04_CLOUDY(self):
        event = self._create_event(10, [1, 2], BOEvent.MAINTENANCE)
        resp = self.api_client.get(self.url)
        data = self.deserialize(resp)
        self.assertEqual(data, {'status': u'CLOUDY'})

    def test_05_STORMY(self):

# Path: baobab/utils/test.py
# class ResourceTestCase(TastypieResourceTestCase):
# 
#     def setUp(self, *args, **kwargs):
#         super(ResourceTestCase, self).setUp(*args, **kwargs)
#         self._mock = []
# 
#         cls_path = 'baobab.socialnetwork.base.LOG'
#         self._mock.append(patch(cls_path, new_callable=MockLOG))
#         self.log = self._mock[0].start()
# 
#         cls_path = 'baobab.socialnetwork.base.SocialNetworkBase.__subclasses__'
#         self._mock.append(patch(cls_path, return_value=[MockSN, ]))
#         self._mock[1].start()
# 
#     def tearDown(self, *args, **kwargs):
#         super(ResourceTestCase, self).tearDown(*args, **kwargs)
#         for mock in self._mock:
#             mock.stop()
# 
# Path: baobab/backoffice/models.py
# class Event(models.Model):
#     objects = EventManager()  # override the default manager
# 
#     # Used for <pubDate> in RSS Feed
#     last_update = models.DateTimeField(default=now)
# 
#     date_start = models.DateTimeField(default=now)
#     date_end = models.DateTimeField(null=True, blank=True, default=None)
#     estimate_date_end = models.DateTimeField()
#     duration = models.PositiveIntegerField(help_text='Duration (in minutes)')
# 
#     # XXX to remove at the next release
#     title = models.CharField(max_length=255,
#                              help_text='A short description of the event')
# 
#     # XXX to remove at the next release
#     summary = models.TextField(null=True, blank=True, default=None)
#     services = models.ManyToManyField('Service', related_name='events',
#                                       blank=True)
#     MAINTENANCE = 0
#     INCIDENT = 1
#     CATEGORY_CHOICES = (
#         (MAINTENANCE, 'Maintenance'),
#         (INCIDENT, 'Incident'),
#     )
#     category = models.PositiveSmallIntegerField(choices=CATEGORY_CHOICES,
#                                                 help_text='Type of the Event')
#     msg = models.CharField('Social Network', max_length=255,
#                            null=True, blank=True, default=None)
# 
#     def __unicode__(self):
#         return self.title
# 
#     def save(self, *args, **kwargs):
#         if not self.id and self.date_end and self.date_end > now():
#             # create an event with a date_end in future: need to be converted
#             # to the estimate_date_end
#             delta = self.date_end - self.date_start
#             self.duration = delta.total_seconds() / 60
#             self.date_end = None
#         if self.date_end:
#             delta = self.date_end - self.date_start
#             self.duration = delta.total_seconds() / 60
#             if not self.estimate_date_end or \
#                self.date_start >= self.estimate_date_end:
#                 self.estimate_date_end = self.date_end
#             if self.date_end <= now():
#                 if self.eventlogs.exists() and \
#                    self.eventlogs.all()[0].date < self.date_end:
#                     self.last_update = self.date_end
#         else:
#             delta = timedelta(minutes=self.duration)
#             self.estimate_date_end = self.date_start + delta
#         super(Event, self).save(*args, **kwargs)
# 
#     class Meta:
#         # XXX avoid the admin to override the right order: see EventQuerySet
#         ordering = ['id', 'pk']


# Path: baobab/apirest/tests/test_status.py
from datetime import timedelta
from django.utils.timezone import now
from tastypie.http import HttpMethodNotAllowed
from baobab.utils.test import ResourceTestCase
from baobab.backoffice.models import Event as BOEvent

        event.save()
        event.services.add(*services)

        def _end_event(event=event):
            event.date_end = now()
            event.save()

        event.end = _end_event
        return event

    def test_01_get_list(self):
        resp = self.api_client.get(self.url)
        self.assertValidJSONResponse(resp)

    def test_02_get_detail(self):
        resp = self.api_client.get('%s/1' % self.url)
        self.assertEqual(type(resp), HttpMethodNotAllowed)

    def test_03_OK(self):
        resp = self.api_client.get(self.url)
        data = self.deserialize(resp)
        self.assertEqual(data, {'status': u'SUNNY'})

    def test_04_CLOUDY(self):
        event = self._create_event(10, [1, 2], BOEvent.MAINTENANCE)
        resp = self.api_client.get(self.url)
        data = self.deserialize(resp)
        self.assertEqual(data, {'status': u'CLOUDY'})

    def test_05_STORMY(self):

        event = self._create_event(10, [1, 2], BOEvent.INCIDENT)