Testing the code

I have a flatpage in my website. I created it by writing this:
urlpatterns = [

path('admin/', admin.site.urls),
path('facts/', include('django.contrib.flatpages.urls')),]

After that in admin page I created a page about-me, so the whole url for that page is ‘localhost/facts/about-me/’

I tried to write test for this page:
class StaticURLTests(TestCase):
def setUp(self):
self.guest_client = Client()

def test_about_author(self):
    response = self.guest_client.get('/facts/about-me/')
    self.assertEqual(response.status_code, 200)

But I get the following error:
self.assertEqual(response.status_code, 200)
AssertionError: 404 != 200
FAILED (failures=1)
Destroying test database for alias ‘default’…

Can’t figure out why. Maybe smb was facing the same problem

Hi!

HTTP 404 status code means a Not Found error.

For testing Django creates a test database by default so your about-me page doesn’t exist in there.

The setUp stage is useful for creating test data, in this case a FlatPage, and then you can query it like you already did.