@@ -28,7 +28,6 @@ def valid_registration_data():
2828 email = "test@example.com" ,
2929 reason = "Need access to BPA resources" ,
3030 password = "SecurePass123!" ,
31- organizations = BPARegistrationDataFactory .get_default_organizations (),
3231 ).model_dump ()
3332
3433
@@ -50,22 +49,17 @@ def test_to_biocommons_register_data(valid_registration_data):
5049
5150
5251def test_successful_registration (
53- test_client_with_email , mocker , valid_registration_data ,
54- mock_auth0_client , test_db_session
52+ test_client , valid_registration_data , mock_auth0_client , test_db_session
5553):
5654 """Test successful user registration with BPA service"""
57- test_client = test_client_with_email
5855 user_id = random_auth0_id ()
5956 mock_auth0_client .create_user .return_value = Auth0UserDataFactory .build (user_id = user_id )
60- mock_email_cls = mocker .patch ("routers.bpa_register.EmailService" , autospec = True )
61- mock_email_cls .return_value .send .return_value = None
6257
6358 response = test_client .post ("/bpa/register" , json = valid_registration_data )
6459
6560 assert response .status_code == 200
6661 assert response .json ()["message" ] == "User registered successfully"
6762
68- mock_email_cls .return_value .send .assert_called_once ()
6963 # Check user is created in the database
7064 db_user = test_db_session .get (BiocommonsUser , user_id )
7165 assert db_user is not None
@@ -95,12 +89,7 @@ def test_successful_registration(
9589 assert bpa_service .status == "pending"
9690 assert bpa_service .last_updated is not None
9791 assert bpa_service .updated_by == "system"
98- assert len (bpa_service .resources ) == 2
99-
100- for resource in bpa_service .resources :
101- assert resource .last_updated is not None
102- assert resource .initial_request_time is not None
103- assert resource .updated_by == "system"
92+ assert len (bpa_service .resources ) == 0
10493
10594 assert (
10695 called_data .user_metadata .bpa .registration_reason
@@ -165,25 +154,11 @@ def test_registration_auth0_error(
165154 assert response .json ()["message" ] == "Auth0 error: Something went wrong"
166155
167156
168- def test_registration_with_invalid_organization (
169- test_client , valid_registration_data
170- ):
171- """Test registration with invalid organization ID"""
172- data = valid_registration_data .copy ()
173- data ["organizations" ] = {"invalid-org-id" : True }
174-
175- response = test_client .post ("/bpa/register" , json = data )
176-
177- assert response .status_code == 400
178- assert "Invalid organization ID" in response .json ()["detail" ]
179-
180-
181157def test_registration_request_validation (test_client ):
182158 """Test request validation"""
183159 invalid_data = {
184160 "username" : "testuser" ,
185161 "email" : "invalid-email" ,
186- "organizations" : {},
187162 }
188163
189164 response = test_client .post ("/bpa/register" , json = invalid_data )
@@ -194,45 +169,6 @@ def test_registration_request_validation(test_client):
194169 assert any (error ["field" ] == "email" for error in error_data ["field_errors" ])
195170
196171
197- def test_no_selected_organizations (
198- test_client , test_db_session , mock_auth0_client , valid_registration_data
199- ):
200- """Test registration with no organizations selected"""
201- data = valid_registration_data .copy ()
202- data ["organizations" ] = {
203- "bpa-bioinformatics-workshop" : False ,
204- "cipps" : False ,
205- "ausarg" : False ,
206- }
207- user_data = Auth0UserDataFactory .build ()
208- mock_auth0_client .create_user .return_value = user_data
209-
210- response = test_client .post ("/bpa/register" , json = data )
211-
212- assert response .status_code == 200
213- # Check user data sent to Auth0
214- called_data = mock_auth0_client .create_user .call_args [0 ][0 ]
215- bpa_service = called_data .app_metadata .services [0 ]
216- assert len (bpa_service .resources ) == 0
217-
218-
219- def test_empty_organizations_dict (
220- test_client , test_db_session , mock_auth0_client , valid_registration_data
221- ):
222- """Test registration with empty organizations dictionary"""
223- data = valid_registration_data .copy ()
224- data ["organizations" ] = {}
225- user_data = Auth0UserDataFactory .build ()
226- mock_auth0_client .create_user .return_value = user_data
227-
228- response = test_client .post ("/bpa/register" , json = data )
229-
230- assert response .status_code == 200
231- called_data = mock_auth0_client .create_user .call_args [0 ][0 ]
232- bpa_service = called_data .app_metadata .services [0 ]
233- assert len (bpa_service .resources ) == 0
234-
235-
236172def test_registration_email_format (test_client , valid_registration_data ):
237173 """Test email format validation"""
238174 data = valid_registration_data .copy ()
@@ -244,31 +180,3 @@ def test_registration_email_format(test_client, valid_registration_data):
244180 details = response .json ()
245181 errors = details ["field_errors" ]
246182 assert "email" in [error ["field" ] for error in errors ]
247-
248-
249- def test_all_organizations_selected (
250- test_client_with_email ,
251- test_db_session ,
252- mock_settings ,
253- mocker ,
254- mock_auth0_client ,
255- valid_registration_data ,
256- ):
257- """Test registration with all organizations selected"""
258- data = valid_registration_data .copy ()
259- data ["organizations" ] = {k : True for k in mock_settings .organizations .keys ()}
260-
261- user_data = Auth0UserDataFactory .build ()
262- mock_auth0_client .create_user .return_value = user_data
263-
264- email_service_cls = mocker .patch ("routers.bpa_register.EmailService" , autospec = True )
265- email_service_cls .return_value .send .return_value = True
266-
267- response = test_client_with_email .post ("/bpa/register" , json = data )
268-
269- assert response .status_code == 200
270- called_data = mock_auth0_client .create_user .call_args [0 ][0 ]
271- bpa_service = called_data .app_metadata .services [0 ]
272- assert len (bpa_service .resources ) == len (mock_settings .organizations )
273-
274- email_service_cls .return_value .send .assert_called_once ()
0 commit comments