|
36 | 36 | from sentry.types.actor import Actor |
37 | 37 | from sentry.users.models.user import User |
38 | 38 | from sentry.users.models.user_option import UserOption |
39 | | -from sentry.workflow_engine.models import Detector |
| 39 | +from sentry.workflow_engine.models import Detector, DetectorWorkflow |
40 | 40 | from sentry.workflow_engine.typings.grouptype import IssueStreamGroupType |
41 | 41 |
|
42 | 42 |
|
@@ -482,6 +482,164 @@ def test_project_detectors(self) -> None: |
482 | 482 | assert Detector.objects.filter(project=project, type=ErrorGroupType.slug).count() == 1 |
483 | 483 | assert Detector.objects.filter(project=project, type=IssueStreamGroupType.slug).count() == 1 |
484 | 484 |
|
| 485 | + def test_transfer_to_organization_with_metric_issue_detector_and_workflow(self) -> None: |
| 486 | + from_org = self.create_organization() |
| 487 | + team = self.create_team(organization=from_org) |
| 488 | + to_org = self.create_organization() |
| 489 | + project = self.create_project(teams=[team]) |
| 490 | + |
| 491 | + detector = self.create_detector(project=project) |
| 492 | + data_source = self.create_data_source(organization=from_org) |
| 493 | + data_source.detectors.add(detector) |
| 494 | + workflow = self.create_workflow(organization=from_org) |
| 495 | + self.create_detector_workflow(detector=detector, workflow=workflow) |
| 496 | + |
| 497 | + project.transfer_to(organization=to_org) |
| 498 | + |
| 499 | + project.refresh_from_db() |
| 500 | + detector.refresh_from_db() |
| 501 | + data_source.refresh_from_db() |
| 502 | + workflow.refresh_from_db() |
| 503 | + |
| 504 | + assert project.organization_id == to_org.id |
| 505 | + assert detector.project_id == project.id |
| 506 | + assert data_source.organization_id == to_org.id |
| 507 | + assert workflow.organization_id == to_org.id |
| 508 | + assert DetectorWorkflow.objects.filter(detector=detector, workflow=workflow).exists() |
| 509 | + |
| 510 | + def test_transfer_to_organization_with_workflow_data_condition_groups(self) -> None: |
| 511 | + from_org = self.create_organization() |
| 512 | + team = self.create_team(organization=from_org) |
| 513 | + to_org = self.create_organization() |
| 514 | + project = self.create_project(teams=[team]) |
| 515 | + |
| 516 | + detector = self.create_detector(project=project) |
| 517 | + workflow = self.create_workflow(organization=from_org) |
| 518 | + self.create_detector_workflow(detector=detector, workflow=workflow) |
| 519 | + condition_group = self.create_data_condition_group(organization=from_org) |
| 520 | + self.create_workflow_data_condition_group( |
| 521 | + workflow=workflow, condition_group=condition_group |
| 522 | + ) |
| 523 | + |
| 524 | + project.transfer_to(organization=to_org) |
| 525 | + |
| 526 | + project.refresh_from_db() |
| 527 | + detector.refresh_from_db() |
| 528 | + workflow.refresh_from_db() |
| 529 | + condition_group.refresh_from_db() |
| 530 | + |
| 531 | + assert project.organization_id == to_org.id |
| 532 | + assert detector.project_id == project.id |
| 533 | + assert workflow.organization_id == to_org.id |
| 534 | + assert condition_group.organization_id == to_org.id |
| 535 | + wdcg = condition_group.workflowdataconditiongroup_set.first() |
| 536 | + assert wdcg is not None |
| 537 | + assert wdcg.workflow_id == workflow.id |
| 538 | + |
| 539 | + def test_transfer_to_organization_does_not_transfer_shared_workflows(self) -> None: |
| 540 | + from_org = self.create_organization() |
| 541 | + team = self.create_team(organization=from_org) |
| 542 | + to_org = self.create_organization() |
| 543 | + |
| 544 | + project_a = self.create_project(teams=[team], name="Project A") |
| 545 | + project_b = self.create_project(teams=[team], organization=from_org, name="Project B") |
| 546 | + |
| 547 | + detector_a = self.create_detector(project=project_a) |
| 548 | + detector_b = self.create_detector(project=project_b) |
| 549 | + |
| 550 | + shared_workflow = self.create_workflow(organization=from_org, name="Shared Workflow") |
| 551 | + self.create_detector_workflow(detector=detector_a, workflow=shared_workflow) |
| 552 | + self.create_detector_workflow(detector=detector_b, workflow=shared_workflow) |
| 553 | + |
| 554 | + exclusive_workflow = self.create_workflow(organization=from_org, name="Exclusive Workflow") |
| 555 | + self.create_detector_workflow(detector=detector_a, workflow=exclusive_workflow) |
| 556 | + |
| 557 | + shared_dcg = self.create_data_condition_group(organization=from_org) |
| 558 | + self.create_workflow_data_condition_group( |
| 559 | + workflow=shared_workflow, condition_group=shared_dcg |
| 560 | + ) |
| 561 | + |
| 562 | + exclusive_dcg = self.create_data_condition_group(organization=from_org) |
| 563 | + self.create_workflow_data_condition_group( |
| 564 | + workflow=exclusive_workflow, condition_group=exclusive_dcg |
| 565 | + ) |
| 566 | + |
| 567 | + project_a.transfer_to(organization=to_org) |
| 568 | + |
| 569 | + project_a.refresh_from_db() |
| 570 | + project_b.refresh_from_db() |
| 571 | + detector_a.refresh_from_db() |
| 572 | + detector_b.refresh_from_db() |
| 573 | + shared_workflow.refresh_from_db() |
| 574 | + exclusive_workflow.refresh_from_db() |
| 575 | + shared_dcg.refresh_from_db() |
| 576 | + exclusive_dcg.refresh_from_db() |
| 577 | + |
| 578 | + assert project_a.organization_id == to_org.id |
| 579 | + assert project_b.organization_id == from_org.id |
| 580 | + assert detector_a.project_id == project_a.id |
| 581 | + assert detector_b.project_id == project_b.id |
| 582 | + assert shared_workflow.organization_id == from_org.id |
| 583 | + assert exclusive_workflow.organization_id == to_org.id |
| 584 | + assert shared_dcg.organization_id == from_org.id |
| 585 | + assert exclusive_dcg.organization_id == to_org.id |
| 586 | + assert DetectorWorkflow.objects.filter( |
| 587 | + detector=detector_a, workflow=shared_workflow |
| 588 | + ).exists() |
| 589 | + assert DetectorWorkflow.objects.filter( |
| 590 | + detector=detector_b, workflow=shared_workflow |
| 591 | + ).exists() |
| 592 | + assert DetectorWorkflow.objects.filter( |
| 593 | + detector=detector_a, workflow=exclusive_workflow |
| 594 | + ).exists() |
| 595 | + |
| 596 | + def test_transfer_to_organization_with_detector_workflow_condition_group(self) -> None: |
| 597 | + from_org = self.create_organization() |
| 598 | + team = self.create_team(organization=from_org) |
| 599 | + to_org = self.create_organization() |
| 600 | + project = self.create_project(teams=[team]) |
| 601 | + |
| 602 | + detector = self.create_detector(project=project) |
| 603 | + workflow_condition_group = self.create_data_condition_group(organization=from_org) |
| 604 | + detector.workflow_condition_group = workflow_condition_group |
| 605 | + detector.save() |
| 606 | + |
| 607 | + project.transfer_to(organization=to_org) |
| 608 | + |
| 609 | + project.refresh_from_db() |
| 610 | + detector.refresh_from_db() |
| 611 | + workflow_condition_group.refresh_from_db() |
| 612 | + |
| 613 | + assert project.organization_id == to_org.id |
| 614 | + assert detector.project_id == project.id |
| 615 | + assert workflow_condition_group.organization_id == to_org.id |
| 616 | + assert detector.workflow_condition_group_id == workflow_condition_group.id |
| 617 | + |
| 618 | + def test_transfer_to_organization_with_workflow_when_condition_groups(self) -> None: |
| 619 | + from_org = self.create_organization() |
| 620 | + to_org = self.create_organization() |
| 621 | + team = self.create_team(organization=from_org) |
| 622 | + project = self.create_project(teams=[team]) |
| 623 | + |
| 624 | + detector = self.create_detector(project=project) |
| 625 | + when_condition_group = self.create_data_condition_group(organization=from_org) |
| 626 | + workflow = self.create_workflow( |
| 627 | + organization=from_org, when_condition_group=when_condition_group |
| 628 | + ) |
| 629 | + self.create_detector_workflow(detector=detector, workflow=workflow) |
| 630 | + |
| 631 | + project.transfer_to(organization=to_org) |
| 632 | + |
| 633 | + project.refresh_from_db() |
| 634 | + detector.refresh_from_db() |
| 635 | + workflow.refresh_from_db() |
| 636 | + when_condition_group.refresh_from_db() |
| 637 | + |
| 638 | + assert project.organization_id == to_org.id |
| 639 | + assert detector.project_id == project.id |
| 640 | + assert workflow.organization_id == to_org.id |
| 641 | + assert when_condition_group.organization_id == to_org.id |
| 642 | + |
485 | 643 |
|
486 | 644 | class ProjectOptionsTests(TestCase): |
487 | 645 | """ |
|
0 commit comments