|
9 | 9 | from waffle.testutils import override_switch |
10 | 10 |
|
11 | 11 | from marsha.account.social_pipeline import MARSHA_DEFAULT_AUTH_PIPELINE |
12 | | -from marsha.account.social_pipeline.social_auth import auth_allowed, social_details |
| 12 | +from marsha.account.social_pipeline.social_auth import ( |
| 13 | + associate_by_email, |
| 14 | + auth_allowed, |
| 15 | + social_details, |
| 16 | +) |
13 | 17 | from marsha.core.defaults import RENATER_FER_SAML |
14 | 18 |
|
15 | 19 |
|
@@ -188,3 +192,87 @@ def test_social_details_step_without_names(self): |
188 | 192 | social_details(backend, details, response=None), |
189 | 193 | {"details": {"first_name": "", "last_name": ""}}, |
190 | 194 | ) |
| 195 | + |
| 196 | + |
| 197 | +class AssociateByEmailPipelineTestCase(TestCase): |
| 198 | + """Test case for the `associate_by_email` pipeline step.""" |
| 199 | + |
| 200 | + maxDiff = None |
| 201 | + |
| 202 | + def test_marsha_pipeline_includes_associate_by_email_step(self): |
| 203 | + """Asserts the `associate_by_email` step is in Marsha's default pipeline.""" |
| 204 | + self.assertListEqual( |
| 205 | + [ |
| 206 | + "marsha.account.social_pipeline.social_auth.social_details", |
| 207 | + "social_core.pipeline.social_auth.social_uid", |
| 208 | + "marsha.account.social_pipeline.social_auth.auth_allowed", |
| 209 | + "social_core.pipeline.social_auth.social_user", |
| 210 | + "social_core.pipeline.user.get_username", |
| 211 | + "marsha.account.social_pipeline.social_auth.associate_by_email", |
| 212 | + "social_edu_federation.pipeline.user.create_user", |
| 213 | + "social_core.pipeline.social_auth.associate_user", |
| 214 | + "social_core.pipeline.social_auth.load_extra_data", |
| 215 | + "social_core.pipeline.user.user_details", |
| 216 | + "marsha.account.social_pipeline.organization.create_organization_from_saml", |
| 217 | + "marsha.account.social_pipeline.playlist.create_playlist_from_saml", |
| 218 | + ], |
| 219 | + MARSHA_DEFAULT_AUTH_PIPELINE, |
| 220 | + msg="MARSHA_DEFAULT_AUTH_PIPELINE must be fixed to include `associate_by_email`", |
| 221 | + ) |
| 222 | + |
| 223 | + self.assertListEqual( |
| 224 | + [ |
| 225 | + "marsha.account.social_pipeline.social_auth.social_details", |
| 226 | + "social_core.pipeline.social_auth.social_uid", |
| 227 | + "marsha.account.social_pipeline.social_auth.auth_allowed", |
| 228 | + "social_core.pipeline.social_auth.social_user", |
| 229 | + "social_core.pipeline.user.get_username", |
| 230 | + "marsha.account.social_pipeline.social_auth.associate_by_email", |
| 231 | + "social_edu_federation.pipeline.user.create_user", |
| 232 | + "social_core.pipeline.social_auth.associate_user", |
| 233 | + "social_core.pipeline.social_auth.load_extra_data", |
| 234 | + "social_core.pipeline.user.user_details", |
| 235 | + "marsha.account.social_pipeline.organization.create_organization_from_saml", |
| 236 | + "marsha.account.social_pipeline.playlist.create_playlist_from_saml", |
| 237 | + ], |
| 238 | + settings.SOCIAL_AUTH_SAML_FER_PIPELINE, |
| 239 | + msg="SOCIAL_AUTH_SAML_FER_PIPELINE must be fixed to include `associate_by_email`", |
| 240 | + ) |
| 241 | + |
| 242 | + @override_switch(RENATER_FER_SAML, active=True) |
| 243 | + def test_associate_by_email_step_enabled(self): |
| 244 | + """Asserts the email is used to associate the user when the waffle switch is enabled.""" |
| 245 | + strategy = load_strategy() |
| 246 | + backend = load_backend(strategy, "saml_fer", None) |
| 247 | + with mock.patch( |
| 248 | + "marsha.account.social_pipeline.social_auth.social_associate_by_email" |
| 249 | + ) as social_associate_by_email_mock: |
| 250 | + details = {"not": "relevant"} |
| 251 | + |
| 252 | + associate_by_email(backend, details, strategy, 42, some_kwargs=18) |
| 253 | + |
| 254 | + social_associate_by_email_mock.assert_called_once_with( |
| 255 | + backend, |
| 256 | + details, |
| 257 | + None, |
| 258 | + strategy, |
| 259 | + 42, |
| 260 | + some_kwargs=18, |
| 261 | + ) |
| 262 | + |
| 263 | + @override_switch(RENATER_FER_SAML, active=False) |
| 264 | + def test_associate_by_email_step_disabled(self): |
| 265 | + """ |
| 266 | + Asserts the email is not used to associate the user when the waffle switch is disabled. |
| 267 | + """ |
| 268 | + strategy = load_strategy() |
| 269 | + backend = load_backend(strategy, "saml_fer", None) |
| 270 | + with mock.patch( |
| 271 | + "marsha.account.social_pipeline.social_auth.social_associate_by_email" |
| 272 | + ) as social_associate_by_email_mock: |
| 273 | + details = {"not": "relevant"} |
| 274 | + |
| 275 | + self.assertIsNone( |
| 276 | + associate_by_email(backend, details, strategy, 42, some_kwargs=18) |
| 277 | + ) |
| 278 | + self.assertFalse(social_associate_by_email_mock.called) |
0 commit comments