32
32
import ConfigParser as configparser
35
class TestConfig(unittest.TestCase):
35
class TestConfig(object):
36
def setup_method(self):
37
37
self.config_parser = Mock()
38
38
self.config = blitzortung.config.Config(self.config_parser)
40
40
def test_get_username(self):
41
41
self.config_parser.get.return_value = '<username>'
42
assert_that(self.config.get_username(), is_(equal_to('<username>')))
43
assert_that(self.config_parser.mock_calls, contains(call.get('auth', 'username')))
42
assert_that(self.config.get_username()).is_equal_to('<username>')
43
assert_that(self.config_parser.mock_calls).contains(call.get('auth', 'username'))
45
45
def test_get_password(self):
46
46
self.config_parser.get.return_value = '<password>'
47
assert_that(self.config.get_password(), is_(equal_to('<password>')))
48
assert_that(self.config_parser.mock_calls, contains(call.get('auth', 'password')))
47
assert_that(self.config.get_password()).is_equal_to('<password>')
48
assert_that(self.config_parser.mock_calls).contains(call.get('auth', 'password'))
50
50
def test_get_raw_path(self):
51
51
self.config_parser.get.return_value = '<raw_path>'
52
assert_that(self.config.get_raw_path(), is_(equal_to('<raw_path>')))
53
assert_that(self.config_parser.mock_calls, contains(call.get('path', 'raw')))
52
assert_that(self.config.get_raw_path()).is_equal_to('<raw_path>')
53
assert_that(self.config_parser.mock_calls).contains(call.get('path', 'raw'))
55
55
def test_get_archive_path(self):
56
56
self.config_parser.get.return_value = '<archive_path>'
57
assert_that(self.config.get_archive_path(), is_(equal_to('<archive_path>')))
58
assert_that(self.config_parser.mock_calls, contains(call.get('path', 'archive')))
57
assert_that(self.config.get_archive_path()).is_equal_to('<archive_path>')
58
assert_that(self.config_parser.mock_calls).contains(call.get('path', 'archive'))
60
60
def test_get_db_connection_string(self):
61
61
self.config_parser.get.side_effect = lambda *x: {
64
64
('db', 'username'): '<username>',
65
65
('db', 'password'): '<password>'}[x]
67
assert_that(self.config.get_db_connection_string(),
68
is_(equal_to("host='<host>' dbname='<dbname>' user='<username>' password='<password>'")))
67
assert_that(self.config.get_db_connection_string()) \
68
.is_equal_to("host='<host>' dbname='<dbname>' user='<username>' password='<password>'")
70
assert_that(self.config_parser.mock_calls, contains(
70
assert_that(self.config_parser.mock_calls).contains(
71
71
call.get('db', 'host'),
72
72
call.get('db', 'dbname'),
73
73
call.get('db', 'username'),
74
call.get('db', 'password')))
74
call.get('db', 'password'))
76
76
def test_get_webservice_port(self):
77
77
self.config_parser.get.return_value = 1234
78
assert_that(self.config.get_webservice_port(), is_(equal_to(1234)))
79
assert_that(self.config_parser.mock_calls, contains(call.get('webservice', 'port')))
78
assert_that(self.config.get_webservice_port()).is_equal_to(1234)
79
assert_that(self.config_parser.mock_calls).contains(call.get('webservice', 'port'))
81
81
def test_string_representation(self):
82
82
self.config_parser.get.side_effect = lambda *x: {
83
83
('auth', 'username'): '<username>',
84
84
('auth', 'password'): '<password>'}[x]
86
assert_that(str(self.config), is_(equal_to("Config(user: <username>, pass: **********)")))
86
assert_that(str(self.config)).is_equal_to("Config(user: <username>, pass: **********)")
88
assert_that(self.config_parser.mock_calls, contains(
88
assert_that(self.config_parser.mock_calls).contains(
89
89
call.get('auth', 'username'),
90
call.get('auth', 'password')))
93
class TestConfigModule(unittest.TestCase):
90
call.get('auth', 'password'))
93
class TestConfigModule(object):
95
def setup_method(self):
96
96
self.config_module = blitzortung.config.ConfigModule()
98
98
@patch(config_parser_module + '.ConfigParser')
99
99
def test_provide_config_parser(self, config_parser_class_mock):
100
100
config_parser = self.config_module.provide_config_parser()
102
assert_that(config_parser, is_(config_parser_class_mock.return_value))
103
assert_that(config_parser_class_mock.mock_calls, has_item(call()))
104
assert_that(config_parser.mock_calls, has_item(call.read('/etc/blitzortung.conf')))
102
assert_that(config_parser).is_equal_to(config_parser_class_mock.return_value)
103
assert_that(config_parser_class_mock.mock_calls).contains(call())
104
assert_that(config_parser.mock_calls).contains(call.read('/etc/blitzortung.conf'))
106
106
@patch('blitzortung.INJECTOR')
107
107
def test_get_config(self, injector_class_mock):
109
109
injector_class_mock.get.return_value = config
111
assert_that(blitzortung.config.config(), is_(equal_to(config)))
b'\\ No newline at end of file'
111
assert_that(blitzortung.config.config()).is_equal_to(config)