# Path: tests/base.py
# class APITestCase(APITestCase):
#     client_class = APIClient
# 
# Path: tests/naturalkey_app/models.py
# class ModelWithNaturalKey(models.Model):
#     key = models.ForeignKey(NaturalKeyChild, models.CASCADE)
#     note = models.TextField()
# 
#     def __str__(self):
#         return "%s: %s" % (self.key, self.note)


from .base import APITestCase
from rest_framework import status
from django.contrib.auth.models import User
from tests.naturalkey_app.models import ModelWithNaturalKey
import json
class NaturalKeyTestCase(APITestCase):
    def setUp(self):
        self.user = User.objects.create(username='testuser', is_superuser=True)
        self.client.force_authenticate(user=self.user)

    def test_naturalkey_config(self):
        response = self.client.get('/config.json')
        self.assertEqual([
            {
                'name': 'note',
                'label': 'Note',
                'type': 'text',
                'bind': {'required': True},
            },
            {
                'name': 'key',
                'label': 'Key',
                'type': 'group',
                'bind': {'required': True},
                'children': [{
                     'name': 'parent[slug]',
                     'label': 'Parent',
                     'type': 'select one',
                     'wq:ForeignKey': 'naturalkeyparent',
                     'wq:length': 50,
                     'bind': {'required': True},
                }, {
                     'name': 'date',
                     'label': 'Date',
                     'type': 'date',

# Path: tests/base.py
# class APITestCase(APITestCase):
#     client_class = APIClient
# 
# Path: tests/naturalkey_app/models.py
# class ModelWithNaturalKey(models.Model):
#     key = models.ForeignKey(NaturalKeyChild, models.CASCADE)
#     note = models.TextField()
# 
#     def __str__(self):
#         return "%s: %s" % (self.key, self.note)


# Path: tests/test_naturalkey.py
from .base import APITestCase
from rest_framework import status
from django.contrib.auth.models import User
from tests.naturalkey_app.models import ModelWithNaturalKey
import json

class NaturalKeyTestCase(APITestCase):
    def setUp(self):
        self.user = User.objects.create(username='testuser', is_superuser=True)
        self.client.force_authenticate(user=self.user)

    def test_naturalkey_config(self):
        response = self.client.get('/config.json')
        self.assertEqual([
            {
                'name': 'note',
                'label': 'Note',
                'type': 'text',
                'bind': {'required': True},
            },
            {
                'name': 'key',
                'label': 'Key',
                'type': 'group',
                'bind': {'required': True},
                'children': [{
                     'name': 'parent[slug]',
                     'label': 'Parent',
                     'type': 'select one',
                     'wq:ForeignKey': 'naturalkeyparent',
                     'wq:length': 50,
                     'bind': {'required': True},
                }, {
                     'name': 'date',
                     'label': 'Date',
                     'type': 'date',

                     'bind': {'required': True},