import json
from rest_framework import status
from django.test import TestCase, Client
from django.urls import reverse
from ..models import Temperature, HeartBeats
from ..serializers import TemperatureSerializer, HeartBeatsSerializer


client = Client()


class GetCurrentTemperatureTest(TestCase):
    """ Test class for GET current temperature from API """

    def setUp(self):
        Temperature.objects.create(temperature=35)

    def test_get_current_temperature(self):
        response = client.get(reverse('temperature'))
        temperature = Temperature.objects.order_by('date', 'time').last()
        serializer = TemperatureSerializer(temperature)
        self.assertEqual(response.data, serializer.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)


class CreateNewTemperatureTest(TestCase):
    """ Test class for saving a new temperature registry """

    def setUp(self):
        self.valid_payload = {
            'temperature': 27.2
        }

        self.invalid_payload = {
            'temperature': ''
        }

    def test_creat_valid_temperature(self):
        response = client.post(
            reverse('temperature'),
            data=json.dumps(self.valid_payload),
            content_type='application/json'
        )
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

    def test_create_invalid_temperature(self):
        response = client.post(
            reverse('temperature'),
            data=json.dumps(self.invalid_payload),
            content_type='application/json'
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)


class GetCurrentHeartBeatsTest(TestCase):
    """ Test class for GET current heartbeats from API """

    def setUp(self):
        HeartBeats.objects.create(beats=70)

    def test_get_current_heartbeats(self):
        response = client.get(reverse('heartbeats'))
        heartbeats = HeartBeats.objects.order_by('date', 'time').last()
        serializer = HeartBeatsSerializer(heartbeats)
        self.assertEqual(response.data, serializer.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)


class CreateNewHeartBeatsTest(TestCase):
    """" Test class for saving a new heartbeats registry """

    def setUp(self):
        self.valid_payload = {
            'beats': 80
        }
        self.invalid_payload = {
            'beats': ''
        }

    def test_create_valid_heartbeats(self):
        response = client.post(
            reverse('heartbeats'),
            data=json.dumps(self.valid_payload),
            content_type='application/json'
        )
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

    def test_create_invalid_temperature(self):
        response = client.post(
            reverse('heartbeats'),
            data=json.dumps(self.invalid_payload),
            content_type='application/json'
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

@@ -156,16 +156,27 @@
 artBeats
+, Breathing
 %0Afrom ..
@@ -237,16 +237,37 @@
 rializer
+, BreathingSerializer
 %0A%0A%0Aclien
@@ -3006,28 +3006,1394 @@
 tatus.HTTP_400_BAD_REQUEST)%0A
+%0A%0Aclass GetCurrentBreathingTest(TestCase):%0A    %22%22%22 Test class for GET current breathing from API %22%22%22%0A%0A    def setUp(self):%0A        Breathing.objects.create(is_breathing=True)%0A%0A    def test_get_current_breathing(self):%0A        response = client.get(reverse('breathing'))%0A        breathing = Breathing.objects.order_by('date', 'time').last()%0A        serializer = BreathingSerializer(breathing)%0A        self.assertEqual(response.data, serializer.data)%0A        self.assertEqual(response.status_code, status.HTTP_200_OK)%0A%0A%0Aclass CreateNewBreathingTest(TestCase):%0A    %22%22%22%22 Test class for saving a new breathing registry %22%22%22%0A%0A    def setUp(self):%0A        self.valid_payload = %7B%0A            'is_breathing': True%0A        %7D%0A        self.invalid_payload = %7B%0A            'is_breathing': ''%0A        %7D%0A%0A    def test_create_valid_breathing(self):%0A        response = client.post(%0A            reverse('breathing'),%0A            data=json.dumps(self.valid_payload),%0A            content_type='application/json'%0A        )%0A        self.assertEqual(response.status_code, status.HTTP_201_CREATED)%0A%0A    def test_create_invalid_breathing(self):%0A        response = client.post(%0A            reverse('breathing'),%0A            data=json.dumps(self.invalid_payload),%0A            content_type='application/json'%0A        )%0A        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)%0A

Implement tests for breathing endpoint