Skip to content

Commit c765c55

Browse files
committed
Test case for sync_remote_repository_organizations
1 parent e869507 commit c765c55

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

readthedocs/rtd_tests/tests/test_oauth_tasks.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
from django.contrib.auth.models import User
88
from django.test import TestCase
99
from django_dynamic_fixture import get
10+
from unittest import mock
1011
from unittest.mock import patch
1112

1213
from readthedocs.builds.models import Version
1314
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
1517
from readthedocs.projects.models import Project
18+
from readthedocs.sso.models import SSOIntegration
1619

1720

1821
class SyncRemoteRepositoriesTests(TestCase):
@@ -73,3 +76,37 @@ def test_sync_repository_failsync_more_than_one(self, sync_bb, sync_gl, sync_gh)
7376
sync_bb.assert_called_once()
7477
sync_gl.assert_called_once()
7578
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

Comments
 (0)