From ce4b199fe472c23f37376fc2e30e946c93bd4952 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 30 Jul 2021 21:39:13 +0300 Subject: add some unit tests This is a first step towards integrating with GitHub/Bitbucket properly. --- test/test_bitbucket.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/test_bitbucket.py (limited to 'test/test_bitbucket.py') diff --git a/test/test_bitbucket.py b/test/test_bitbucket.py new file mode 100644 index 0000000..776c48c --- /dev/null +++ b/test/test_bitbucket.py @@ -0,0 +1,34 @@ +# Copyright (c) 2021 Egor Tensin +# This file is part of the "cgitize" project. +# For details, see https://github.com/egor-tensin/cgitize. +# Distributed under the MIT License. + +import unittest + +from atlassian.bitbucket.cloud import Cloud +from requests.exceptions import HTTPError + + +class BitbucketTests(unittest.TestCase): + def setUp(self): + self.bitbucket = Cloud(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') + + https_links = [link for link in r['links']['clone'] if link['name'] == 'https'] + self.assertEqual(len(https_links), 1) + self.assertEqual(https_links[0]['href'], 'https://bitbucket.org/egor-tensin/cgitize-test-repository.git') + + ssh_links = [link for link in r['links']['clone'] if link['name'] == 'ssh'] + self.assertEqual(len(ssh_links), 1) + self.assertEqual(ssh_links[0]['href'], 'git@bitbucket.org:egor-tensin/cgitize-test-repository.git') + + self.assertEqual(r['owner']['display_name'], 'Egor Tensin') + self.assertEqual(r['owner']['nickname'], 'egor-tensin') -- cgit v1.2.3