tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.58k stars 378 forks source link

Fix TestCase | only "models" works as app_label #1457

Open esrehmki opened 1 year ago

esrehmki commented 1 year ago
- in the current implementation only "models" works as app_label
- there is no way to change that during run time as it's hard coded
- the fix introduces another _APP_LABEL global variable that is set
   in the initializer

Enables testing of apps with other labels than "models" in test classes of tortoise/contrib/test automagically from the TORTOISE_ORM config dict.

Description

Following the design of the file, a new global variable is introduced that is defined during the call of the initializer function. Later occurences of the app_label function parameter in _setUpDB member functions, that don't expose the app_label variable, are provided with _APP_LABEL as default value.

Motivation and Context

App labels other than 'models' were not correctly propagated to the test functions, as 'models' was hardcoded as app_label in the _setUpDB member functions.

How Has This Been Tested?

Existing tests of the package pass.

Checklist: