Newer
Older
GestionHoteleriaApi / apps / hotel / tests.py
from apps.hotel.models import Hotel
from django.test import TestCase

# Create your tests here.
from django.urls import reverse


class HotelTest(TestCase):

    @classmethod
    def setUpTestData(cls):
        Hotel.objects.create(name='Colombia', code='45hv-c')

        # number_of_hoteles = 13
        # for hotel_num in range(number_of_hoteles):
        #     Hotel.objects.create(name='Brisas %s' % hotel_num, )

    # def setUp(self):
    #     pass
    #
    # def tearDown(self):
    #     pass

    def test_name_label(self):
        hotel = Hotel.objects.get(id=1)
        field_label = hotel._meta.get_field('name').verbose_name
        self.assertEqual(field_label, 'name')

    def test_code_label(self):
        hotel = Hotel.objects.get(id=1)
        field_label = hotel._meta.get_field('code').verbose_name
        self.assertEqual(field_label, 'code')

    def test_name_max_length(self):
        hotel = Hotel.objects.get(id=1)
        max_length = hotel._meta.get_field('name').max_length
        self.assertEqual(max_length, 60)

    def test_code_max_length(self):
        hotel = Hotel.objects.get(id=1)
        max_length = hotel._meta.get_field('code').max_length
        self.assertEqual(max_length, 60)

    # def test_view_url_accessible_by_name(self):
    #     resp = self.client.get(reverse('hotel'))
    #     self.assertEqual(resp.status_code, 200)

    # def test_view_uses_correct_template(self):
    #     resp = self.client.get(reverse('hotel'))
    #     self.assertEqual(resp.status_code, 200)
    #
    #     self.assertTemplateUsed(resp, 'hotel/hotel_list.html')

    # def test_lists_all_authors(self):
    #     # Get second page and confirm it has (exactly) remaining 3 items
    #     resp = self.client.get(reverse('hotel') + '?page=2')
    #     self.assertEqual(resp.status_code, 200)
    #     self.assertTrue('is_paginated' in resp.context)
    #     self.assertTrue(resp.context['is_paginated'] == True)
    #     self.assertTrue(len(resp.context['hotel_list']) == 3)


class ViewsUrlsTest(TestCase):

    def test_view_url_exists_at_desired_location_of_hotel(self):
        resp = self.client.get('/hotel/hotel/')
        self.assertEqual(resp.status_code, 200)

    def test_view_url_exists_at_desired_location_of_typeRoom(self):
        resp = self.client.get('/hotel/type_room/')
        self.assertEqual(resp.status_code, 200)

    def test_view_url_exists_at_desired_location_of_room(self):
        resp = self.client.get('/hotel/room/')
        self.assertEqual(resp.status_code, 200)

    def test_view_url_exists_at_desired_location_of_availableroom(self):
        resp = self.client.get('/hotel/availableroom/')
        self.assertEqual(resp.status_code, 200)