I've tried to test the views of my application in django but with no success.
I got the message after the command python manage.py test <app_name>
:
RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against t
he production database when it's not needed (for example, when running tests). Django was unable to create a connection to the
'postgres' database and will use the first PostgreSQL database instead.
warnings.warn(
Got an error creating the test database: permission denied to create database
Where I don't understand how do I implement this test in my DATABASE
in settings.py
file.
settings.py:
#imports
import os
//To import the env.py secret_keys
if os.path.exists('env.py'):
import env
import dj_database_url
... . .
//postgress
if 'DATABASE_URL' in os.environ:
DATABASES = {
'default': dj_database_url.parse(os.environ.get('DATABASE_URL'))
}
else:
#local
print("Postgres URL not found, using sqlite instead")
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
test_views.py
class TestViews(TestCase):
#test_main_view_GET test is displayed on the main url in main_tour_folder
def test_destinations_GET(self):
client = Client()
response = client.get(reverse('destination'))
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'tour_store/destinations.html')
I've seen in one article that I need to create a TEST
with NAME
dictionary within the DATABASES
config but with no success.
Aucun commentaire:
Enregistrer un commentaire