from django.http import response
from django.test import TestCase
from .models import Post
from django.urls import reverse
# Create your tests here.


class PostModelTest(TestCase):

    def setUp(self):
        Post.objects.create(text='A test')

    def test_text_content(self):
        post = Post.objects.get(id=1)
        expected_object_name = f'{post.text}'
        self.assertEqual(expected_object_name, 'A test')


class HomePageTest(TestCase):

    def setUp(self):
        Post.objects.create(text='Another test')

    def test_view_url_exists(self):
        res = self.client.get('/')
        self.assertEqual(res.status_code, 200)

    def test_view_url_name(self):
        res = self.client.get(reverse('home'))
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'home.html')
