# Path: tests/testapp/models.py
# class TimeSeries(models.Model):
#     date = models.DateField()
#     value = models.FloatField()
# 
#     objects = DataFrameManager()
# 
# class CustomIndexSeries(models.Model):
#     code = models.SlugField(primary_key=True)
#     value = models.FloatField()
# 
# Path: tests/settings.py
# HAS_DJANGO_PANDAS = False


import unittest
import json
import datetime
import os
from rest_framework.test import APITestCase
from tests.testapp.models import TimeSeries, CustomIndexSeries
from wq.io import load_string
from .settings import HAS_DJANGO_PANDAS

    def test_view_csv_noid(self):
        response = self.client.get("/timeseriesnoid.csv")
        data = self.load_string(response)
        self.assertEqual(len(data), 5)
        self.assertEqual(data[0].value, '0.5')

    @unittest.skipUnless(HAS_DJANGO_PANDAS, 'requires django-pandas')
    def test_view_django_pandas(self):
        response = self.client.get("/djangopandas.csv")
        data = self.load_string(response)
        self.assertEqual(len(data), 5)
        self.assertEqual(data[0].value, '0.5')

    def test_view_json(self):
        response = self.client.get("/timeseries.json")
        self.assertEqual(response.accepted_media_type, "application/json")
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 5)
        self.assertIn('id', data[0])
        self.assertEqual(data[0]["id"], 1)
        self.assertEqual(data[0]["value"], 0.5)
        self.assertEqual(data[0]["date"], "2014-01-01T00:00:00.000Z")

    def test_view_json_kwargs(self):
        response = self.client.get("/timeseries.json?date_format=epoch")
        self.assertEqual(response.accepted_media_type, "application/json")
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 5)
        self.assertEqual(data[0]["value"], 0.5)

# Path: tests/testapp/models.py
# class TimeSeries(models.Model):
#     date = models.DateField()
#     value = models.FloatField()
# 
#     objects = DataFrameManager()
# 
# class CustomIndexSeries(models.Model):
#     code = models.SlugField(primary_key=True)
#     value = models.FloatField()
# 
# Path: tests/settings.py
# HAS_DJANGO_PANDAS = False


# Path: tests/test_views.py
import unittest
import json
import datetime
import os
from rest_framework.test import APITestCase
from tests.testapp.models import TimeSeries, CustomIndexSeries
from wq.io import load_string
from .settings import HAS_DJANGO_PANDAS


    def test_view_csv_noid(self):
        response = self.client.get("/timeseriesnoid.csv")
        data = self.load_string(response)
        self.assertEqual(len(data), 5)
        self.assertEqual(data[0].value, '0.5')

    @unittest.skipUnless(HAS_DJANGO_PANDAS, 'requires django-pandas')
    def test_view_django_pandas(self):
        response = self.client.get("/djangopandas.csv")
        data = self.load_string(response)
        self.assertEqual(len(data), 5)
        self.assertEqual(data[0].value, '0.5')

    def test_view_json(self):
        response = self.client.get("/timeseries.json")
        self.assertEqual(response.accepted_media_type, "application/json")
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 5)
        self.assertIn('id', data[0])
        self.assertEqual(data[0]["id"], 1)
        self.assertEqual(data[0]["value"], 0.5)
        self.assertEqual(data[0]["date"], "2014-01-01T00:00:00.000Z")

    def test_view_json_kwargs(self):
        response = self.client.get("/timeseries.json?date_format=epoch")
        self.assertEqual(response.accepted_media_type, "application/json")
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 5)
        self.assertEqual(data[0]["value"], 0.5)

        date = datetime.datetime.utcfromtimestamp(data[0]["date"] / 1000)