|
14 | 14 |
|
15 | 15 | from dje.models import Dataspace |
16 | 16 | from dje.tests import create_superuser |
| 17 | +from workflow.integrations import JiraIntegration |
| 18 | +from workflow.integrations import get_class_for_platform |
| 19 | +from workflow.integrations import get_class_for_tracker |
| 20 | +from workflow.integrations import is_valid_issue_tracker_id |
17 | 21 | from workflow.integrations.github import GitHubIntegration |
18 | 22 | from workflow.integrations.gitlab import GitLabIntegration |
19 | 23 | from workflow.models import Question |
20 | 24 | from workflow.models import RequestTemplate |
21 | 25 |
|
22 | 26 |
|
| 27 | +class WorkflowIntegrationsTestCase(TestCase): |
| 28 | + def test_is_valid_issue_tracker_id(self): |
| 29 | + valid_urls = [ |
| 30 | + "https://github.com/org/repo", |
| 31 | + "https://gitlab.com/group/project", |
| 32 | + "https://aboutcode.atlassian.net/projects/PROJ", |
| 33 | + "https://aboutcode.atlassian.net/jira/software/projects/PROJ", |
| 34 | + ] |
| 35 | + for url in valid_urls: |
| 36 | + with self.subTest(url=url): |
| 37 | + self.assertTrue(is_valid_issue_tracker_id(url)) |
| 38 | + |
| 39 | + invalid_urls = [ |
| 40 | + "https://bitbucket.org/team/repo", |
| 41 | + "https://github.com/", |
| 42 | + "https://gitlab.com/", |
| 43 | + "https://atlassian.net/projects/", |
| 44 | + "https://example.com", |
| 45 | + ] |
| 46 | + for url in invalid_urls: |
| 47 | + with self.subTest(url=url): |
| 48 | + self.assertFalse(is_valid_issue_tracker_id(url)) |
| 49 | + |
| 50 | + def test_get_class_for_tracker(self): |
| 51 | + self.assertIs(get_class_for_tracker("https://github.com/org/repo"), GitHubIntegration) |
| 52 | + self.assertIs(get_class_for_tracker("https://gitlab.com/group/project"), GitLabIntegration) |
| 53 | + self.assertIs( |
| 54 | + get_class_for_tracker("https://aboutcode.atlassian.net/projects/PROJ"), JiraIntegration |
| 55 | + ) |
| 56 | + self.assertIsNone(get_class_for_tracker("https://example.com")) |
| 57 | + |
| 58 | + def test_get_class_for_platform(self): |
| 59 | + self.assertIs(get_class_for_platform("github"), GitHubIntegration) |
| 60 | + self.assertIs(get_class_for_platform("gitlab"), GitLabIntegration) |
| 61 | + self.assertIs(get_class_for_platform("jira"), JiraIntegration) |
| 62 | + self.assertIsNone(get_class_for_platform("example")) |
| 63 | + |
| 64 | + |
23 | 65 | class GitHubIntegrationTestCase(TestCase): |
24 | 66 | def setUp(self): |
25 | 67 | patcher = mock.patch("workflow.models.Request.handle_integrations", return_value=None) |
|
0 commit comments