# Path: tests/models.py
# class Team(ObjectSet):
#     employees = models.ManyToManyField(Employee)
#     context_json = jsonfield.JSONField(null=True, blank=True)
# 
# class Employee(models.Model):
#     first_name = models.CharField(max_length=50)
#     last_name = models.CharField(max_length=50)
#     title = models.ForeignKey(Title, null=True)
#     office = models.ForeignKey(Office)
#     is_manager = models.NullBooleanField(default=False)


import json
from django.test import TestCase
from django.core import management
from restlib2.http import codes
from ...models import Team, Employee

    def test_root(self):
        response = self.client.get('/api/sets/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 1)

    def test_type(self):
        response = self.client.get('/api/sets/teams/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 0)

    def test_type_instance(self):
        Team(Employee.objects.all(), save=True)
        response = self.client.get('/api/sets/teams/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 1)

    def test_context(self):
        response = self.client.post('/api/sets/teams/', json.dumps({
            'context': {
                'field': 'tests.title.salary',
                'operator': 'gt',
                'value': 15000,
            }
        }), content_type='application/json',
            HTTP_ACCEPT='application/json')


# Path: tests/models.py
# class Team(ObjectSet):
#     employees = models.ManyToManyField(Employee)
#     context_json = jsonfield.JSONField(null=True, blank=True)
# 
# class Employee(models.Model):
#     first_name = models.CharField(max_length=50)
#     last_name = models.CharField(max_length=50)
#     title = models.ForeignKey(Title, null=True)
#     office = models.ForeignKey(Office)
#     is_manager = models.NullBooleanField(default=False)


# Path: tests/cases/sets/tests.py
import json
from django.test import TestCase
from django.core import management
from restlib2.http import codes
from ...models import Team, Employee


    def test_root(self):
        response = self.client.get('/api/sets/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 1)

    def test_type(self):
        response = self.client.get('/api/sets/teams/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 0)

    def test_type_instance(self):
        Team(Employee.objects.all(), save=True)
        response = self.client.get('/api/sets/teams/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 1)

    def test_context(self):
        response = self.client.post('/api/sets/teams/', json.dumps({
            'context': {
                'field': 'tests.title.salary',
                'operator': 'gt',
                'value': 15000,
            }
        }), content_type='application/json',
            HTTP_ACCEPT='application/json')


        self.assertEqual(Employee.objects.filter(title__salary__gt=15000)