Recently written test case for an API model - and it worked fine on the API. I used the structure of the test case on a database model, but I’m getting a FAIL.
Running the app locally works fine, there are no issues, but his test case isn’t working. Any advice on how to get “un stuck” is greatly appreciated!
#posts/tests.py
from django.test import SimpleTestCase
from django.urls import reverse
from .models import Post
class PostObjectTest(SimpleTestCase):
@classmethod
def setUpTestData(cls):
cls.post = Post.objects.create(
title="Post Short Description",
date_post="2023-06-01",
employment="OTHER",
position="OTHER",
vessel_size="150",
location="OTHER",
description="Long description of job post",
email="someone@somewhere.com",
phone="1234567890",
)
def test_listview(self):
response = self.client.get(reverse("post_list")) # Check that correct URL is being used
self.assertEqual(response.status_code, 200) # Confirm 200 status
self.assertEqual(Post.objects.count(), 1) # Confirm single entry
self.assertContains(response, self.post) # Confirm all data created Post object
Found 2 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
.F
======================================================================
FAIL: test_listview (posts.tests.PostObjectTest)
----------------------------------------------------------------------