@@ -3454,3 +3454,57 @@ async def test_can_create_neon_account(self, mock_neon_client) -> None:
3454
3454
3455
3455
await up .arefresh_from_db ()
3456
3456
self .assertEqual (up .neon_account_id , "9876" )
3457
+
3458
+
3459
+ @override_settings (DEVELOPMENT = False )
3460
+ @patch ("cl.users.views.create_neon_account" )
3461
+ @patch ("cl.users.views.update_neon_account" )
3462
+ class NeonAccountUpdateTest (TestCase ):
3463
+
3464
+ def setUp (self ) -> None :
3465
+ self .client = AsyncClient ()
3466
+ self .up = UserProfileWithParentsFactory .create (
3467
+ user__username = "pandora" ,
3468
+ user__password = make_password ("password" ),
3469
+ )
3470
+
3471
+ async def test_can_call_update_task_when_account_id_found (
3472
+ self , update_account_mock , create_account_mock
3473
+ ) -> None :
3474
+ """Tests whether we use the update task when the account has a neon_account_id"""
3475
+ self .up .neon_account_id = "12345"
3476
+ await self .up .asave ()
3477
+
3478
+ await self .client .alogin (username = "pandora" , password = "password" )
3479
+ r = await self .client .post (
3480
+ reverse ("view_settings" ),
3481
+ {
3482
+ "first_name" : "test_name" ,
3483
+ "last_name" : "test_last_name" ,
3484
+ "email" : self .up .user .email ,
3485
+ },
3486
+ follow = True ,
3487
+ )
3488
+
3489
+ self .assertEqual (r .status_code , HTTP_200_OK )
3490
+ update_account_mock .delay .assert_called_once_with (self .up .user .pk )
3491
+ create_account_mock .delay .assert_not_called ()
3492
+
3493
+ async def test_can_call_create_task_when_no_account_id_found (
3494
+ self , update_account_mock , create_account_mock
3495
+ ) -> None :
3496
+ """Tests whether we use the create task when the account does not have a neon_account_id"""
3497
+ await self .client .alogin (username = "pandora" , password = "password" )
3498
+ r = await self .client .post (
3499
+ reverse ("view_settings" ),
3500
+ {
3501
+ "first_name" : "test_name" ,
3502
+ "last_name" : "test_last_name" ,
3503
+ "email" : self .up .user .email ,
3504
+ },
3505
+ follow = True ,
3506
+ )
3507
+
3508
+ self .assertEqual (r .status_code , HTTP_200_OK )
3509
+ create_account_mock .delay .assert_called_once_with (self .up .user .pk )
3510
+ update_account_mock .delay .assert_not_called ()
0 commit comments