Open
Description
Code of Conduct
- I agree to follow Django's Code of Conduct
Feature Description
Allow Django to generate mock data for MSW in the frontend by reusing existing FactoryBoy + Faker factories. The mock data can be exported as a JSON file or JavaScript handler file that MSW can directly use.
Problem
Right now, we're writing mock data twice: once in Django (with factories) and again manually in MSW. This causes duplication and makes it easy for frontend mocks to fall out of sync with backend models.
Request or proposal
proposal
Additional Details
- The goal is for Django to remain the single source of truth for mock data
- Could support output as
.json
or.js
(with MSW handlers) - Faker could be seeded for consistent results
- Ideal output lives in or near the Django project, not separately in the frontend
Implementation Suggestions
# Django command (pseudo)
from myapp.factories import PersonFactory
data = PersonFactory.create_batch(10)
# Save to JSON for MSW
with open('frontend/mocks/people.json', 'w') as f:
json.dump(data, f)
// MSW in React
import people from './mocks/people.json'
export const handlers = [
rest.get('/api/people', (req, res, ctx) => {
return res(ctx.status(200), ctx.json(people))
})
]
Metadata
Metadata
Assignees
Type
Projects
Status
Idea