diff --git a/.gitignore b/.gitignore index d9de844..00f724b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,8 @@ .sonarlint .vscode +tags + __pycache__ venv +junk diff --git a/README.md b/README.md index fdb1eed..25524bb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ README ====== +[![Build Status](https://semaphoreci.com/api/v1/octopi-assembly/python-teamcity/branches/0-1/shields_badge.svg)](https://semaphoreci.com/octopi-assembly/python-teamcity) + + Python Teamcity is a python wrapper for the [Teamcity](https://www.jetbrains.com/teamcity/) REST API which aims to provide a more conventionally pythonic way of controlling a Teamcity server. It provides a higher-level API containing a number of @@ -64,7 +67,7 @@ Installing without setup.py Then install the required python packages using pip_:: $ sudo pip install python-teamcity - + Inspiration --------------- diff --git a/requirements.txt b/requirements.txt index bcd0e07..0d88385 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,13 @@ -certifi==2018.10.15 +atomicwrites==1.2.1 +attrs==18.2.0 +certifi==2018.11.29 chardet==3.0.4 -idna==2.7 -pkg-resources==0.0.0 +idna==2.8 +more-itertools==4.3.0 +pluggy==0.8.0 +py==1.7.0 +pytest==4.0.2 python-dateutil==2.7.5 -requests==2.20.1 +requests==2.21.0 six==1.12.0 urllib3==1.24.1 diff --git a/teamcity/api.py b/teamcity/api.py index 884c6fd..bb8a994 100644 --- a/teamcity/api.py +++ b/teamcity/api.py @@ -34,7 +34,7 @@ def __init__(self, username, password, scheme="http", host="localhost", port=811 self.password = password if password else os.environ.get('TEAMCITY_PASSWORD') self.protocol = scheme self.host = host - self.port = port + self.port = port if isinstance(port, int) else int(port) self.session = kwargs.get('session', requests.Session()) self.session.auth = HTTPBasicAuth(self.username, self.password) diff --git a/teamcity/teamcity.py b/teamcity/teamcity.py index 4a7bb01..766c970 100644 --- a/teamcity/teamcity.py +++ b/teamcity/teamcity.py @@ -31,7 +31,10 @@ def _generate_api_endpoint(self): if os.environ.get('TEAMCITY_API_VERSION'): api = os.environ.get('TEAMCITY_API') auth = "{auth}/{api}/{version}".format(auth=auth, api=api, version=os.environ.get('TEAMCITY_API_VERSION')) - self.api_endpoint = "{base_url}/{auth}".format(base_url=self.base_url, auth=auth) + if auth: + self.api_endpoint = "{base_url}/{auth}".format(base_url=self.base_url, auth=auth) + else: + self.api_endpoint = "{base_url}".format(base_url=self.base_url) @classmethod def from_environ(cls): diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..b974282 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +from . import * \ No newline at end of file diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..f366a4e --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,44 @@ +import pytest + +from teamcity.api import TeamcityApi + + +@pytest.fixture +def username(): + ''' Username for the tests + ''' + return "srahul07" + +@pytest.fixture +def password(): + """ Password for the tests + """ + return "rahul" + +class TestTeamcityApi(object): + + def test_default_initial_connect(self, username, password): + teamcity_api = TeamcityApi(username, password) + assert teamcity_api.protocol == "http" + assert teamcity_api.host == "localhost" + assert teamcity_api.port == 8111 + + @pytest.mark.parametrize("scheme, host, port", [ + ("http", "localhost", "8111") + ]) + def test_setting_initial_connect(self, username, password, scheme, host, port): + teamcity_api = TeamcityApi(username, password, scheme, host, port) + assert teamcity_api.protocol == "http" + assert teamcity_api.host == "localhost" + assert teamcity_api.port == 8111 + + def test_base_url(self, username, password): + teamcity_api = TeamcityApi(username, password) + assert teamcity_api.base_url == "http://localhost:8111" + + @pytest.mark.parametrize("scheme, host, port, expected", [ + ("https", "example.com", 443, "https://example.com") + ]) + def test__generate_url(self, username, password, scheme, host, port, expected): + teamcity_api = TeamcityApi(username, password, scheme, host, port) + assert teamcity_api._generate_url() == expected \ No newline at end of file diff --git a/tests/test_teamcity.py b/tests/test_teamcity.py new file mode 100644 index 0000000..3eb7c4f --- /dev/null +++ b/tests/test_teamcity.py @@ -0,0 +1,15 @@ +import pytest + +from teamcity.teamcity import Teamcity + + +class TestTeamcity(object): + + def test_username_password(self): + teamcity = Teamcity("srahul07", "rahul") + assert teamcity.username == "srahul07" + assert teamcity.password == "rahul" + + def test_default_initial_connect(self): + teamcity = Teamcity("srahul07", "rahul") + assert teamcity.api_endpoint != "http://localhost:8111/httpAuth" \ No newline at end of file