paulocheque / django-dynamic-fixture

A complete library to create dynamic model instances for testing purposes.
http://django-dynamic-fixture.readthedocs.io/
Other
391 stars 67 forks source link

[bugfix] Set shorter verbose names for models #16

Closed michaelmior closed 11 years ago

michaelmior commented 11 years ago

This avoids hitting the 50-character limit of automatically generated Django permission names.

Not sure if this issue occurs with older versions of Django, but in Django 1.5, the names generated for the default add, change, and delete permissions end up being too long for the 50 characters field in auth_permissions. I simply set verbose_name for each model to something a bit shorter.

michaelmior commented 11 years ago

Just a note that there's no test for this right now. One option could be to get the verbose name for each model and construct the permission name as Django would to make sure it doesn't hit the limit.

paulocheque commented 11 years ago

Hi there. Thanks a lot for reporting, I will merge this pull request.

I just do not consider this a bug, but a test-fix, that is the reason I set it to 'enhancement'.

Regards

michaelmior commented 11 years ago

Well, if the app is added to INSTALLED_APPS, this will cause syncdb to fail. This doesn't happen only when running tests.

It's not picked up in the test environment since sqlite lets you pretty much insert anything anywhere. Anyway, thanks for the merge!

paulocheque commented 11 years ago

Oh, absolutely! So I agree, I will change the label! ;) Thanks for commenting!

paulocheque commented 11 years ago

Maybe a better solution is to generate a distribution package without models and tests, to avoid any similar problem. What do you think?

michaelmior commented 11 years ago

Seems like a lot of extra complexity. Personally I like to be able be able to just pip install foo and have everything work and I'm not sure that's achievable in a clean way with a separate distribution package.

It would be nice not to have the models installed when not running tests anyway though. This ticket from the Django tracker suggests some ways of handling the problem of having models defined only for tests.

I like the approach @jphalip uses of modifying INSTALLED_APPS during tests and then manually calling syncdb.

michaelmior commented 11 years ago

Actually, I just realized that django_nose will allow you to put models in any file (they suggest test_models.py) and when it is imported in tests, the models will be created automatically. That seems like the cleanest solution.

I tried this out by just renaming models.py to test_models.py and it seems to work as expected. These seems like the cleanest solution IMO.