Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is Permission table populated in test database, while others aren't (django python)?

While playing around with django testing I noticed that Permission table in test database is not empty (like, for example, User and tables of models defined by me) – it has all permissions from the real table.
pdb

My questions:

  1. Is the Permission table the only prepopulated table? (I have trouble inspecting other tables, because db is in-memory)
  2. Where is it prepopulated (I also couldn’t find)? Upon setting up test suit? Or just before executing each test method? Or maybe added to queryset everytime it is requested?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Permissions are created when you run manage.py migrate, there is a signal handler that listens to the post_migrate signal and creates these permissions for every new model.

Docs

The ContentType table will also be populated in a similar manner

When you run your tests, your test DB will have your migrations applied to it

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading