-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to import public repositories on corporate site #3537
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f5e8987
Allow to import public repositories on corporate site
humitos 4151207
Test for importing public repos under private default level
humitos 7f4467c
Refactor the use of DEFAULT_PRIVACY_LEVEL to be able to override
humitos b258d35
Added the same test for GitLab and GitHub
humitos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from django.conf import settings | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
from django.test.utils import override_settings | ||
|
||
from readthedocs.oauth.models import RemoteOrganization, RemoteRepository | ||
from readthedocs.oauth.services import ( | ||
|
@@ -131,6 +132,24 @@ def test_multiple_users_same_repo(self): | |
self.assertEqual(github_project, github_project_5) | ||
self.assertEqual(github_project_2, github_project_6) | ||
|
||
@override_settings(DEFAULT_PRIVACY_LEVEL='private') | ||
def test_make_private_project(self): | ||
""" | ||
Test ability to import ``public`` repositories under ``private`` level. | ||
""" | ||
repo_json = { | ||
'name': 'testrepo', | ||
'full_name': 'testuser/testrepo', | ||
'description': 'Test Repo', | ||
'git_url': 'git://github.com/testuser/testrepo.git', | ||
'private': False, | ||
'ssh_url': 'ssh://[email protected]:testuser/testrepo.git', | ||
'html_url': 'https://github.com/testuser/testrepo', | ||
'clone_url': 'https://github.com/testuser/testrepo.git', | ||
} | ||
repo = self.service.create_repository(repo_json, organization=self.org) | ||
self.assertIsNotNone(repo) | ||
|
||
|
||
class BitbucketOAuthTests(TestCase): | ||
|
||
|
@@ -270,6 +289,16 @@ def test_make_project_fail(self): | |
data, organization=self.org, privacy=self.privacy) | ||
self.assertIsNone(repo) | ||
|
||
@override_settings(DEFAULT_PRIVACY_LEVEL='private') | ||
def test_make_private_project(self): | ||
""" | ||
Test ability to import ``public`` repositories under ``private`` level. | ||
""" | ||
data = self.repo_response_data.copy() | ||
data['is_private'] = False | ||
repo = self.service.create_repository(data, organization=self.org) | ||
self.assertIsNotNone(repo) | ||
|
||
def test_make_organization(self): | ||
org = self.service.create_organization(self.team_response_data) | ||
self.assertIsInstance(org, RemoteOrganization) | ||
|
@@ -444,3 +473,15 @@ def test_make_organization(self): | |
'https://secure.gravatar.com/avatar/test', | ||
) | ||
self.assertEqual(org.url, 'https://gitlab.com/testorga') | ||
|
||
@override_settings(DEFAULT_PRIVACY_LEVEL='private') | ||
def test_make_private_project(self): | ||
""" | ||
Test ability to import ``public`` repositories under ``private`` level. | ||
""" | ||
data = self.repo_response_data.copy() | ||
data['visibility'] = 'public' | ||
with mock.patch('readthedocs.oauth.services.gitlab.GitLabService.is_owned_by') as m: # yapf: disable | ||
m.return_value = True | ||
repo = self.service.create_repository(data, organization=self.org) | ||
self.assertIsNotNone(repo) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most important part of the test.
The problem we have here is how are the method defined and how they use this setting:
public
(the default) and theBitbucketService.create_repository
is created withpublic
as default forprivacy
at https://github.com/rtfd/readthedocs.org/blob/415120759b9abbf67092a1e4781341b0d58f205a/readthedocs/oauth/services/bitbucket.py#L90-L92@override_settings
patch has no effectThe test passes because it's a
public
repo under apublic
default privacy level.What it should be the best way to handle this? Should we make
privacy
asNone
by default and access thesettings
object inside thecreate_repository
method?cc @agjohnson
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this probably makes the most sense. 👍