# Path: tests/base.py
# class APITestCase(APITestCase):
#     client_class = APIClient
# 
# Path: tests/rest_app/models.py
# class ItemType(LabelModel):
#     name = models.CharField(max_length=10)
#     active = models.NullBooleanField(default=True)
# 
# class DateModel(models.Model):
#     name = models.CharField(max_length=10)
#     date = models.DateTimeField()
#     empty_date = models.DateTimeField(null=True)
# 
#     def __str__(self):
#         return "%s on %s" % (self.name, self.date.date())
# 
# class ChoiceModel(LabelModel):
#     CHOICE_CHOICES = [
#         ('one', 'Choice One'),
#         ('two', 'Choice Two'),
#         ('three', 'Choice Three'),
#     ]
#     name = models.CharField(
#         max_length=10,
#         help_text='Enter Name',
#     )
#     choice = models.CharField(
#         max_length=10,
#         help_text='Pick One',
#         choices=CHOICE_CHOICES,
#     )
# 
#     wq_label_template = "{{name}}: {{choice}}"
# 
# Path: tests/rest_app/serializers.py
# class ChoiceLabelSerializer(ModelSerializer):
#     choice_label = serializers.SerializerMethodField()
# 
#     def get_choice_label(self, instance):
#         return instance.choice.upper()
# 
#     class Meta:
#         model = ChoiceModel
#         fields = "__all__"
# 
# class DateLabelSerializer(ModelSerializer):
#     date_label = serializers.SerializerMethodField()
# 
#     def get_date_label(self, instance):
#         return instance.date.strftime('%B %-d, %Y')
# 
#     class Meta:
#         model = DateModel
#         fields = "__all__"
# 
# class ItemLabelSerializer(ModelSerializer):
#     label = serializers.SerializerMethodField()
#     type_id = serializers.SerializerMethodField()
#     type_label = serializers.SerializerMethodField()
# 
#     def get_label(self, instance):
#         return '%s: %s' % (instance.type.name, instance.name)
# 
#     def get_type_id(self, instance):
#         return 'id-%s' % instance.type_id
# 
#     def get_type_label(self, instance):
#         return instance.type.name.upper()
# 
#     class Meta:
#         model = Item
#         fields = "__all__"


from .base import APITestCase
from rest_framework import status
from tests.rest_app.models import ItemType, DateModel, ChoiceModel
from tests.rest_app.serializers import (
    ChoiceLabelSerializer, DateLabelSerializer, ItemLabelSerializer,
)
        from wq.db.rest import router
        from wq.db.rest import router
        from wq.db.rest import router
        response = self.client.get("/itemtypes/1.json")
        self.assertTrue(status.is_success(response.status_code), response.data)
        self.assertIn('active_label', response.data)
        self.assertEqual(response.data['active_label'], "Yes")

    def test_custom_date_label(self):

        # Default label
        item = DateModel.objects.get(pk=1)
        obj = router.serialize(item)
        self.assertEqual(obj['date_label'], '2015-01-01 06:00 AM')

        # Custom label
        obj = DateLabelSerializer(item).data
        self.assertEqual(obj['date_label'], 'January 1, 2015')

    def test_custom_choice_label(self):

        # Default label
        item = ChoiceModel.objects.get(pk=1)
        obj = router.serialize(item)
        self.assertEqual(obj['choice_label'], 'Choice Two')

        # Custom label
        obj = ChoiceLabelSerializer(item).data
        self.assertEqual(obj['choice_label'], 'TWO')

    def test_custom_fk_label(self):

        # Default labels

# Path: tests/base.py
# class APITestCase(APITestCase):
#     client_class = APIClient
# 
# Path: tests/rest_app/models.py
# class ItemType(LabelModel):
#     name = models.CharField(max_length=10)
#     active = models.NullBooleanField(default=True)
# 
# class DateModel(models.Model):
#     name = models.CharField(max_length=10)
#     date = models.DateTimeField()
#     empty_date = models.DateTimeField(null=True)
# 
#     def __str__(self):
#         return "%s on %s" % (self.name, self.date.date())
# 
# class ChoiceModel(LabelModel):
#     CHOICE_CHOICES = [
#         ('one', 'Choice One'),
#         ('two', 'Choice Two'),
#         ('three', 'Choice Three'),
#     ]
#     name = models.CharField(
#         max_length=10,
#         help_text='Enter Name',
#     )
#     choice = models.CharField(
#         max_length=10,
#         help_text='Pick One',
#         choices=CHOICE_CHOICES,
#     )
# 
#     wq_label_template = "{{name}}: {{choice}}"
# 
# Path: tests/rest_app/serializers.py
# class ChoiceLabelSerializer(ModelSerializer):
#     choice_label = serializers.SerializerMethodField()
# 
#     def get_choice_label(self, instance):
#         return instance.choice.upper()
# 
#     class Meta:
#         model = ChoiceModel
#         fields = "__all__"
# 
# class DateLabelSerializer(ModelSerializer):
#     date_label = serializers.SerializerMethodField()
# 
#     def get_date_label(self, instance):
#         return instance.date.strftime('%B %-d, %Y')
# 
#     class Meta:
#         model = DateModel
#         fields = "__all__"
# 
# class ItemLabelSerializer(ModelSerializer):
#     label = serializers.SerializerMethodField()
#     type_id = serializers.SerializerMethodField()
#     type_label = serializers.SerializerMethodField()
# 
#     def get_label(self, instance):
#         return '%s: %s' % (instance.type.name, instance.name)
# 
#     def get_type_id(self, instance):
#         return 'id-%s' % instance.type_id
# 
#     def get_type_label(self, instance):
#         return instance.type.name.upper()
# 
#     class Meta:
#         model = Item
#         fields = "__all__"


# Path: tests/test_labels.py
from .base import APITestCase
from rest_framework import status
from tests.rest_app.models import ItemType, DateModel, ChoiceModel
from tests.rest_app.serializers import (
    ChoiceLabelSerializer, DateLabelSerializer, ItemLabelSerializer,
)
        from wq.db.rest import router
        from wq.db.rest import router
        from wq.db.rest import router

        response = self.client.get("/itemtypes/1.json")
        self.assertTrue(status.is_success(response.status_code), response.data)
        self.assertIn('active_label', response.data)
        self.assertEqual(response.data['active_label'], "Yes")

    def test_custom_date_label(self):

        # Default label
        item = DateModel.objects.get(pk=1)
        obj = router.serialize(item)
        self.assertEqual(obj['date_label'], '2015-01-01 06:00 AM')

        # Custom label
        obj = DateLabelSerializer(item).data
        self.assertEqual(obj['date_label'], 'January 1, 2015')

    def test_custom_choice_label(self):

        # Default label
        item = ChoiceModel.objects.get(pk=1)
        obj = router.serialize(item)
        self.assertEqual(obj['choice_label'], 'Choice Two')

        # Custom label
        obj = ChoiceLabelSerializer(item).data
        self.assertEqual(obj['choice_label'], 'TWO')

    def test_custom_fk_label(self):

        # Default labels

        item = ItemType.objects.get(pk=1).item_set.get(name='Test 1')