|
22 | 22 | from enterprise_subsidy.apps.content_metadata.constants import ProductSources |
23 | 23 | from enterprise_subsidy.apps.fulfillment.api import InvalidFulfillmentMetadataException |
24 | 24 | from enterprise_subsidy.apps.fulfillment.exceptions import IncompleteContentMetadataException |
| 25 | +from enterprise_subsidy.apps.subsidy.constants import ALLOW_LATE_ENROLLMENT_KEY |
25 | 26 | from test_utils.utils import MockResponse |
26 | 27 |
|
27 | 28 | from ..models import ContentNotFoundForCustomerException, PriceValidationError, Subsidy |
@@ -472,6 +473,39 @@ def test_redeem_with_metadata( |
472 | 473 | assert new_transaction.quantity == -mock_content_price |
473 | 474 | assert new_transaction.metadata == tx_metadata |
474 | 475 |
|
| 476 | + @mock.patch('enterprise_subsidy.apps.subsidy.models.Subsidy.price_for_content') |
| 477 | + @mock.patch('enterprise_subsidy.apps.subsidy.models.Subsidy.enterprise_client') |
| 478 | + @mock.patch("enterprise_subsidy.apps.content_metadata.api.ContentMetadataApi.get_content_summary") |
| 479 | + def test_redeem_late_enrollment_requires_resolved_course_run( |
| 480 | + self, mock_get_content_summary, mock_enterprise_client, mock_price_for_content |
| 481 | + ): |
| 482 | + """ |
| 483 | + Late enrollment should not attempt LMS enrollment when catalog metadata has no concrete run. |
| 484 | + """ |
| 485 | + lms_user_id = 1 |
| 486 | + content_key = "edX+test" |
| 487 | + subsidy_access_policy_uuid = str(uuid4()) |
| 488 | + mock_get_content_summary.return_value = { |
| 489 | + 'content_uuid': 'edX+test', |
| 490 | + 'content_key': 'edX+test', |
| 491 | + 'content_title': 'edx: Test Course', |
| 492 | + 'source': 'edX', |
| 493 | + 'mode': 'verified', |
| 494 | + 'content_price': 10000, |
| 495 | + 'geag_variant_id': None, |
| 496 | + } |
| 497 | + mock_price_for_content.return_value = 1000 |
| 498 | + |
| 499 | + with self.assertRaisesRegex(ContentNotFoundForCustomerException, 'exact course run key'): |
| 500 | + self.subsidy.redeem( |
| 501 | + lms_user_id, |
| 502 | + content_key, |
| 503 | + subsidy_access_policy_uuid, |
| 504 | + metadata={ALLOW_LATE_ENROLLMENT_KEY: True}, |
| 505 | + ) |
| 506 | + |
| 507 | + mock_enterprise_client.enroll.assert_not_called() |
| 508 | + |
475 | 509 | @mock.patch('enterprise_subsidy.apps.subsidy.models.is_geag_fulfillment', return_value=True) |
476 | 510 | @mock.patch('enterprise_subsidy.apps.subsidy.models.Subsidy.price_for_content') |
477 | 511 | @mock.patch('enterprise_subsidy.apps.subsidy.models.Subsidy.enterprise_client') |
|
0 commit comments