2

I try to implement TDD using:

  1. django version 3.0
  2. Selenium version 3.141.0 with chromedriver.exe
  3. PgAdmin4 (Postgresql 13.0)

Here is my test code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from django.contrib.staticfiles.testing import StaticLiveServerTestCase


class NewUserTest(StaticLiveServerTestCase):
    def setUp(self):
        self.browser = webdriver.Chrome("D:\chromedriver.exe")

    def tearDown(self):
        self.browser.quit()

    def test_success_login(self):
        self.browser.get(self.live_server_url)

        input_username = self.browser.find_element_by_id('id_username')
        input_password = self.browser.find_element_by_id('id_password')
        self.assertTrue(input_password.get_attribute('required'))

        input_username.send_keys('onesinus')
        input_password.send_keys('123')
        input_password.send_keys(Keys.ENTER)

But when the test executed

python manage.py test

I have two error:

1. django.db.utils.NotSupportedError: cannot truncate a table referenced in a foreign key constraint
DETAIL:  Table "my_table_name" references "auth_user".
HINT:  Truncate table "my_table_name" at the same time, or use TRUNCATE ... CASCADE.

2. Traceback (most recent call last):
  File "D:\mycms\venv\lib\site-packages\django\test\testcases.py", line 274, in __call__
    self._post_teardown()
  File "D:\mycms\venv\lib\site-packages\django\test\testcases.py", line 1009, in _post_teardown
    self._fixture_teardown()
  File "D:\mycms\venv\lib\site-packages\django\test\testcases.py", line 1041, in _fixture_teardown
    call_command('flush', verbosity=0, interactive=False,
  File "D:\mycms\venv\lib\site-packages\django\core\management\__init__.py", line 168, in call_command
    return command.execute(*args, **defaults)
  File "D:\mycms\venv\lib\site-packages\django\core\management\base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "D:\mycms\venv\lib\site-packages\django\core\management\commands\flush.py", line 65, in handle
    raise CommandError(
django.core.management.base.CommandError: Database test_db-staging couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin sqlflush'. That's the SQL this command wasn't able to run.

Someone have find this problem before? or someone can help me to solve this?

Is that possible if I use django.test.runner like override teardown_databases method?

I am thinking of changing profession :)

Thank you so much for your response and help! have a nice day!

Kode Kite
  • 328
  • 5
  • 15

0 Answers0