class APITestCase(APITestCase):
    client_class = APIClient class RootModel(LabelModel):
    slug = models.SlugField()
    description = models.TextField()

    wq_label_template = "{{slug}}" class OneToOneModel(LabelModel):
    root = models.OneToOneField(RootModel, models.CASCADE)

    wq_label_template = "onetoonemodel for {{root}}" class ForeignKeyModel(LabelModel):
    root = models.ForeignKey(RootModel, models.CASCADE)

    wq_label_template = "foreignkeymodel for {{root}}" class ExtraModel(LabelModel):
    root = models.ForeignKey(
        RootModel,
        models.CASCADE,
        related_name="extramodels",
    )
    alt_root = models.ForeignKey(
        RootModel,
        models.CASCADE,
        related_name="extramodel_set",
        null=True,
        blank=True,
    )

    wq_label_template = "extramodel for {{root}}" class UserManagedModel(models.Model):
    user = models.ForeignKey("auth.User", models.CASCADE) class Parent(LabelModel):
    name = models.CharField(max_length=10) class Child(LabelModel):
    name = models.CharField(max_length=10)
    parent = models.ForeignKey(Parent, models.CASCADE, related_name="children") class ItemType(LabelModel):
    name = models.CharField(max_length=10)
    active = models.NullBooleanField(default=True) class Item(LabelModel):
    name = models.CharField(max_length=10)
    type = models.ForeignKey(ItemType, models.CASCADE)

    class Meta:
        ordering = ('type', 'name') class SlugModel(LabelModel):
    code = models.SlugField()
    name = models.CharField(max_length=255) class SlugRefParent(LabelModel):
    ref = models.ForeignKey(SlugModel, models.CASCADE)
    name = models.CharField(max_length=255)

    wq_label_template = "{{name}}{{#ref_id}} ({{ref}}){{/ref_id}}" 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}}"
from .base import APITestCase
from rest_framework import status
from tests.rest_app.models import (
    RootModel, OneToOneModel, ForeignKeyModel, ExtraModel, UserManagedModel,
    Parent, Child, ItemType, Item, SlugModel, SlugRefParent, ChoiceModel,
)
from django.contrib.auth.models import User
from django.conf import settings


class TemplateTestCase(APITestCase):
    def setUp(self):
        instance = RootModel.objects.create(
            slug='instance',
            description="Test"
        )
        for cls in OneToOneModel, ForeignKeyModel, ExtraModel:
            cls.objects.create(
                root=instance,
            )
        user = User.objects.create(username="testuser", is_superuser=True)
        self.client.force_authenticate(user)
        UserManagedModel.objects.create(id=1, user=user)
        parent = Parent.objects.create(name="Test", pk=1)
        parent.children.create(name="Test 1")
        parent.children.create(name="Test 2")
        itype = ItemType.objects.create(name="Test", pk=1)
        itype.item_set.create(name="Test 1")
        itype.item_set.create(name="Test 2")

        slugref = SlugModel.objects.create(