lundi 27 janvier 2020

Django.core.exceptions.ImproperlyConfigured: Error running functional_tests.py

django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

my functional tests:

from selenium import webdriver
from lists.models import Item
from selenium.webdriver.common.keys import Keys
import time
import unittest
import os



class NewVisitorTest(unittest.TestCase):
def setUp(self):
    self.browser = webdriver.Firefox()
def tearDown(self):
    self.browser.quit()

def test_can_start_a_list_and_retrieve_it_later(self):
    self.browser.get('http://localhost:8000/')
    # She notices the page title and header mention to-do lists
    print(self.browser.title)
    self.assertIn('lists', self.browser.title)
    header_text = self.browser.find_element_by_tag_name('h1').text
    self.assertIn('list', header_text)

    inputbox = self.browser.find_element_by_id('id_new_item')
    self.assertEqual(
    inputbox.get_attribute('placeholder'),
    'Enter a to-do item'
    )
    inputbox.send_keys('Buy peacock feathers')
    inputbox.send_keys(Keys.ENTER)
    time.sleep(1)
    table = self.browser.find_element_by_id('id_list_table')
    rows = table.find_elements_by_tag_name('tr')
    self.assertIn('1: Buy peacock feathers',[row.text for row in rows])
    self.assertIn('2: Use a peacock feather', [row.text for row in rows])
    self.fail('Finish the test!')


def check_for_row_in_list_table(self,row_text):
    table = self.browser.find_element__by_id('id_list_table')
    rows = table.find_element_by_tag_name('tr')
    self.assertIn(row_text,[row.text for row in rows])    
    inputbox.send_keys(Keys.ENTER)
    time.sleep(1)
    self.check_for_row_in_list_table('1:Buy a peacock feather')
    inputbox = self.browser.find_element_by_id('id_new_item')
    input.send_keys('Use peacock feathers to make a fly')
    inputbox.send_keys(Keys.ENTER)
    time.sleep(1)
    self.check_for_row_in_list_table('1:Buy a peacock feather')
    self.check_for_row_in_list_table('2: Use a peacock feather')


if __name__ == '__main__':
unittest.main(warnings='ignore')

my models :When I try to run functional_tests I get the error.

from django.db import models


class Item(models.Model):
text = models.TextField(default='')

my settings file . I have included the list app in my INSTALLED_APPS too.

import os


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = 'xyz'

DEBUG = True

ALLOWED_HOSTS = []


INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'lists.apps.ListsConfig',
]

Aucun commentaire:

Enregistrer un commentaire