# Path: accounts/models.py
# class BlogUser(AbstractUser):
#     nickname = models.CharField('昵称', max_length=100, blank=True)
#     created_time = models.DateTimeField('创建时间', default=now)
#     last_mod_time = models.DateTimeField('修改时间', default=now)
#     source = models.CharField("创建来源", max_length=100, blank=True)
# 
#     def get_absolute_url(self):
#         return reverse(
#             'blog:author_detail', kwargs={
#                 'author_name': self.username})
# 
#     def __str__(self):
#         return self.email
# 
#     def get_full_url(self):
#         site = get_current_site().domain
#         url = "https://{site}{path}".format(site=site,
#                                             path=self.get_absolute_url())
#         return url
# 
#     class Meta:
#         ordering = ['-id']
#         verbose_name = "用户"
#         verbose_name_plural = verbose_name
#         get_latest_by = 'id'
# 
# Path: owntracks/models.py
# class OwnTrackLog(models.Model):
#     tid = models.CharField(max_length=100, null=False, verbose_name='用户')
#     lat = models.FloatField(verbose_name='纬度')
#     lon = models.FloatField(verbose_name='经度')
#     created_time = models.DateTimeField('创建时间', default=now)
# 
#     def __str__(self):
#         return self.tid
# 
#     class Meta:
#         ordering = ['created_time']
#         verbose_name = "OwnTrackLogs"
#         verbose_name_plural = verbose_name
#         get_latest_by = 'created_time'


import json
from django.test import Client, RequestFactory, TestCase
from accounts.models import BlogUser
from .models import OwnTrackLog
# Create your tests here.

class OwnTrackLogTest(TestCase):
    def setUp(self):
        self.client = Client()
        self.factory = RequestFactory()

    def test_own_track_log(self):
        o = {
            'tid': 12,
            'lat': 123.123,
            'lon': 134.341
        }

        self.client.post(
            '/owntracks/logtracks',
            json.dumps(o),
            content_type='application/json')
        length = len(OwnTrackLog.objects.all())
        self.assertEqual(length, 1)

        o = {
            'tid': 12,
            'lat': 123.123
        }

        self.client.post(
            '/owntracks/logtracks',
            json.dumps(o),
            content_type='application/json')

# Path: accounts/models.py
# class BlogUser(AbstractUser):
#     nickname = models.CharField('昵称', max_length=100, blank=True)
#     created_time = models.DateTimeField('创建时间', default=now)
#     last_mod_time = models.DateTimeField('修改时间', default=now)
#     source = models.CharField("创建来源", max_length=100, blank=True)
# 
#     def get_absolute_url(self):
#         return reverse(
#             'blog:author_detail', kwargs={
#                 'author_name': self.username})
# 
#     def __str__(self):
#         return self.email
# 
#     def get_full_url(self):
#         site = get_current_site().domain
#         url = "https://{site}{path}".format(site=site,
#                                             path=self.get_absolute_url())
#         return url
# 
#     class Meta:
#         ordering = ['-id']
#         verbose_name = "用户"
#         verbose_name_plural = verbose_name
#         get_latest_by = 'id'
# 
# Path: owntracks/models.py
# class OwnTrackLog(models.Model):
#     tid = models.CharField(max_length=100, null=False, verbose_name='用户')
#     lat = models.FloatField(verbose_name='纬度')
#     lon = models.FloatField(verbose_name='经度')
#     created_time = models.DateTimeField('创建时间', default=now)
# 
#     def __str__(self):
#         return self.tid
# 
#     class Meta:
#         ordering = ['created_time']
#         verbose_name = "OwnTrackLogs"
#         verbose_name_plural = verbose_name
#         get_latest_by = 'created_time'


# Path: owntracks/tests.py
import json
from django.test import Client, RequestFactory, TestCase
from accounts.models import BlogUser
from .models import OwnTrackLog

# Create your tests here.

class OwnTrackLogTest(TestCase):
    def setUp(self):
        self.client = Client()
        self.factory = RequestFactory()

    def test_own_track_log(self):
        o = {
            'tid': 12,
            'lat': 123.123,
            'lon': 134.341
        }

        self.client.post(
            '/owntracks/logtracks',
            json.dumps(o),
            content_type='application/json')
        length = len(OwnTrackLog.objects.all())
        self.assertEqual(length, 1)

        o = {
            'tid': 12,
            'lat': 123.123
        }

        self.client.post(
            '/owntracks/logtracks',
            json.dumps(o),
            content_type='application/json')

        length = len(OwnTrackLog.objects.all())