-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
18 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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from unittest.mock import MagicMock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from noti import Github | ||
|
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 |
---|---|---|
@@ -1,40 +1,73 @@ | ||
import json | ||
import tempfile | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
import pytest | ||
|
||
from noti import NotiConfig | ||
from noti import NotiError | ||
|
||
def create_tempfile(content): | ||
fp = tempfile.NamedTemporaryFile('w') | ||
fp.write(content) | ||
fp.flush() | ||
conf = NotiConfig(Path(fp.name)) | ||
fp.close() | ||
|
||
return conf | ||
|
||
class TestNotiConfig: | ||
|
||
@patch('noti.Path.home') | ||
def test_init_config(self, home): | ||
home.return_value = tempfile.tempdir | ||
path = Path(home.return_value, ".noticonfig.json") | ||
|
||
assert not path.exists() | ||
|
||
conf = NotiConfig() | ||
content = path.read_text() | ||
path.unlink() | ||
default_config = json.loads(content) | ||
|
||
assert default_config == conf.DEFAULT_CONFIG | ||
assert not path.exists() | ||
|
||
|
||
|
||
def test_user_config(self): | ||
fp = tempfile.NamedTemporaryFile('w') | ||
fp.write(''' | ||
conf = create_tempfile(''' | ||
{ | ||
"gitlab": {} | ||
} | ||
''') | ||
fp.flush() | ||
conf = NotiConfig(Path(fp.name)) | ||
fp.close() | ||
|
||
assert 'gitlab' in conf.user_config | ||
assert 'global' not in conf.user_config | ||
|
||
def test_get_config(self): | ||
fp = tempfile.NamedTemporaryFile('w') | ||
fp.write(''' | ||
conf = create_tempfile(''' | ||
{ | ||
"github": { | ||
"hello": "world" | ||
} | ||
} | ||
''') | ||
fp.flush() | ||
conf = NotiConfig(Path(fp.name)) | ||
fp.close() | ||
|
||
config = conf.get_config('github') | ||
|
||
assert config.get('mr_limit') == 5 | ||
assert config.get('hello') == 'world' | ||
|
||
def test_bitbar_config(self): | ||
conf = create_tempfile(''' | ||
{ | ||
"bitbar": { | ||
"running": "_running_" | ||
} | ||
} | ||
''') | ||
|
||
bitbar = conf.bitbar_config | ||
assert bitbar.get('running') == '_running_' | ||
assert bitbar.get('failed') == NotiConfig.DEFAULT_CONFIG.get('bitbar').get('failed') |