|
18 | 18 | _get_cluster, |
19 | 19 | add_base_url_to_rank, |
20 | 20 | get_organization_bucket, |
| 21 | + get_project_base_url_rank_key, |
21 | 22 | ) |
22 | 23 | from sentry.uptime.detectors.tasks import ( |
23 | 24 | LAST_PROCESSED_KEY, |
@@ -144,17 +145,38 @@ def test(self): |
144 | 145 | ] |
145 | 146 | ) |
146 | 147 |
|
147 | | - def test_should_not_detect(self): |
| 148 | + def test_should_not_detect_project(self): |
148 | 149 | with mock.patch( |
149 | | - # TODO: Replace this mock with real tests when we implement this function properly |
150 | | - "sentry.uptime.detectors.tasks.should_detect_for_project", |
151 | | - return_value=False, |
152 | | - ), mock.patch( |
153 | 150 | "sentry.uptime.detectors.tasks.get_candidate_urls_for_project" |
154 | 151 | ) as mock_get_candidate_urls_for_project: |
| 152 | + self.project.update_option("sentry:uptime_autodetection", False) |
155 | 153 | assert not process_project_url_ranking(self.project, 5) |
156 | 154 | mock_get_candidate_urls_for_project.assert_not_called() |
157 | 155 |
|
| 156 | + def test_should_not_detect_organization(self): |
| 157 | + url_1 = "https://sentry.io" |
| 158 | + url_2 = "https://sentry.sentry.io" |
| 159 | + project_2 = self.create_project() |
| 160 | + add_base_url_to_rank(self.project, url_2) |
| 161 | + add_base_url_to_rank(self.project, url_1) |
| 162 | + add_base_url_to_rank(self.project, url_1) |
| 163 | + add_base_url_to_rank(project_2, url_1) |
| 164 | + |
| 165 | + keys = [ |
| 166 | + get_project_base_url_rank_key(self.project), |
| 167 | + get_project_base_url_rank_key(project_2), |
| 168 | + ] |
| 169 | + redis = _get_cluster() |
| 170 | + assert all(redis.exists(key) for key in keys) |
| 171 | + |
| 172 | + with mock.patch( |
| 173 | + "sentry.uptime.detectors.tasks.get_candidate_urls_for_project" |
| 174 | + ) as mock_get_candidate_urls_for_project: |
| 175 | + self.organization.update_option("sentry:uptime_autodetection", False) |
| 176 | + assert not process_organization_url_ranking(self.organization.id) |
| 177 | + mock_get_candidate_urls_for_project.assert_not_called() |
| 178 | + assert all(not redis.exists(key) for key in keys) |
| 179 | + |
158 | 180 |
|
159 | 181 | @freeze_time() |
160 | 182 | class ProcessProjectUrlRankingTest(TestCase): |
|
0 commit comments