# 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 Service(models.Model):
#     IAAS = 0
#     PAAS = 1
#     SITE = 2
#     API = 3
#     SSL = 4
#     DOMAIN = 5
#     EMAIL = 6
#     SERVICE_CHOICES = (
#         (IAAS, 'IAAS'),
#         (PAAS, 'PAAS'),
#         (SITE, 'Site'),
#         (API, 'API'),
#         (SSL, 'SSL'),
#         (DOMAIN, 'Domain'),
#         (EMAIL, 'Email'),
#     )
#     name = models.PositiveSmallIntegerField(choices=SERVICE_CHOICES,
#                                             unique=True,
#                                             help_text='name of the service')
#     description = models.CharField(
#         max_length=100,
#         help_text='more information about the service')
# 
#     # XXX this simulate an enum field like django does
#     #     the third field is for the api schema
#     SUNNY = 0
#     CLOUDY = 1
#     FOGGY = 2  # only use by the global status
#     STORMY = 3
#     STATUS_CHOICES = (
#         (SUNNY, 'SUNNY', 'All services are up and running'),
#         (CLOUDY, 'CLOUDY', 'A scheduled maintenance ongoing'),
#         (FOGGY, 'FOGGY', 'Incident which are not impacting our services.'),
#         (STORMY, 'STORMY', 'An incident ongoing'),
#     )
#     DICT_STATUS_CHOICES = dict(map(lambda x: (x[0], x[1]), STATUS_CHOICES))
# 
#     @property
#     def status(self):
#         date_end = Q(date_end__isnull=True) | Q(date_end__gt=now())
#         if self.events.filter(
#                 date_end,
#                 date_start__lte=now(),
#                 category=Event.INCIDENT).exists():
#             return Service.STORMY
#         elif self.events.filter(
#                 date_end,
#                 date_start__lte=now(),
#                 category=Event.MAINTENANCE).exists():
#             return Service.CLOUDY
#         return Service.SUNNY
# 
#     def get_status_display(self):
#         return Service.DICT_STATUS_CHOICES[self.status]
# 
#     def __unicode__(self):
#         return '%s (%s)' % (self.get_name_display(), self.description)


import datetime
from django.utils.timezone import now
from baobab.utils.test import ResourceTestCase
from baobab.backoffice.models import Service as BOService
# -*- coding: utf-8 -*-




class TestServices(ResourceTestCase):
    fixtures = ['db_user', 'db_backoffice']

    url = '/api/services'

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

    def test_02_number_of_elem(self):
        resp = self.api_client.get(self.url)
        data = self.deserialize(resp)
        self.assertEqual(len(data), len(BOService.SERVICE_CHOICES))

    def test_03_key(self):
        resp = self.api_client.get(self.url)
        datas = self.deserialize(resp)
        for data in datas:
            self.assertKeys(data, ['name', 'description', 'status'])

    def test_04_name(self):
        resp = self.api_client.get(self.url)
        datas = self.deserialize(resp)

# 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 Service(models.Model):
#     IAAS = 0
#     PAAS = 1
#     SITE = 2
#     API = 3
#     SSL = 4
#     DOMAIN = 5
#     EMAIL = 6
#     SERVICE_CHOICES = (
#         (IAAS, 'IAAS'),
#         (PAAS, 'PAAS'),
#         (SITE, 'Site'),
#         (API, 'API'),
#         (SSL, 'SSL'),
#         (DOMAIN, 'Domain'),
#         (EMAIL, 'Email'),
#     )
#     name = models.PositiveSmallIntegerField(choices=SERVICE_CHOICES,
#                                             unique=True,
#                                             help_text='name of the service')
#     description = models.CharField(
#         max_length=100,
#         help_text='more information about the service')
# 
#     # XXX this simulate an enum field like django does
#     #     the third field is for the api schema
#     SUNNY = 0
#     CLOUDY = 1
#     FOGGY = 2  # only use by the global status
#     STORMY = 3
#     STATUS_CHOICES = (
#         (SUNNY, 'SUNNY', 'All services are up and running'),
#         (CLOUDY, 'CLOUDY', 'A scheduled maintenance ongoing'),
#         (FOGGY, 'FOGGY', 'Incident which are not impacting our services.'),
#         (STORMY, 'STORMY', 'An incident ongoing'),
#     )
#     DICT_STATUS_CHOICES = dict(map(lambda x: (x[0], x[1]), STATUS_CHOICES))
# 
#     @property
#     def status(self):
#         date_end = Q(date_end__isnull=True) | Q(date_end__gt=now())
#         if self.events.filter(
#                 date_end,
#                 date_start__lte=now(),
#                 category=Event.INCIDENT).exists():
#             return Service.STORMY
#         elif self.events.filter(
#                 date_end,
#                 date_start__lte=now(),
#                 category=Event.MAINTENANCE).exists():
#             return Service.CLOUDY
#         return Service.SUNNY
# 
#     def get_status_display(self):
#         return Service.DICT_STATUS_CHOICES[self.status]
# 
#     def __unicode__(self):
#         return '%s (%s)' % (self.get_name_display(), self.description)


# Path: baobab/apirest/tests/test_services.py
import datetime
from django.utils.timezone import now
from baobab.utils.test import ResourceTestCase
from baobab.backoffice.models import Service as BOService

# -*- coding: utf-8 -*-




class TestServices(ResourceTestCase):
    fixtures = ['db_user', 'db_backoffice']

    url = '/api/services'

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

    def test_02_number_of_elem(self):
        resp = self.api_client.get(self.url)
        data = self.deserialize(resp)
        self.assertEqual(len(data), len(BOService.SERVICE_CHOICES))

    def test_03_key(self):
        resp = self.api_client.get(self.url)
        datas = self.deserialize(resp)
        for data in datas:
            self.assertKeys(data, ['name', 'description', 'status'])

    def test_04_name(self):
        resp = self.api_client.get(self.url)
        datas = self.deserialize(resp)

        names = [val for _, val in BOService.SERVICE_CHOICES]