def test_private_external_repo_with_no_repos_access_token(self): git_url = 'https://github.com/foo/bar.git' # Create repo with self.assertRaises(GitCloneException): repo = ExternalRepo(project=self.project, git_url=git_url, is_public=False) repo.save()
def test_cannot_upload_if_project_has_external_repo(self): user = self.auth_client.user repo_name = self.project.name repo = ExternalRepo(project=self.project, git_url='https://github.com/polyaxon/empty.git') repo.save() assert self.model_class.objects.count() == 0 uploaded_file = self.get_upload_file() with patch('api.repos.views.handle_new_files') as mock_task: response = self.auth_client.put(self.url, data={'repo': uploaded_file}, content_type=MULTIPART_CONTENT) assert response.status_code == status.HTTP_403_FORBIDDEN file_path = '{}/{}/{}.tar.gz'.format(conf.get('UPLOAD_MOUNT_PATH'), user.username, repo_name) self.assertFalse(os.path.exists(file_path)) assert mock_task.call_count == 0 # No new repo was not created and still exists assert self.model_class.objects.count() == 0 repo_path = '{}/{}/{}/{}'.format(conf.get('REPOS_MOUNT_PATH'), user.username, repo_name, repo_name) self.assertFalse(os.path.exists(repo_path))
def test_checkout_commit_and_master(self): git_url = 'https://github.com/polyaxon/empty.git' # Create repo repo = ExternalRepo(project=self.project, git_url=git_url) repo.save() # Check last commit assert len(repo.last_commit) == 2 # Add new file file_path = os.path.join(repo.path, 'file1.dat') open(file_path, 'w+') assert git.get_status(repo.path) is not None git.commit(repo.path, '*****@*****.**', 'username') # Check last commit commit1 = repo.last_commit[0] assert commit1 is not None # Add new file file_path = os.path.join(repo.path, 'file2.dat') open(file_path, 'w+') assert git.get_status(repo.path) is not None git.commit(repo.path, '*****@*****.**', 'username') # Check last commit commit2 = repo.last_commit[0] assert commit2 is not None # Commits are different assert commit1 != commit2 # Checkout to commit1 git.checkout_commit(repo_path=repo.path, commit=commit1) assert repo.last_commit[0] == commit1 # Checkout to master git.checkout_commit(repo_path=repo.path) assert repo.last_commit[0] == commit2
def test_external_repo_creation_and_deletion(self): repo_path = '{}/{}/{}/{}'.format(settings.REPOS_MOUNT_PATH, self.project.user.username, self.project.name, 'empty') self.assertFalse(os.path.exists(repo_path)) git_url = 'https://github.com/polyaxon/empty.git' # Create repo repo = ExternalRepo(project=self.project, git_url=git_url) repo.save() assert repo.path == repo_path assert repo.name == 'empty' self.assertTrue(os.path.exists(repo_path)) git_file_path = '{}/.git'.format(repo_path) self.assertTrue(os.path.exists(git_file_path)) # Test fetch works correctly git.fetch(repo.git_url, repo.path) # Test query model works assert repo == ExternalRepo.objects.get(project=self.project, git_url=git_url) # Check last commit assert repo.last_commit is None # Delete repo repo.delete() self.assertFalse(os.path.exists(repo_path))