A
A
Alexey Semyonov2019-05-15 19:20:57
Django
Alexey Semyonov, 2019-05-15 19:20:57

When writing a unit test to save/change a model, how do you get rid of the FK in Django?

I use pytest for unit tests. The situation is such that I want to test, for example, the creation of a new record.
1. I'm trying to create an object through pytest. The problem is that it is necessary to create third-party objects in order to fill in the required FK field (and they also have mandatory FKs, etc.). That's why there is such a complexity
2. I'm trying to create an object through mock. I mock the object and substitute my value, but the problem is that the object is not actually created, and I'm just juggling the data here.
That's why I'm looking for a better solution.
Ps or maybe you can somehow create an object in 1 way, only all FK could not be filled.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2019-05-15
@sim3x

KISS
Create mandatory records
Tests must be dumb as a cork

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question