@@ -371,3 +371,51 @@ def test_register_password_hashing(self):
371371 user = User .objects .get (username = 'newuser' )
372372 self .assertNotEqual (user .password , 'newpass123' ) # Should be hashed
373373 self .assertTrue (user .check_password ('newpass123' )) # But should validate
374+
375+ class UserProfileViewTestCase (TestCase ):
376+ def setUp (self ):
377+ self .company = Company .objects .create (
378+ name = 'Test Company' ,
379+ address = '123 Test St' ,
380+ phone = '555-1234' ,
381+ email = 'test@company.com'
382+ )
383+
384+ self .user = User .objects .create_user (
385+ username = 'testuser' ,
386+ password = 'testpass123' ,
387+ email = 'test@user.com' ,
388+ first_name = 'Test' ,
389+ last_name = 'User'
390+ )
391+
392+ self .profile = UserProfile .objects .create (
393+ user = self .user ,
394+ company = self .company
395+ )
396+
397+ self .token = AuthToken .objects .create (user = self .user )
398+
399+ def test_get_profile (self ):
400+ """Test GET /api/auth/profile/ returns user profile data"""
401+ response = self .client .get ('/api/auth/profile/' ,
402+ headers = {'Authorization' : f'Token { self .token .key } ' }
403+ )
404+
405+ self .assertEqual (response .status_code , 200 )
406+ data = response .json ()
407+
408+ self .assertEqual (data ['id' ], self .user .id )
409+ self .assertEqual (data ['username' ], 'testuser' )
410+ self .assertEqual (data ['email' ], 'test@user.com' )
411+ self .assertEqual (data ['first_name' ], 'Test' )
412+ self .assertEqual (data ['last_name' ], 'User' )
413+ self .assertEqual (data ['company_id' ], self .company .id )
414+ self .assertEqual (data ['company_name' ], 'Test Company' )
415+
416+ def test_get_profile_no_auth (self ):
417+ """Test GET /api/auth/profile/ without authentication returns 401"""
418+ response = self .client .get ('/api/auth/profile/' )
419+ self .assertEqual (response .status_code , 401 )
420+ data = response .json ()
421+ self .assertEqual (data ['error' ], 'Authentication required' )
0 commit comments