Re: Regarding the Django ImportError Issue

2023-09-07 Thread Ferney Bermeo Ruiz
Hello, the same thing happened to me, the solution was to install at least 
django... if you have a project under development, it is best to install 
the file requirements.txt with pip. within your virtual environment. 
Greetings and success :)

El viernes, 25 de agosto de 2023 a las 13:48:17 UTC-5, ivan harold escribió:

> I think it is better if you reply to the specific thread that has this 
> issue. So that the concerned person will be able to see your reply 
> immediately.
>
> On Saturday, August 26, 2023 at 1:29:58 AM UTC+8 abhijeet tripathi wrote:
>
>>
>>
>> Hello,
>>
>> I hope this message finds you well. I wanted to let you know that I've 
>> taken a look at the error message you shared:
>>
>> ```
>> Aug 25 12:28:30 AM  ImportError: Couldn't import Django. Are you sure 
>> it's installed and available on your PYTHONPATH environment variable? Did 
>> you forget to activate a virtual environment?
>> Aug 25 12:28:30 AM  ==> Build failed
>> ```
>>
>> To better assist you in resolving this issue, could you kindly provide me 
>> with some additional details? This information will help me gain a clearer 
>> understanding of your setup and the potential causes of the error:
>>
>> 1. **Operating System:** Please let me know the operating system you're 
>> using (e.g., Windows, macOS, Linux).
>>
>> 2. **Python Version:** What version of Python is installed on your 
>> system? You can find this information by running the command `python 
>> --version` in your terminal.
>>
>> 3. **Virtual Environment:** Are you working within a virtual environment? 
>> If so, have you activated the virtual environment before attempting to run 
>> the project?
>>
>> 4. **Project Configuration:** Could you share any relevant configuration 
>> details related to your project setup? This could include how your project 
>> is structured and any configuration files that may be relevant.
>>
>> 5. **Django Installation:** Confirm whether Django is installed in your 
>> virtual environment. You can use the command `pip show django` to check its 
>> status.
>>
>> 6. **PYTHONPATH:** If you've made any modifications to the PYTHONPATH 
>> environment variable, please share the details of those changes.
>>
>> 7. **Build Process:** Briefly describe the steps you take leading up to 
>> encountering the error. This could include any commands you run or actions 
>> you perform.
>>
>> By providing these details, I'll be able to narrow down the potential 
>> causes of the ImportError and offer more precise guidance to help you 
>> resolve it.
>>
>> Thank you for your cooperation. I look forward to receiving more 
>> information from you so that we can work together to address this issue 
>> effectively.
>>
>> Best regards,
>> [Abhijit]
>>
>

-- 
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/26841f5c-b7f7-47e0-aa59-12afbbd73b45n%40googlegroups.com.


Re: pytest, asgiref, Selenium and database access? How to make them work?

2023-09-07 Thread Luciano Martins (luxu)
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.


Re: pytest, asgiref, Selenium and database access? How to make them work?

2023-09-07 Thread David Nugent
install pytest-django
use fixture @pytest.mark.db
profit

On 5 September 2023 at 08:15:10, Alfons Eberle (alfons.sig...@gmail.com)
wrote:

> 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='t...@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/7281f73c-dcbb-418f-acf1-dd4f5f065cc9n%40googlegroups.com
> 
> .
>

-- 
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/CAE5VhgVtiekG%3DD_p8SuuDLceJhgK%3D2R6A_p4yBRNMn3RR1JTuA%40mail.gmail.com.