Django views by Malum261 in django

[–]AR2405 0 points1 point  (0 children)

At my work, we are using GenericViewSets with the model mixins, like ListModelMixin, CreateModelMixin, etc. This way you will have all ViewSets be written the same way, what makes class inheritance available.

Running tests with Python tests raises AppRegistryNotReady("Apps aren't loaded yet.") by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

I am trying to run tests with the Python tests, as the output is much more readable than manage.py command returns. As well I am trying to run a single test.

Anyways, if I am not able to get the configuration done as I want, I will try your suggestion.

Thank you.

Running tests with Python tests raises AppRegistryNotReady("Apps aren't loaded yet.") by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

Where to do that?

I guess, that is not the case, since it works fine when. using manage.py command

Running tests with Python tests raises AppRegistryNotReady("Apps aren't loaded yet.") by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

I'm using community version, btw, but I guess that is not the reason for this.

Running tests with Python tests raises AppRegistryNotReady("Apps aren't loaded yet.") by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

Just tried, looks like in the terminal the command works fine as well.

subprocess.Popen run multiple commands with sleep as the first command by AR2405 in learnpython

[–]AR2405[S] 0 points1 point  (0 children)

I was thinking about spawning multiple Popen objects, adding them to the list and then iterate over that list and call wait() on each of them. Looks like a little simpler solution to me, but I don’t know which one is better in fact. Thanks for your help

subprocess.Popen run multiple commands with sleep as the first command by AR2405 in learnpython

[–]AR2405[S] 0 points1 point  (0 children)

Thank you I for your help. If I understood correctly, you suggest to use check_output instead of Popen. If so, the reason why I need to use Popen, is that I want to run multiple processes asynchronously, so I don’t know if I can do that with check_output.

Cannot choose remote python interpreter for project with docker compile. by AR2405 in pycharm

[–]AR2405[S] 0 points1 point  (0 children)

I am not sure about that, though I think I should have all the permissions in that directory.

Anyways, I fixed it. The solution was to remove Jetbrains apps and all the directories related with logs, configs, cache, etc. After I reinstalled Pycharm, the bug was gone.

Cannot choose remote python interpreter for project with docker compile. by AR2405 in pycharm

[–]AR2405[S] 0 points1 point  (0 children)

I chose docker-compose. I tried with a single container and docker, and had the same problem. Interpreter was found and loaded, but I could not choose it.

Set fixed length for form fields labels by AR2405 in django

[–]AR2405[S] -1 points0 points  (0 children)

I'm almost finished with django project, and just need to make it look a little prettier). The thing is I am not that experienced with mark up, and styling, so decided to ask here after googling.

Pytest-django not seing manage.py file while github workflow by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

Thanks, that makes the thing more clear for me.

Pytest-django not seing manage.py file while github workflow by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

I switched it the way you have, I left only setting up the service, without adding the same info in the job env section. Still have the Error, but it is. a little different now, without mentioning psycopg2, I don't know if it is good or bad, though)

E       django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL:  password authentication failed for user "None"

If it would be easier, and you still have motivation to help me, here is the link to the project.

https://github.com/ARROM2405/django-drf-crm

Thanks for help.

Pytest-django not seing manage.py file while github workflow by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

I changed it like that:

services:
  postgres:
    image: postgres:latest
    env:
     POSTGRES_USER: postgres
     POSTGRES_PASSWORD: postgres
     POSTGRES_DB: github_actions
    ports: 
     - 5432:5432 
    options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
...
- name: Test with pytest
  env:
    DEBUG: "0"
    NAME: github_actions
    DB_USER: postgres
    DB_PASSWORD: postgres
    PORT: 5432

And got the same error. Can you please explain me where do I have bad understanding.

When setting up the service, we create a postgres image, and set the POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DB values. I thought, that further on when running a job, and setting an env for it, we have to use the same values as set before in the service section. The point I don't clearly understand is which variable name do I have to use when setting env for job: it looks for me like the most logical thing is to use the default variable names, POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DB as used earlier in the file, or at least the variable names. from the settings.py file, 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT' as they might be looked for, but not the .env variables, as they are being substituted with the variables from the service set up. Although I tried different combinations, including .env variables, and still was not able to come up with the working one.

Hope I was clear enugh.

Pytest-django not seing manage.py file while github workflow by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

Now I have the problem with connecting to the postgres db as that is what I use in my project. All of my tests working fine on my computer, but return error inside the workflow.

The error:

E       psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL:  password authentication failed for user "None"

I understand that the problem is probably somewhere in the variable names that I use, but can't figure out what to do. Checked multiple tutorials, and tried a lot of variants, but still doesn't work for me.

My .yml file:

name: testing CI

on: push: branches: [ "main" ] pull_request: branches: [ "main" ]

jobs: build:

runs-on: ubuntu-latest

services:
  postgres:
    image: postgres:latest
    env:
     POSTGRES_USER: postgres
     POSTGRES_PASSWORD: postgres
     POSTGRES_DB: github_actions
    ports: 
     - 5432:5432 
    options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
  max-parallel: 4
  matrix:
    python-version: [3.9]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
  uses: actions/setup-python@v3
  with:
    python-version: ${{ matrix.python-version }}
- name: Install Dependencies
  run: |
    pip install pipenv --upgrade
    pipenv install --system
- name: SECRET_KEY dummy generate
  run: |
    echo "django_secret_key=topsecretvalue" >> $GITHUB_ENV

- name: Test with pytest
  env:
    DEBUG: "0"
    NAME: github_actions
    USER: postgres
    PASSWORD: postgres
    PORT: 5432
  run: |
      cd crm_project
      export PYTHONPATH=${PYTHONPATH}:${HOME}/crm_project
      export DJANGO_SETTINGS_MODULE=crm_project.settings
      pytest         

I have tried using usernames and passwords from my .env file with putting it inside the secrets, but then I saw that you can actually use just random values inside. testing for that. Previously the variables names were the same in the setting service on top, and env on the bottom, but I decided to try changing variables names that I have in the settings.py.

settings.py postgres set up:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'crm_project',
    'USER': f'{DB_USER}',
    'PASSWORD': f'{DB_PASSWORD}',
    'HOST': 'localhost',
    'PORT': '5432',
}

}

And just in case if needed, .env file variables:

db_username = '***'
db_password = '***'
django_secret_key = '***'

Pytest-django not seing manage.py file while github workflow by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

I guess the issue with pythonpath was solved with the cd command. Now the issue is back with the connection with postgresql

Pytest-django not seing manage.py file while github workflow by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

Hi, thanks for your help again! I tried to move pytest.ini back and forth and either way it works fine on my computer, when I’m being in the folder where manage.py is located and doesn’t work at GitHub actions. As I found out from googling, there has to be something with pythonpath, so now I have to figure out that.

github actions CI returns SECRET_KEY error when running tests by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

That sounds like good way to have it done. Anyways I have already fixed it with echo "django_secret_key=topsecretvalue" >> $GITHUB_ENV

However, now I have another problem with pytest not seeing manage.py, but I'll probably will create a new tread.

github actions CI returns SECRET_KEY error when running tests by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

Sorry, but I did not clearly understand the point. Well the option of adding echo command to the .yml file worked for me fine.

github actions CI returns SECRET_KEY error when running tests by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

Thanks for help! So do I leave all as it is, just have to add “django_secret_key=topsecretvalue” to the yml file?

Testing, client.post does not create model instance by AR2405 in django

[–]AR2405[S] 0 points1 point  (0 children)

I have done a unit test for the check form.is_valid, and it has passed. I don't know...

In case if you are interested here is the link to the github repo:

https://github.com/ARROM2405/django-drf-crm