Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
.sonarlint
.vscode

tags

__pycache__
venv
junk
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -64,7 +67,7 @@ Installing without setup.py
Then install the required python packages using pip_::

$ sudo pip install python-teamcity

Inspiration
---------------

Expand Down
13 changes: 9 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion teamcity/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion teamcity/teamcity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import *
44 changes: 44 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tests/test_teamcity.py
Original file line number Diff line number Diff line change
@@ -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"