-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We now have enough non-network functionality to warrant testing. Signed-off-by: Stephen Finucane <[email protected]>
- Loading branch information
1 parent
5c0db06
commit fb73c2c
Showing
4 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"""Unit tests for ``git_pw/api.py``.""" | ||
|
||
import mock | ||
import pytest | ||
|
||
from git_pw import api | ||
|
||
|
||
@mock.patch.object(api, 'LOG') | ||
@mock.patch.object(api, 'CONF') | ||
def test_get_server_undefined(mock_conf, mock_log): | ||
mock_conf.server = None | ||
|
||
with pytest.raises(SystemExit): | ||
api._get_server() | ||
|
||
assert mock_log.error.called | ||
|
||
|
||
@mock.patch.object(api, 'LOG') | ||
@mock.patch.object(api, 'CONF') | ||
def test_get_server_missing_version(mock_conf, mock_log): | ||
mock_conf.server = 'https://example.com/api' | ||
|
||
server = api._get_server() | ||
|
||
assert mock_log.warning.called | ||
assert server == 'https://example.com/api' | ||
|
||
|
||
@mock.patch.object(api, 'LOG') | ||
@mock.patch.object(api, 'CONF') | ||
def test_get_server_missing_version_and_path(mock_conf, mock_log): | ||
mock_conf.server = 'https://example.com/' | ||
|
||
server = api._get_server() | ||
|
||
assert mock_log.warning.called | ||
assert server == 'https://example.com/api' | ||
|
||
|
||
@mock.patch.object(api, 'LOG') | ||
@mock.patch.object(api, 'CONF') | ||
def test_get_project_undefined(mock_conf, mock_log): | ||
mock_conf.project = None | ||
|
||
with pytest.raises(SystemExit): | ||
api._get_project() | ||
|
||
assert mock_log.error.called | ||
|
||
|
||
@mock.patch.object(api, 'CONF') | ||
def test_get_project_wildcard(mock_conf): | ||
mock_conf.project = '*' | ||
|
||
project = api._get_project() | ||
|
||
assert project == '' | ||
|
||
|
||
@mock.patch.object(api, '_get_server') | ||
def test_version_missing(mock_server): | ||
mock_server.return_value = 'https://example.com/api' | ||
|
||
assert api.version() == (1, 0) | ||
|
||
|
||
@mock.patch.object(api, '_get_server') | ||
def test_version(mock_server): | ||
mock_server.return_value = 'https://example.com/api/1.1' | ||
|
||
assert api.version() == (1, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mock==2.0.0 | ||
pytest==3.6.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters