3
from testtools import TestCase
4
from testtools.matchers import raises, Equals
8
from contextlib import contextmanager
12
def temp_config_file(content):
13
with tempfile.NamedTemporaryFile() as f:
20
class ConfigFileLoadTests(TestCase):
22
def test_raises_IOError_if_file_not_found(self):
23
name = tempfile.mktemp()
25
lambda: lkkb.get_lkkb_auth_pair(name),
29
def assert_content_raises_exception(self, content, exception):
30
with temp_config_file(content) as name:
32
lambda: lkkb.get_lkkb_auth_pair(name),
36
def test_empty_file_raises_ValueError(self):
37
self.assert_content_raises_exception(
39
ValueError("Could not find 'LeanKit' section in config file.")
42
def test_empty_section_raises_ValueError(self):
43
self.assert_content_raises_exception(
45
ValueError("No username set in config file.")
48
def test_empty_user_option_raises_ValueError(self):
49
self.assert_content_raises_exception(
54
ValueError("No username set in config file.")
57
def test_missing_password_raises_ValueError(self):
58
self.assert_content_raises_exception(
63
ValueError("No password set in config file.")
66
def test_empty_password_raises_ValueError(self):
67
self.assert_content_raises_exception(
73
ValueError("No password set in config file.")
76
def test_can_retrieve_username_and_password(self):
77
with temp_config_file(
83
lkkb.get_lkkb_auth_pair(name),
84
Equals(('foo', 'bar'))
89
from unittest import TestLoader
90
return TestLoader().loadTestsFromName(__name__)