|
| 1 | +from mhq.service.incidents.incident_filter import ConfigurationsIncidentFilterProcessor |
| 2 | +from mhq.store.models.incidents import IncidentFilter |
| 3 | +from mhq.store.models.settings.configuration_settings import SettingType |
| 4 | +from mhq.service.settings.configuration_settings import ( |
| 5 | + IncidentTypesSetting, |
| 6 | + IncidentPrsSetting, |
| 7 | +) |
| 8 | +from mhq.store.models.incidents.enums import IncidentType |
| 9 | +from mhq.store.models.settings import EntityType |
| 10 | + |
| 11 | + |
| 12 | +def test_get_incident_types_when_only_types_setting_present(): |
| 13 | + setting_types = [SettingType.INCIDENT_TYPES_SETTING] |
| 14 | + setting_type_to_settings_map = { |
| 15 | + SettingType.INCIDENT_TYPES_SETTING: IncidentTypesSetting( |
| 16 | + incident_types=[ |
| 17 | + IncidentType.INCIDENT, |
| 18 | + IncidentType.ALERT, |
| 19 | + IncidentType.REVERT_PR, |
| 20 | + ] |
| 21 | + ) |
| 22 | + } |
| 23 | + |
| 24 | + incident_filter = ConfigurationsIncidentFilterProcessor( |
| 25 | + incident_filter=IncidentFilter(), |
| 26 | + entity_type=EntityType.TEAM, |
| 27 | + entity_id="team_id", |
| 28 | + setting_types=setting_types, |
| 29 | + setting_type_to_settings_map=setting_type_to_settings_map, |
| 30 | + ).apply() |
| 31 | + |
| 32 | + expected_incident_types = [ |
| 33 | + IncidentType.INCIDENT, |
| 34 | + IncidentType.ALERT, |
| 35 | + IncidentType.REVERT_PR, |
| 36 | + ] |
| 37 | + |
| 38 | + assert incident_filter.incident_types == expected_incident_types |
| 39 | + |
| 40 | + |
| 41 | +def test_get_incident_types_when_types_setting_is_empty(): |
| 42 | + setting_types = [SettingType.INCIDENT_TYPES_SETTING] |
| 43 | + setting_type_to_settings_map = { |
| 44 | + SettingType.INCIDENT_TYPES_SETTING: IncidentTypesSetting(incident_types=[]) |
| 45 | + } |
| 46 | + |
| 47 | + incident_filter = ConfigurationsIncidentFilterProcessor( |
| 48 | + incident_filter=IncidentFilter(), |
| 49 | + entity_type=EntityType.TEAM, |
| 50 | + entity_id="dummy_id", |
| 51 | + setting_types=setting_types, |
| 52 | + setting_type_to_settings_map=setting_type_to_settings_map, |
| 53 | + ).apply() |
| 54 | + |
| 55 | + assert incident_filter.incident_types == [] |
| 56 | + |
| 57 | + |
| 58 | +def test_get_incident_types_when_only_prs_setting_present_returns_none(): |
| 59 | + setting_types = [SettingType.INCIDENT_PRS_SETTING] |
| 60 | + incident_prs_setting = IncidentPrsSetting( |
| 61 | + include_revert_prs=True, title_filters=[], head_branch_filters=[] |
| 62 | + ) |
| 63 | + setting_type_to_settings_map = { |
| 64 | + SettingType.INCIDENT_PRS_SETTING: incident_prs_setting |
| 65 | + } |
| 66 | + |
| 67 | + incident_filter = ConfigurationsIncidentFilterProcessor( |
| 68 | + incident_filter=IncidentFilter(), |
| 69 | + entity_type=EntityType.TEAM, |
| 70 | + entity_id="team_id", |
| 71 | + setting_types=setting_types, |
| 72 | + setting_type_to_settings_map=setting_type_to_settings_map, |
| 73 | + ).apply() |
| 74 | + |
| 75 | + assert incident_filter.incident_types is None |
| 76 | + |
| 77 | + |
| 78 | +def test_get_incident_types_when_both_types_and_prs_settings_present_and_includes_revert_prs(): |
| 79 | + setting_types = [ |
| 80 | + SettingType.INCIDENT_TYPES_SETTING, |
| 81 | + SettingType.INCIDENT_PRS_SETTING, |
| 82 | + ] |
| 83 | + incident_prs_setting = IncidentPrsSetting( |
| 84 | + include_revert_prs=True, title_filters=[], head_branch_filters=[] |
| 85 | + ) |
| 86 | + setting_type_to_settings_map = { |
| 87 | + SettingType.INCIDENT_TYPES_SETTING: IncidentTypesSetting( |
| 88 | + incident_types=[IncidentType.INCIDENT, IncidentType.REVERT_PR] |
| 89 | + ), |
| 90 | + SettingType.INCIDENT_PRS_SETTING: incident_prs_setting, |
| 91 | + } |
| 92 | + |
| 93 | + incident_filter = ConfigurationsIncidentFilterProcessor( |
| 94 | + incident_filter=IncidentFilter(), |
| 95 | + entity_type=EntityType.TEAM, |
| 96 | + entity_id="team_id", |
| 97 | + setting_types=setting_types, |
| 98 | + setting_type_to_settings_map=setting_type_to_settings_map, |
| 99 | + ).apply() |
| 100 | + |
| 101 | + expected_incident_types = [IncidentType.INCIDENT, IncidentType.REVERT_PR] |
| 102 | + |
| 103 | + assert incident_filter.incident_types == expected_incident_types |
| 104 | + |
| 105 | + |
| 106 | +def test_get_incident_types_when_both_settings_present_and_not_includes_revert_prs(): |
| 107 | + setting_types = [ |
| 108 | + SettingType.INCIDENT_TYPES_SETTING, |
| 109 | + SettingType.INCIDENT_PRS_SETTING, |
| 110 | + ] |
| 111 | + incident_prs_setting = IncidentPrsSetting( |
| 112 | + include_revert_prs=False, title_filters=[], head_branch_filters=[] |
| 113 | + ) |
| 114 | + setting_type_to_settings_map = { |
| 115 | + SettingType.INCIDENT_TYPES_SETTING: IncidentTypesSetting( |
| 116 | + incident_types=[IncidentType.INCIDENT, IncidentType.REVERT_PR] |
| 117 | + ), |
| 118 | + SettingType.INCIDENT_PRS_SETTING: incident_prs_setting, |
| 119 | + } |
| 120 | + |
| 121 | + incident_filter = ConfigurationsIncidentFilterProcessor( |
| 122 | + incident_filter=IncidentFilter(), |
| 123 | + entity_type=EntityType.TEAM, |
| 124 | + entity_id="team_id", |
| 125 | + setting_types=setting_types, |
| 126 | + setting_type_to_settings_map=setting_type_to_settings_map, |
| 127 | + ).apply() |
| 128 | + |
| 129 | + expected_incident_types = [IncidentType.INCIDENT] |
| 130 | + |
| 131 | + assert incident_filter.incident_types == expected_incident_types |
0 commit comments