def setUp(self): self.client.login(username='******', password='******') self.user = User.objects.get(pk=1) self.project = Project.objects.get(slug='pip') self.org = RemoteOrganization.objects.create(slug='rtfd', json='') self.privacy = self.project.version_privacy_level self.service = GitHubService(user=self.user, account=None)
def setUp(self): self.client.login(username='******', password='******') self.user = User.objects.get(pk=1) self.project = Project.objects.get(slug='pip') self.org = RemoteOrganization.objects.create(slug='rtfd', json='') self.privacy = settings.DEFAULT_PRIVACY_LEVEL self.service = GitHubService(user=self.user, account=None) self.external_version = get(Version, project=self.project, type=EXTERNAL) self.external_build = get( Build, project=self.project, version=self.external_version ) self.integration = get( GitHubWebhook, project=self.project, provider_data={ 'url': 'https://github.com/' } ) self.provider_data = [ { "config": { "url": "https://example.com/webhook" }, "url": "https://api.github.com/repos/test/Hello-World/hooks/12345678", } ]
def test_sync_repositories_only_creates_one_remote_repo_per_vcs_repo(self, mock_request): mock_request.get('https://api.github.com/user/repos', json=self.payload_user_repos) self.assertEqual(RemoteRepository.objects.count(), 0) remote_repositories = self.service.sync_repositories() self.assertEqual(RemoteRepository.objects.count(), 1) self.assertEqual(len(remote_repositories), 1) self.assertEqual(RemoteRepositoryRelation.objects.count(), 1) user_2 = fixture.get(User) user_2_socialaccount = fixture.get( SocialAccount, user=user_2, provider=GitHubOAuth2Adapter.provider_id, ) fixture.get( SocialToken, account=user_2_socialaccount, ) service_2 = GitHubService(user=user_2, account=user_2_socialaccount) remote_repositories = service_2.sync_repositories() self.assertEqual(RemoteRepository.objects.count(), 1) self.assertEqual(len(remote_repositories), 1) self.assertEqual(RemoteRepositoryRelation.objects.count(), 2)
def test_multiple_users_same_repo(self): repo_json = { 'name': '', 'full_name': 'testrepo/multiple', 'description': '', 'git_url': '', 'private': False, 'ssh_url': '', 'html_url': '', 'clone_url': '', } github_project = self.service.create_repository( repo_json, organization=self.org, privacy=self.privacy, ) user2 = User.objects.get(pk=2) service = GitHubService(user=user2, account=None) github_project_2 = service.create_repository( repo_json, organization=self.org, privacy=self.privacy, ) self.assertIsInstance(github_project, RemoteRepository) self.assertIsInstance(github_project_2, RemoteRepository) self.assertNotEqual(github_project_2, github_project) github_project_3 = self.service.create_repository( repo_json, organization=self.org, privacy=self.privacy, ) github_project_4 = service.create_repository( repo_json, organization=self.org, privacy=self.privacy, ) self.assertIsInstance(github_project_3, RemoteRepository) self.assertIsInstance(github_project_4, RemoteRepository) self.assertEqual(github_project, github_project_3) self.assertEqual(github_project_2, github_project_4) github_project_5 = self.service.create_repository( repo_json, organization=self.org, privacy=self.privacy, ) github_project_6 = service.create_repository( repo_json, organization=self.org, privacy=self.privacy, ) self.assertEqual(github_project, github_project_5) self.assertEqual(github_project_2, github_project_6)
def test_multiple_users_same_repo(self): repo_json = { "name": "", "full_name": "testrepo/multiple", "description": "", "git_url": "", "private": False, "ssh_url": "", "html_url": "", "clone_url": "", } github_project = self.service.create_repository(repo_json, organization=self.org, privacy=self.privacy) user2 = User.objects.get(pk=2) service = GitHubService(user=user2, account=None) github_project_2 = service.create_repository(repo_json, organization=self.org, privacy=self.privacy) self.assertIsInstance(github_project, RemoteRepository) self.assertIsInstance(github_project_2, RemoteRepository) self.assertNotEqual(github_project_2, github_project) github_project_3 = self.service.create_repository( repo_json, organization=self.org, privacy=self.privacy) github_project_4 = service.create_repository(repo_json, organization=self.org, privacy=self.privacy) self.assertIsInstance(github_project_3, RemoteRepository) self.assertIsInstance(github_project_4, RemoteRepository) self.assertEqual(github_project, github_project_3) self.assertEqual(github_project_2, github_project_4) github_project_5 = self.service.create_repository( repo_json, organization=self.org, privacy=self.privacy) github_project_6 = service.create_repository(repo_json, organization=self.org, privacy=self.privacy) self.assertEqual(github_project, github_project_5) self.assertEqual(github_project_2, github_project_6)