from datetime import datetime

from django.core.urlresolvers import reverse
from django.test import TestCase

from animals.models import Animal


class AnimalsViewsTestCase(TestCase):
    fixtures = ['animals_testdata.json']

    def test_index(self):
        """
        Checks for 200 status and that expected variables in context
        and that some animals are displayed by default.
        """
        resp = self.client.get(reverse('animals_index'))
        self.assertTrue('form' in resp.context)
        self.assertTrue('alist' in resp.context)
        self.assertTrue('results_count' in resp.context)
        self.assertNotContains(resp, '<div>0 animals displayed</div>',
                               status_code=200)

    def test_type_search(self):
        resp = self.client.post(reverse('animals_index'), {
            'animal_type': 'CAT', 'intake_date_start': '2012-05-01'})
        self.assertContains(resp, "5/31/2012")
        self.assertContains(resp, "black domestic sh", status_code=200)

    def test_date_search(self):
        resp = self.client.post(reverse('animals_index'), {
            'intake_date_start': '2012-06-04',
             'intake_date_end': '2012-06-04'})
        self.assertContains(resp, "6/4/2012")
        self.assertContains(resp, "chalupa")
        self.assertContains(resp, "white rat terrier", status_code=200)

    def test_paginated_type_search(self):
        self.client.post(reverse('animals_index'), {'animal_type': 'CAT',
            'intake_date_start': '2012-05-01'})
        resp = self.client.get('%s?page=2' % reverse('animals_index'))
        self.assertContains(resp, "6/2/2012", count=4)
        self.assertContains(resp, "calico domestic sh", status_code=200)

    def test_sex_search(self):
        resp = self.client.post(reverse('animals_index'), {'sex': 'M',
            'intake_date_start': '2012-05-01'})
        self.assertContains(resp, "5/30/2012")
        self.assertContains(resp, "beagle")
        self.assertContains(resp, "tricolor beagle", status_code=200)

    def test_condition_search(self):
        resp = self.client.post(reverse('animals_index'), {
            'intake_condition': 'INJURED', 'intake_date_start': '2012-05-01'})
        self.assertContains(resp, "5/30/2012")
        self.assertContains(resp, "bo jangles")
        self.assertContains(resp, "white catahoula", status_code=200)

    def test_markers_displayed(self):
        resp = self.client.post(reverse('animals_index'), {
            'intake_date_start': '2012-06-04',
            'intake_date_end': '2012-06-04'})
        self.assertContains(resp, "map.addMarker", count=43, status_code=200)

@@ -871,33 +871,33 @@
 _start': '2012-0
-5
+8
 -01'%7D)%0A        s
@@ -926,12 +926,12 @@
 p, %22
-5/31
+8/24
 /201
@@ -1135,32 +1135,31 @@
 rt': '2012-0
-6-04
+9-07
 ',%0A
- 
             
@@ -1176,36 +1176,36 @@
 te_end': '2012-0
-6-04
+9-07
 '%7D)%0A        self
@@ -1231,11 +1231,11 @@
 p, %22
-6/4
+9/7
 /201
@@ -1277,15 +1277,14 @@
 p, %22
-chalupa
+smokey
 %22)%0A 
@@ -1321,25 +1321,19 @@
 p, %22
-white rat terrier
+tan pug mix
 %22, s

fix date search test for new fixture