Skip to content

Commit 677af1c

Browse files
authored
docs(development/testing) Docs about temporary test models (#10963)
Added a section about temporary models which can be used when developer needs to test a behaviour of a feature that is not tied to a specific model (e.g. custom lookup, or custom field).
1 parent 303d257 commit 677af1c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

develop-docs/development/testing.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ If the test runner detects that you used the Django `TestCase` class but you did
135135
end up needing it, it will yell at you. This protects you against other
136136
developers yelling at you later for slowing down CI.
137137

138+
### Database tests on temporary models
139+
140+
If you have a use case where you need to test some behavior of a model (e.g. custom field, or custom lookup), those kind of test shouldn't be tied to the existent models since they can change at any time.
141+
142+
In the codebase, for this case, we have a special Django app `fixtures` which will not generate migrations, and models created as a part of this app won't end up in the production, but will only exist during the duration of the test. There are [multiple examples](https://github.com/getsentry/sentry/blob/774af7dc287a1f9199ce855953c9e9184d8bb9c5/tests/sentry/db/models/fields/test_jsonfield.py) of this in our codebase.
143+
144+
To create test models, modify the `Meta` of your test model, and assign the model to the `fixtures` app:
145+
146+
```python
147+
class MyTestModel(models.Model):
148+
... # some fields
149+
150+
class Meta:
151+
app_label = "fixtures"
152+
153+
```
154+
138155
### External Services
139156

140157
Use the `responses` library to add stub responses for an outbound API requests your code is making.

0 commit comments

Comments
 (0)