Coverage for src/common/management/commands/setup_database.py: 0%

25 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-08-04 12:59 +0300

1from django.core.management.base import BaseCommand 

2from django.core.management import call_command 

3 

4# python manage.py setup_database 

5 

6 

7class Command(BaseCommand): 

8 help = 'Setup database with products, reviews, and roles' 

9 

10 def handle(self, *args, **options): 

11 self.stdout.write(self.style.SUCCESS('🚀 Starting database setup...')) 

12 

13 try: 

14 self.stdout.write( 

15 self.style.SUCCESS('📦 Step 1/4: Creating products...') 

16 ) 

17 call_command('create_products') 

18 self.stdout.write( 

19 self.style.SUCCESS('✅ Products created successfully!') 

20 ) 

21 

22 self.stdout.write( 

23 self.style.SUCCESS('⭐ Step 2/4: Creating reviews...') 

24 ) 

25 call_command('create_reviews') 

26 self.stdout.write( 

27 self.style.SUCCESS('✅ Reviews created successfully!') 

28 ) 

29 

30 self.stdout.write( 

31 self.style.SUCCESS('👥 Step 3/4: Creating roles and users...') 

32 ) 

33 call_command('create_roles') 

34 self.stdout.write( 

35 self.style.SUCCESS('✅ Roles and users created successfully!') 

36 ) 

37 

38 self.stdout.write( 

39 self.style.SUCCESS('🏠 Step 4/4: Creating addresses...') 

40 ) 

41 

42 self.stdout.write( 

43 self.style.SUCCESS( 

44 '\n🎉 Database setup completed successfully!' 

45 ) 

46 ) 

47 self.stdout.write(self.style.SUCCESS('🔑 Admin credentials:')) 

48 self.stdout.write(' • Super User: super_user@mail.com | !1Aabb') 

49 self.stdout.write( 

50 ' • Inventory User: inventory_user@mail.com | !1Aabb' 

51 ) 

52 self.stdout.write(' • Order User: order_user@mail.com | !1Aabb') 

53 

54 except Exception as e: 

55 self.stdout.write( 

56 self.style.ERROR(f'❌ Error during setup: {str(e)}') 

57 ) 

58 raise e