|
13 | 13 | RequestPermissionProject, |
14 | 14 | OrganizationAuthorization, |
15 | 15 | ProjectAuthorization, |
| 16 | + OrganizationRole, |
| 17 | + ProjectRole, |
16 | 18 | ) |
17 | 19 |
|
18 | 20 | from connect.usecases.authorizations.create import CreateAuthorizationUseCase |
@@ -423,3 +425,107 @@ def test_create_org(self): |
423 | 425 |
|
424 | 426 | self.request_permission_project(data) |
425 | 427 | self.assertEquals(ProjectAuthorization.objects.count(), 2) |
| 428 | + |
| 429 | + |
| 430 | +class MarketingRoleTestCase(TestCase, TestCaseSetUp): |
| 431 | + """Tests for the MARKETING role (role=6) at organization and project levels.""" |
| 432 | + |
| 433 | + def setUp(self): |
| 434 | + self.superuser = User.objects.create( |
| 435 | + email="super@test.user", username="superuser" |
| 436 | + ) |
| 437 | + self.user = User.objects.create( |
| 438 | + email="marketing@test.user", username="MarketingTestUser", has_2fa=True |
| 439 | + ) |
| 440 | + self.org = Organization.objects.create( |
| 441 | + name="Marketing test org", |
| 442 | + description="Marketing test org", |
| 443 | + inteligence_organization=1, |
| 444 | + organization_billing__cycle=BillingPlan.BILLING_CYCLE_MONTHLY, |
| 445 | + organization_billing__plan=BillingPlan.PLAN_TRIAL, |
| 446 | + ) |
| 447 | + self.project = self.org.project.create(name="Marketing test project") |
| 448 | + |
| 449 | + def test_marketing_role_value(self): |
| 450 | + """Test that MARKETING role has correct enum value.""" |
| 451 | + self.assertEqual(OrganizationRole.MARKETING.value, 6) |
| 452 | + self.assertEqual(ProjectRole.MARKETING.value, 6) |
| 453 | + |
| 454 | + def test_marketing_org_authorization_properties(self): |
| 455 | + """Test that MARKETING role has correct permission properties at org level.""" |
| 456 | + role = OrganizationRole.MARKETING.value |
| 457 | + self.create_auth(self.user, self.org, role) |
| 458 | + authorization = self.org.authorizations.get(user=self.user) |
| 459 | + |
| 460 | + self.assertEqual(authorization.role, 6) |
| 461 | + self.assertTrue(authorization.can_read) |
| 462 | + self.assertTrue(authorization.can_contribute) |
| 463 | + self.assertTrue(authorization.can_write) |
| 464 | + self.assertFalse(authorization.is_admin) |
| 465 | + |
| 466 | + def test_marketing_role_maps_to_project(self): |
| 467 | + """Test that MARKETING org role propagates correctly to project.""" |
| 468 | + role = OrganizationRole.MARKETING.value |
| 469 | + self.create_auth(self.user, self.org, role, publish_message=False) |
| 470 | + |
| 471 | + project_auth = self.project.get_user_authorization(self.user) |
| 472 | + self.assertEqual(project_auth.role, ProjectRole.MARKETING.value) |
| 473 | + |
| 474 | + def test_marketing_project_authorization_properties(self): |
| 475 | + """Test that MARKETING role has correct permission properties at project level.""" |
| 476 | + role = OrganizationRole.MARKETING.value |
| 477 | + self.create_auth(self.user, self.org, role, publish_message=False) |
| 478 | + |
| 479 | + project_auth = self.project.get_user_authorization(self.user) |
| 480 | + |
| 481 | + self.assertEqual(project_auth.role, 6) |
| 482 | + self.assertTrue(project_auth.can_read) |
| 483 | + self.assertTrue(project_auth.can_contribute) |
| 484 | + self.assertTrue(project_auth.can_write) |
| 485 | + self.assertTrue(project_auth.is_moderator) |
| 486 | + self.assertFalse(project_auth.is_admin) |
| 487 | + |
| 488 | + def test_update_to_marketing_role(self): |
| 489 | + """Test updating an existing authorization to MARKETING role.""" |
| 490 | + # First create with CONTRIBUTOR role |
| 491 | + initial_role = OrganizationRole.CONTRIBUTOR.value |
| 492 | + self.create_auth(self.user, self.org, initial_role) |
| 493 | + |
| 494 | + # Update to MARKETING role |
| 495 | + update_role = OrganizationRole.MARKETING.value |
| 496 | + auth_dto = UpdateAuthorizationDTO( |
| 497 | + user_email=self.user.email, |
| 498 | + org_uuid=str(self.org.uuid), |
| 499 | + role=update_role, |
| 500 | + request_user=self.superuser.email, |
| 501 | + ) |
| 502 | + |
| 503 | + usecase = UpdateAuthorizationUseCase(message_publisher=MockRabbitMQPublisher()) |
| 504 | + authorization = usecase.update_authorization(auth_dto) |
| 505 | + |
| 506 | + project_auth = self.project.get_user_authorization(self.user) |
| 507 | + |
| 508 | + self.assertEqual(authorization.role, update_role) |
| 509 | + self.assertEqual(project_auth.role, ProjectRole.MARKETING.value) |
| 510 | + |
| 511 | + def test_create_marketing_authorization_for_single_project(self): |
| 512 | + """Test creating MARKETING authorization for a single project.""" |
| 513 | + # First create superuser auth to have permission |
| 514 | + self.org.authorizations.create(user=self.superuser, role=OrganizationRole.ADMIN.value) |
| 515 | + ProjectAuthorization.objects.create( |
| 516 | + user=self.superuser, |
| 517 | + project=self.project, |
| 518 | + role=ProjectRole.MODERATOR.value, |
| 519 | + ) |
| 520 | + |
| 521 | + role = ProjectRole.MARKETING.value |
| 522 | + auth_dto = CreateProjectAuthorizationDTO( |
| 523 | + user_email=self.user.email, |
| 524 | + project_uuid=str(self.project.uuid), |
| 525 | + role=role, |
| 526 | + created_by_email=self.superuser.email, |
| 527 | + ) |
| 528 | + usecase = CreateAuthorizationUseCase(MockRabbitMQPublisher()) |
| 529 | + project_auth = usecase.create_authorization_for_a_single_project(auth_dto) |
| 530 | + |
| 531 | + self.assertEqual(project_auth.role, role) |
0 commit comments