#28983: Documentation on providing initial data with migrations is unhelpful -------------------------------------+------------------------------------- Reporter: Rob Atkinson | Owner: nobody Type: | Status: new Cleanup/optimization | Component: Documentation | Version: 2.0 Severity: Normal | Resolution: Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Tim Graham): Replying to [comment:2 Rob Atkinson]: > I have been using setUp() for the data, but there is some initial data i want autoloaded in all environments, and as this is part of the app i want to do unit tests on the loading process too. i got a bit lost in the deprecation discussion around fixtures - is this auto loading something we want to do in migrations? That sounds like meets the criteria for "If you want to automatically load initial data for an app, don’t use fixtures. Instead, create a migration for your application with RunPython or RunSQL operations." > > Then i want to add some additional data, currently using setUp() - but setUpTestCase() should be fine - but here the question is the inheritance one - if i am testing an app that extends this app - the perhaps the pattern is to import and extend the test case and inherit these methods too? If the extended add needs to add data - does it override setUpTestCase() and then call super.setUpTestCase()? That sounds fine. This is getting into rather specific issues that I don't think the Django documentation needs to get into. > Finally (and this is my ultimate use case) - i have an app that allows a user to load a file and process it using metadata they provide. This app is then extended for specialised resource types - so i want a test case for a FileField. > > IMHO the testing guidelines should cover (at least with links to more information) the following common patterns > > - separation of unit and integration tests (is testing parsing of an uploaded file in an app a unit test? - i can test the parser separately - but i want to unit test the selection and setup of the parser with the uploaded file and other user supplied metadata ) This is somewhat beyond the scope of Django's documentation. There might be best practices to follow, but in my opinion, that's left to other resources like books (e.g. Two Scoops of Django - Best Practices for Django X.Y). > - testing FileField CRUD operations (as these seem to require user code to handle cleanups then testing is vital - https://docs.djangoproject.com/en/2.0/topics/files/ does not provide information on how deletions are managed or testing processes - but if its handled automatically and we dont need to test this ourselves then lets add a note to explain that) I don't think so. It might be enhanced in #23251. > - testing views that use external services. (there are various references to mocking and third party tools, but this seems to be a key function and the docs are silent) - for example, we wouldnt have a government application locally that wouldnt use the mandated official external street address validation service Again, specific use cases like this isn't something that Django has an opinion on. -- Ticket URL: <https://code.djangoproject.com/ticket/28983#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/073.53c2d28f3ec6d7e8ddbf7de5cc7efc43%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.