Hello,
I'm trying to make my first tests in Django (well, in dev to be honest) and I'm having a bit of an issue when testing other things than models.
For example, when I try to test views like this :
from django.test import TestCase, Client
from cinemas_app.models import Cinema
class ChangeCinemaViewTest(TestCase):
def setUp(self):
self.client = Client()
self.cinema1 = Cinema.objects.create(name="Cinema A", address="123", phone="1234567890")
self.cinema2 = Cinema.objects.create(name="Cinema B", address="456", phone="0987654321")
def test_change_cinema_with_client(self):
session = self.client.session
session["selected_cinema"] = self.cinema1.id
session.save()
response = self.client.post("/change_cinema/", {"cinema": self.cinema2.id}, HTTP_REFERER="/home/")
self.assertEqual(self.client.session["selected_cinema"], self.cinema2.id)
self.assertEqual(response.status_code, 302)
self.assertEqual(response["Location"], "/home/")
I get "FAILED cinemas_app/tests/test_cinema_views.py::ChangeCinemaViewTest::test_change_cinema_with_client - django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty. "
I've tried to setup the env adding this :
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cinephoria.settings")
import django
django.setup()
But it does not help. The secret key is not directly into settings. Settings load an env file with the secret key in it.
What am I missing please ?