diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-08-23 02:09:09 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-08-23 02:15:16 +0200 |
commit | 48e147c2894ce8dca9d2aa21a1369d5062580f03 (patch) | |
tree | 81bcc1be75fc1fad68e1d9e393749950692a7f6b | |
parent | requirements.txt: bump dependencies (diff) | |
download | cgitize-48e147c2894ce8dca9d2aa21a1369d5062580f03.tar.gz cgitize-48e147c2894ce8dca9d2aa21a1369d5062580f03.zip |
use separate users for testing
-rw-r--r-- | .github/workflows/ci.yml | 19 | ||||
-rw-r--r-- | examples/cgitize.toml | 8 | ||||
-rwxr-xr-x | test/integration/example/test.sh | 41 | ||||
-rw-r--r-- | test/unit/test_bitbucket.py | 44 | ||||
-rw-r--r-- | test/unit/test_github.py | 50 | ||||
-rw-r--r-- | test/unit/test_gitlab.py | 46 |
6 files changed, 154 insertions, 54 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d58c15..baa7633 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,11 @@ jobs: python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] name: 'Test / ${{ matrix.python-version }}' env: - # API request rate limit is easily exceeded otherwise: CGITIZE_GITHUB_TOKEN: '${{ secrets.CGITIZE_GITHUB_TOKEN }}' + CGITIZE_BITBUCKET_USERNAME: cgitize-test + CGITIZE_BITBUCKET_TOKEN: '${{ secrets.CGITIZE_BITBUCKET_TOKEN }}' + CGITIZE_GITLAB_USERNAME: cgitize-test + CGITIZE_GITLAB_TOKEN: '${{ secrets.CGITIZE_GITLAB_TOKEN}}' steps: - name: Checkout uses: actions/checkout@v3 @@ -48,15 +51,11 @@ jobs: runs-on: ubuntu-latest name: 'Test / example config' env: - # API request rate limit is easily exceeded otherwise: CGITIZE_GITHUB_TOKEN: '${{ secrets.CGITIZE_GITHUB_TOKEN }}' - # Consider creating a separate user (without my private repositories) - # for testing Bitbucket). - #CGITIZE_BITBUCKET_USERNAME: egor-tensin - #CGITIZE_BITBUCKET_TOKEN: '${{ secrets.CGITIZE_BITBUCKET_TOKEN }}' - # Same goes for GitLab. - #CGITIZE_GITLAB_USERNAME: egor-tensin - #CGITIZE_GITLAB_TOKEN: '${{ secrets.CGITIZE_GITLAB_TOKEN}}' + CGITIZE_BITBUCKET_USERNAME: cgitize-test + CGITIZE_BITBUCKET_TOKEN: '${{ secrets.CGITIZE_BITBUCKET_TOKEN }}' + CGITIZE_GITLAB_USERNAME: cgitize-test + CGITIZE_GITLAB_TOKEN: '${{ secrets.CGITIZE_GITLAB_TOKEN}}' steps: - name: Checkout uses: actions/checkout@v3 @@ -67,7 +66,7 @@ jobs: - name: Install dependencies run: pip install -q -r requirements.txt - name: Set up ssh-agent - uses: webfactory/ssh-agent@v0.7.0 + uses: webfactory/ssh-agent@v0.8.0 with: ssh-private-key: '${{ secrets.SSH_KEY }}' - name: Integration test (example config) diff --git a/examples/cgitize.toml b/examples/cgitize.toml index cbaad30..5378c05 100644 --- a/examples/cgitize.toml +++ b/examples/cgitize.toml @@ -24,12 +24,12 @@ owner = "Your Name" #token = "XXX" [github.users.me] -name = "egor-tensin" +name = "cgitize-test" # To avoid directory name clashes with other repositories, you can specify a # subdirectory to put that user's repositories to. dir = "github-dir" # Repositories to skip: -skip = ["chruby", "SafeInt"] +skip = ["repo1", "repo2"] [github.organizations.browserify] # For GitHub, you can also specify organizations. The settings are similar to @@ -61,7 +61,7 @@ dir = "python" #username = "your-username" [bitbucket.users.me] -name = "egor-tensin" +name = "cgitize-test-workspace" dir = "bitbucket-dir" #skip = ["repo1", "repo2"] @@ -84,7 +84,7 @@ id = "berkeleylab/upc-runtime" #username = "your-username" [gitlab.users.me] -name = "egor-tensin" +name = "cgitize-test" dir = "gitlab-dir" #skip = ["repo1", "repo2"] diff --git a/test/integration/example/test.sh b/test/integration/example/test.sh index dfb788f..11afcc1 100755 --- a/test/integration/example/test.sh +++ b/test/integration/example/test.sh @@ -128,22 +128,30 @@ test_ssh() { setup_ssh cgitize + verify_repos \ lens \ chromiumembedded/cef \ graphviz \ wireguard/wintun \ browserify-dir/browserify \ - github-dir/cgitize-test-repository \ - bitbucket-dir/cgitize-test-repository \ - gitlab-dir/cgitize-test-repository + github-dir/public \ + bitbucket-dir/public \ + bitbucket-dir/private \ + gitlab-dir/public \ + gitlab-dir/private + verify_origin lens 'git@github.com:ekmett/lens.git' verify_origin chromiumembedded/cef 'git@bitbucket.org:chromiumembedded/cef.git' verify_origin graphviz 'git@gitlab.com:graphviz/graphviz.git' verify_origin browserify-dir/browserify 'git@github.com:browserify/browserify.git' - verify_origin github-dir/cgitize-test-repository 'git@github.com:egor-tensin/cgitize-test-repository.git' - verify_origin bitbucket-dir/cgitize-test-repository 'git@bitbucket.org:egor-tensin/cgitize-test-repository.git' - verify_origin gitlab-dir/cgitize-test-repository 'git@gitlab.com:egor-tensin/cgitize-test-repository.git' + + verify_origin github-dir/public 'git@github.com:cgitize-test/public.git' + verify_origin bitbucket-dir/public 'git@bitbucket.org:cgitize-test-workspace/public.git' + verify_origin bitbucket-dir/private 'git@bitbucket.org:cgitize-test-workspace/private.git' + verify_origin gitlab-dir/public 'git@gitlab.com:cgitize-test/public.git' + verify_origin gitlab-dir/private 'git@gitlab.com:cgitize-test/private.git' + cleanup success } @@ -156,21 +164,30 @@ test_https() { setup_https cgitize + verify_repos \ lens \ chromiumembedded/cef \ graphviz \ wireguard/wintun \ - github-dir/cgitize-test-repository \ - bitbucket-dir/cgitize-test-repository \ - gitlab-dir/cgitize-test-repository + browserify-dir/browserify \ + github-dir/public \ + bitbucket-dir/public \ + bitbucket-dir/private \ + gitlab-dir/public \ + gitlab-dir/private + verify_origin lens 'https://github.com/ekmett/lens.git' verify_origin chromiumembedded/cef 'https://bitbucket.org/chromiumembedded/cef.git' verify_origin graphviz 'https://gitlab.com/graphviz/graphviz.git' verify_origin browserify-dir/browserify 'https://github.com/browserify/browserify.git' - verify_origin github-dir/cgitize-test-repository 'https://github.com/egor-tensin/cgitize-test-repository.git' - verify_origin bitbucket-dir/cgitize-test-repository 'https://bitbucket.org/egor-tensin/cgitize-test-repository.git' - verify_origin gitlab-dir/cgitize-test-repository 'https://gitlab.com/egor-tensin/cgitize-test-repository.git' + + verify_origin github-dir/public 'https://github.com/cgitize-test/public.git' + verify_origin bitbucket-dir/public 'https://bitbucket.org/cgitize-test-workspace/public.git' + verify_origin bitbucket-dir/private 'https://bitbucket.org/cgitize-test-workspace/private.git' + verify_origin gitlab-dir/public 'https://gitlab.com/cgitize-test/public.git' + verify_origin gitlab-dir/private 'https://gitlab.com/cgitize-test/private.git' + cleanup success } diff --git a/test/unit/test_bitbucket.py b/test/unit/test_bitbucket.py index 2e49168..7611bd4 100644 --- a/test/unit/test_bitbucket.py +++ b/test/unit/test_bitbucket.py @@ -14,27 +14,51 @@ class BitbucketTests(unittest.TestCase): def setUp(self): self.bitbucket = Cloud( username=os.environ.get('CGITIZE_BITBUCKET_USERNAME'), - password=os.environ.get('CGITIZE_BITBUCKET_PASSWORD'), + password=os.environ.get('CGITIZE_BITBUCKET_TOKEN'), cloud=True) def test_nonexistent_repo(self): with self.assertRaises(HTTPError): self.bitbucket.repositories.get('doesnot', 'exist') - def test_existing_repo(self): - r = self.bitbucket.repositories.get('egor-tensin', 'cgitize-test-repository') - self.assertEqual(r.name, 'cgitize-test-repository') - self.assertEqual(r.description, 'Test cgitize repository') + def test_public_repo(self): + r = self.bitbucket.repositories.get('cgitize-test-workspace', 'public') + self.assertEqual(r.name, 'public') + self.assertEqual(r.description, 'Public test cgitize repository') - self.assertEqual(r.data['owner']['display_name'], 'Egor Tensin') - self.assertEqual(r.data['owner']['nickname'], 'egor-tensin') + self.assertEqual(r.data['workspace']['name'], 'Test cgitize workspace') + self.assertEqual(r.data['workspace']['slug'], 'cgitize-test-workspace') - self.assertEqual(r.get_link('html'), 'https://bitbucket.org/egor-tensin/cgitize-test-repository') + self.assertEqual(r.get_link('html'), 'https://bitbucket.org/cgitize-test-workspace/public') clone_urls = [link for link in r.data['links']['clone'] if link['name'] == 'https'] self.assertEqual(len(clone_urls), 1) - self.assertEqual(clone_urls[0]['href'], 'https://bitbucket.org/egor-tensin/cgitize-test-repository.git') + self.assertEqual(clone_urls[0]['href'], 'https://cgitize-test@bitbucket.org/cgitize-test-workspace/public.git') ssh_urls = [link for link in r.data['links']['clone'] if link['name'] == 'ssh'] self.assertEqual(len(ssh_urls), 1) - self.assertEqual(ssh_urls[0]['href'], 'git@bitbucket.org:egor-tensin/cgitize-test-repository.git') + self.assertEqual(ssh_urls[0]['href'], 'git@bitbucket.org:cgitize-test-workspace/public.git') + + def test_private_repo(self): + r = self.bitbucket.repositories.get('cgitize-test-workspace', 'private') + self.assertEqual(r.name, 'private') + self.assertEqual(r.description, 'Private test cgitize repository') + + self.assertEqual(r.data['workspace']['name'], 'Test cgitize workspace') + self.assertEqual(r.data['workspace']['slug'], 'cgitize-test-workspace') + + self.assertEqual(r.get_link('html'), 'https://bitbucket.org/cgitize-test-workspace/private') + + def test_user(self): + w = self.bitbucket.workspaces.get('cgitize-test-workspace') + self.assertEqual(len([r for r in w.repositories.each() if r.name == 'public']), 1) + self.assertEqual(len([r for r in w.repositories.each() if r.name == 'private']), 1) + + +class BitbucketTestPrivateRepo(unittest.TestCase): + def setUp(self): + self.bitbucket = Cloud(cloud=True) + + def test_private_repo(self): + with self.assertRaises(HTTPError): + self.bitbucket.repositories.get('cgitize-test-workspace', 'private') diff --git a/test/unit/test_github.py b/test/unit/test_github.py index 1095c98..7546ed6 100644 --- a/test/unit/test_github.py +++ b/test/unit/test_github.py @@ -17,12 +17,44 @@ class GitHubTests(unittest.TestCase): with self.assertRaises(GithubException): self.github.get_repo('doesnot/exist') - def test_existing_repo(self): - r = self.github.get_repo('egor-tensin/cgitize-test-repository') - self.assertEqual(r.name, 'cgitize-test-repository') - self.assertEqual(r.description, 'Test cgitize repository') - self.assertEqual(r.owner.name, 'Egor Tensin') - self.assertEqual(r.owner.login, 'egor-tensin') - self.assertEqual(r.html_url, 'https://github.com/egor-tensin/cgitize-test-repository') - self.assertEqual(r.clone_url, 'https://github.com/egor-tensin/cgitize-test-repository.git') - self.assertEqual(r.ssh_url, 'git@github.com:egor-tensin/cgitize-test-repository.git') + def test_public_repo(self): + r = self.github.get_repo('cgitize-test/public') + self.assertEqual(r.name, 'public') + self.assertEqual(r.description, 'Public test cgitize repository') + self.assertEqual(r.owner.name, 'Test cgitize user') + self.assertEqual(r.owner.login, 'cgitize-test') + self.assertEqual(r.html_url, 'https://github.com/cgitize-test/public') + self.assertEqual(r.clone_url, 'https://github.com/cgitize-test/public.git') + self.assertEqual(r.ssh_url, 'git@github.com:cgitize-test/public.git') + + def test_private_repo(self): + r = self.github.get_repo('cgitize-test/private') + self.assertEqual(r.name, 'private') + self.assertEqual(r.description, 'Private test cgitize repository') + self.assertEqual(r.owner.name, 'Test cgitize user') + self.assertEqual(r.owner.login, 'cgitize-test') + self.assertEqual(r.html_url, 'https://github.com/cgitize-test/private') + self.assertEqual(r.clone_url, 'https://github.com/cgitize-test/private.git') + self.assertEqual(r.ssh_url, 'git@github.com:cgitize-test/private.git') + + def test_user(self): + # This is a bad way to get user's repositories: it'll return only + # public ones for on particular reason. + rs = self.github.get_user('cgitize-test').get_repos() + self.assertEqual(len([r for r in rs if r.name == 'public']), 1) + self.assertEqual(len([r for r in rs if r.name == 'private']), 0) + + def test_user_authenticated(self): + # This is the way instead: + rs = self.github.get_user().get_repos() + self.assertEqual(len([r for r in rs if r.name == 'public']), 1) + self.assertEqual(len([r for r in rs if r.name == 'private']), 1) + + +class GitHubTestPrivateRepo(unittest.TestCase): + def setUp(self): + self.github = Github() + + def test_private_repo(self): + with self.assertRaises(GithubException): + self.github.get_repo('cgitize-test/private') diff --git a/test/unit/test_gitlab.py b/test/unit/test_gitlab.py index 04a8f71..d708539 100644 --- a/test/unit/test_gitlab.py +++ b/test/unit/test_gitlab.py @@ -20,12 +20,40 @@ class GitLabTests(unittest.TestCase): with self.assertRaises(GitlabGetError): self.gitlab.projects.get('doesnot/exist') - def test_existing_repo(self): - r = self.gitlab.projects.get('egor-tensin/cgitize-test-repository') - self.assertEqual(r.name, 'cgitize-test-repository') - self.assertEqual(r.description, 'Test cgitize repository') - self.assertEqual(r.namespace['name'], 'Egor Tensin') - self.assertEqual(r.namespace['path'], 'egor-tensin') - self.assertEqual(r.web_url, 'https://gitlab.com/egor-tensin/cgitize-test-repository') - self.assertEqual(r.http_url_to_repo, 'https://gitlab.com/egor-tensin/cgitize-test-repository.git') - self.assertEqual(r.ssh_url_to_repo, 'git@gitlab.com:egor-tensin/cgitize-test-repository.git') + def test_public_repo(self): + r = self.gitlab.projects.get('cgitize-test/public') + self.assertEqual(r.name, 'public') + self.assertEqual(r.description, 'Public test cgitize repository') + self.assertEqual(r.namespace['name'], 'Test cgitize user') + self.assertEqual(r.namespace['path'], 'cgitize-test') + self.assertEqual(r.web_url, 'https://gitlab.com/cgitize-test/public') + self.assertEqual(r.http_url_to_repo, 'https://gitlab.com/cgitize-test/public.git') + self.assertEqual(r.ssh_url_to_repo, 'git@gitlab.com:cgitize-test/public.git') + + def test_private_repo(self): + r = self.gitlab.projects.get('cgitize-test/private') + self.assertEqual(r.name, 'private') + self.assertEqual(r.description, 'Private test cgitize repository') + self.assertEqual(r.namespace['name'], 'Test cgitize user') + self.assertEqual(r.namespace['path'], 'cgitize-test') + self.assertEqual(r.web_url, 'https://gitlab.com/cgitize-test/private') + self.assertEqual(r.http_url_to_repo, 'https://gitlab.com/cgitize-test/private.git') + self.assertEqual(r.ssh_url_to_repo, 'git@gitlab.com:cgitize-test/private.git') + + def test_user(self): + u = self.gitlab.users.list(username='cgitize-test') + self.assertEqual(len(u), 1) + u = u[0] + + rs = u.projects.list() + self.assertEqual(len([r for r in rs if r.name == 'public']), 1) + self.assertEqual(len([r for r in rs if r.name == 'private']), 1) + + +class GitLabTestPrivateRepo(unittest.TestCase): + def setUp(self): + self.gitlab = Gitlab('https://gitlab.com') + + def test_private_repo(self): + with self.assertRaises(GitlabGetError): + self.gitlab.projects.get('cgitize-test/private') |