Hello, how is your postgres configured, because there is no database called 
test2. this is the error

Em quarta-feira, 6 de setembro de 2023 às 19:08:32 UTC-3, Alfons Eberle 
escreveu:

> Hey, has anyone gotten pytest to work with django-channels (or asgiref + 
> Daphne) and Selenium in general when database access is required?
>
> My fixtures for users and other models import just fine, but my browser 
> and Daphne process seem to be unaware of the test database and seem unable 
> to create them. Frontend errors out with the classic *pytest 
> django.db.utils.OperationalError: connection to server at "127.0.0.1", port 
> 5432 failed: FATAL: database "test2" does not exist*
>
> I am using a Daphne test server implementation I found on SO + GitHub 
> here: https://github.com/pytest-dev/pytest-django/issues/1027
>
> Here's some sample code I have for reference. channels_live_server is 
> from the implementation above. Doing this simply shows the yellow Django 
> error page with the error above.
> I have tried explicitly creating the database, which gets rid of the 
> error, trying to e.g. log in via the admin but it still does not cause the 
> database to fill with any data. It's like they are in two different 
> *worlds* (threads).
>
> All my other pytests run fine.
>
> Any ideas? Thanks
>
>
> @pytest.fixture
> def authenticated_browser_staff(channels_live_server, client):
>     """Return a browser instance with logged-in user session."""
>     options = webdriver.ChromeOptions()
>     browser_ = webdriver.Chrome(options=options)
>     user_staff = User.objects.create(
>         email='te...@foo.bar', 
>         password=make_password('hunter42'),
>         is_superuser=True
>     ) # usually a fixture, but easier to share like this
>     print('staff id', user_staff.id)  # works as expected
>
>     client.force_login(user_staff)  # works and returns the session ID
>     print('cookie', client.cookies[settings.SESSION_COOKIE_NAME].value)
>
>     browser.get(channels_live_server.url + "/admin/")
>     browser.add_cookie({
>         'name': settings.SESSION_COOKIE_NAME,
>         'value': client.cookies[settings.SESSION_COOKIE_NAME].value,
>         #'expires': None,
>         #'secure': False,
>         #'path': '/'
>     })
>     # server responds with setting sessionid to empty
>     browser.refresh()
>
>     # trying to log in, since passing the cookie does not 
>     # work, but errors out with user does not exist
>     browser.find_element('name', 'username').send_keys(user_staff.email)
>     browser.find_element('name', 'password').send_keys('hunter42')
>     browser.find_element(By.CSS_SELECTOR, "input[type='submit']").click()
>
>     assert any(c for c in browser.get_cookies() if c['name'] == 
> settings.SESSION_COOKIE_NAME)
>     return browser
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4c85adda-887e-4c22-b573-55b75f68c8c3n%40googlegroups.com.

Reply via email to