# Path: examples/django_rest_framework/frontend/frontend/models.py
# class Account(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     email = models.CharField(max_length=30)
# 
#     api_base_name = 'accounts'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import AccountSerializer
#         return AccountSerializer
# 
# class Article(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     headline = models.CharField(max_length=100)
#     pub_date = models.DateField()
#     reporter = models.ForeignKey(Reporter, related_name='articles')
# 
#     api_base_name = 'articles'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import ArticleSerializer
#         return ArticleSerializer
# 
# class Tag(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     label = models.CharField(max_length=30)
#     articles = models.ManyToManyField(Article, related_name='tags')
# 
#     api_base_name = 'tags'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import TagSerializer
#         return TagSerializer
# 
# class Reporter(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     account = models.OneToOneField(Account)
#     first_name = models.CharField(max_length=30)
#     last_name = models.CharField(max_length=30)
# 
#     api_base_name = 'reporters'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import ReporterSerializer
#         return ReporterSerializer


from django.utils.timezone import now
from rest_framework.test import APITestCase
from django_roa.db.exceptions import ROAException
from .models import Account, Article, Tag, Reporter
        # Create
        #

        new_account = Account()
        new_account.email = 'peter@example.com'
        new_account.save()

        self.assertIsNotNone(new_account.id)

        accounts = Account.objects.all()
        self.assertEqual(accounts.count(), 3)
        self.assertEqual(accounts[0].email, 'john@example.com')
        self.assertEqual(accounts[1].email, 'paul@example.com')
        self.assertEqual(accounts[2].email, 'peter@example.com')

        #
        # Delete
        #

        new_account.delete()
        self.assertIsNone(new_account.pk)

        accounts = Account.objects.all()
        self.assertEqual(accounts.count(), 2)

        #
        # Create with relationship
        #

        count_accounts = Account.objects.count()

# Path: examples/django_rest_framework/frontend/frontend/models.py
# class Account(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     email = models.CharField(max_length=30)
# 
#     api_base_name = 'accounts'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import AccountSerializer
#         return AccountSerializer
# 
# class Article(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     headline = models.CharField(max_length=100)
#     pub_date = models.DateField()
#     reporter = models.ForeignKey(Reporter, related_name='articles')
# 
#     api_base_name = 'articles'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import ArticleSerializer
#         return ArticleSerializer
# 
# class Tag(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     label = models.CharField(max_length=30)
#     articles = models.ManyToManyField(Article, related_name='tags')
# 
#     api_base_name = 'tags'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import TagSerializer
#         return TagSerializer
# 
# class Reporter(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     account = models.OneToOneField(Account)
#     first_name = models.CharField(max_length=30)
#     last_name = models.CharField(max_length=30)
# 
#     api_base_name = 'reporters'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import ReporterSerializer
#         return ReporterSerializer


# Path: examples/django_rest_framework/frontend/frontend/tests.py
from django.utils.timezone import now
from rest_framework.test import APITestCase
from django_roa.db.exceptions import ROAException
from .models import Account, Article, Tag, Reporter

        # Create
        #

        new_account = Account()
        new_account.email = 'peter@example.com'
        new_account.save()

        self.assertIsNotNone(new_account.id)

        accounts = Account.objects.all()
        self.assertEqual(accounts.count(), 3)
        self.assertEqual(accounts[0].email, 'john@example.com')
        self.assertEqual(accounts[1].email, 'paul@example.com')
        self.assertEqual(accounts[2].email, 'peter@example.com')

        #
        # Delete
        #

        new_account.delete()
        self.assertIsNone(new_account.pk)

        accounts = Account.objects.all()
        self.assertEqual(accounts.count(), 2)

        #
        # Create with relationship
        #

        count_accounts = Account.objects.count()

        count_reporters = Reporter.objects.count()