|
7 | 7 | from django.contrib.auth.models import User
|
8 | 8 | from django.test import TestCase
|
9 | 9 | from django_dynamic_fixture import get
|
| 10 | +from unittest import mock |
10 | 11 | from unittest.mock import patch
|
11 | 12 |
|
12 | 13 | from readthedocs.builds.models import Version
|
13 | 14 | from readthedocs.oauth.services.base import SyncServiceError
|
14 |
| -from readthedocs.oauth.tasks import sync_remote_repositories |
| 15 | +from readthedocs.oauth.tasks import sync_remote_repositories, sync_remote_repositories_organizations |
| 16 | +from readthedocs.organizations.models import Organization, OrganizationOwner |
15 | 17 | from readthedocs.projects.models import Project
|
| 18 | +from readthedocs.sso.models import SSOIntegration |
16 | 19 |
|
17 | 20 |
|
18 | 21 | class SyncRemoteRepositoriesTests(TestCase):
|
@@ -73,3 +76,37 @@ def test_sync_repository_failsync_more_than_one(self, sync_bb, sync_gl, sync_gh)
|
73 | 76 | sync_bb.assert_called_once()
|
74 | 77 | sync_gl.assert_called_once()
|
75 | 78 | sync_gh.assert_called_once()
|
| 79 | + |
| 80 | + @patch('readthedocs.oauth.tasks.sync_remote_repositories') |
| 81 | + def test_sync_remote_repository_organizations_slugs(self, mock_sync_remote_repositories): |
| 82 | + organization = get(Organization) |
| 83 | + get( |
| 84 | + OrganizationOwner, |
| 85 | + owner=self.user, |
| 86 | + organization=organization, |
| 87 | + ) |
| 88 | + sync_remote_repositories_organizations(organization_slugs=[organization.slug]) |
| 89 | + mock_sync_remote_repositories.delay.assert_called_once() |
| 90 | + mock_sync_remote_repositories.delay.assert_has_calls( |
| 91 | + [mock.call(self.user.pk, countdown=0)], |
| 92 | + ) |
| 93 | + |
| 94 | + @patch('readthedocs.oauth.tasks.sync_remote_repositories') |
| 95 | + def test_sync_remote_repository_organizations_without_slugs(self, mock_sync_remote_repositories): |
| 96 | + organization = get(Organization) |
| 97 | + get( |
| 98 | + SSOIntegration, |
| 99 | + provider=SSOIntegration.PROVIDER_ALLAUTH, |
| 100 | + organization=organization, |
| 101 | + ) |
| 102 | + get( |
| 103 | + OrganizationOwner, |
| 104 | + owner=self.user, |
| 105 | + organization=organization, |
| 106 | + ) |
| 107 | + |
| 108 | + sync_remote_repositories_organizations() |
| 109 | + mock_sync_remote_repositories.delay.assert_called_once() |
| 110 | + mock_sync_remote_repositories.delay.assert_has_calls( |
| 111 | + [mock.call(self.user.pk, countdown=0)], |
| 112 | + ) |
0 commit comments