As I develop the backend side, I also develop the frontend. As you have probably guessed, I have to do some REST requests on my server.
Well, there are a couple of solutions for that. I can use mocks on the frontend, or a fake JSON server. However, there are some cons to this approach:
- I have to remodel what I have on an already existing backend server.
- Dealing with authentication on a fake JSON server is not really comfortable.
- I have to write a lot of boilerplate if I want to go on mocking and unit testing approach.
Again, all the logic I want already exists in my Django project, so what I want is:
- Run a dev server.
- Set up a fresh new database.
- Provide some initial data. Some fake users, posts, whatever.
- Do my testing on my frontend project while the server runs.
- Hit the kill signal. (CTRL+C)
- Gracefully drop the database that I have created on step 2.
- Shutdown the program.
I use pytest
and pytest-django
. They do exactly these when they set up a test environment, I was wondering if I can manually do that.
Thanks in advance.
Environment
- Python 3.9
- Django 2.2