|
3 | 3 | import faker |
4 | 4 | import pytest |
5 | 5 |
|
6 | | -from b2b.factories import ContractPageFactory |
7 | | -from courses.factories import ( |
8 | | - CourseRunFactory, |
9 | | - ProgramFactory, |
10 | | -) |
| 6 | +from b2b.factories import ContractPageFactory, OrganizationPageFactory |
| 7 | +from courses.factories import CourseRunFactory, ProgramFactory |
11 | 8 |
|
12 | 9 | pytestmark = [pytest.mark.django_db] |
13 | 10 | FAKE = faker.Faker() |
@@ -53,3 +50,45 @@ def test_add_program_courses_to_contract(mocker): |
53 | 50 |
|
54 | 51 | assert contract.programs.count() == 1 |
55 | 52 | assert contract.get_course_runs().count() == 4 |
| 53 | + |
| 54 | + |
| 55 | +def test_organization_page_slug_preserved_on_name_change(): |
| 56 | + """Test that the slug is not regenerated when only the name changes.""" |
| 57 | + org = OrganizationPageFactory.create(name="MIT") |
| 58 | + original_slug = org.slug |
| 59 | + |
| 60 | + # Change the name |
| 61 | + org.name = "MIT - Universal AI" |
| 62 | + org.save() |
| 63 | + org.refresh_from_db() |
| 64 | + |
| 65 | + # The slug should not have changed |
| 66 | + assert org.slug == original_slug |
| 67 | + # But the title should reflect the new name |
| 68 | + assert org.title == "MIT - Universal AI" |
| 69 | + |
| 70 | + |
| 71 | +def test_organization_page_slug_generated_on_create(): |
| 72 | + """Test that the slug is generated when creating a new organization.""" |
| 73 | + org = OrganizationPageFactory.create(name="Test Organization", slug="") |
| 74 | + |
| 75 | + # The slug should have been generated |
| 76 | + assert org.slug == "org-test-organization" |
| 77 | + assert org.title == "Test Organization" |
| 78 | + |
| 79 | + |
| 80 | +def test_organization_page_slug_not_overwritten_if_set(): |
| 81 | + """Test that a manually set slug is not overwritten.""" |
| 82 | + org = OrganizationPageFactory.create(name="Test Org", slug="custom-slug") |
| 83 | + |
| 84 | + # The slug should be the custom one |
| 85 | + assert org.slug == "custom-slug" |
| 86 | + |
| 87 | + # Change the name |
| 88 | + org.name = "Test Org Updated" |
| 89 | + org.save() |
| 90 | + org.refresh_from_db() |
| 91 | + |
| 92 | + # The slug should still be the custom one |
| 93 | + assert org.slug == "custom-slug" |
| 94 | + assert org.title == "Test Org Updated" |
0 commit comments