15
15
@mock.patch('mysql.MySQLHelper', autospec=True)
16
16
@mock.patch('mysql.relation_get')
17
17
@mock.patch('mysql.related_units')
18
@mock.patch('mysql.relation_ids')
19
18
@mock.patch('mysql.log')
20
def test_get_allowed_units(self, mock_log, mock_relation_ids,
19
def test_get_allowed_units(self, mock_log, mock_related_units,
22
20
mock_relation_get, mock_helper,
23
21
mock_get_password):
24
mock_relation_ids.return_value = ['r1']
25
mock_related_units.return_value = ['ru1', 'ru2']
27
def mock_rel_get(attribute, unit, rid):
29
d = {'private-address': '1.2.3.4',
30
'dbA_hostname': json.dumps(['2.3.4.5', '6.7.8.9'])}
32
d = {'private-address': '1.2.3.4'}
34
return d.get(attribute, None)
23
def mock_rel_get(unit, rid):
25
# Non-prefixed settings
26
d = {'private-address': '10.0.0.1',
28
elif unit == 'unit/1':
29
# Containing prefixed settings
30
d = {'private-address': '10.0.0.2',
31
'dbA_hostname': json.dumps(['10.0.0.2', '2001:db8:1::2'])}
32
elif unit == 'unit/2':
34
d = {'private-address': '10.0.0.3'}
36
38
mock_relation_get.side_effect = mock_rel_get
39
mock_related_units.return_value = ['unit/0', 'unit/1', 'unit/2']
37
41
units = mysql.get_allowed_units('dbA', 'userA')
38
mock_helper.return_value.grant_exists.assert_called_with('dbA',
41
self.assertEqual(units, set(['ru1', 'ru2']))
43
calls = [mock.call('dbA', 'userA', 'hostA'),
44
mock.call().__nonzero__(),
45
mock.call('dbA', 'userA', '10.0.0.2'),
46
mock.call().__nonzero__(),
47
mock.call('dbA', 'userA', '2001:db8:1::2'),
48
mock.call().__nonzero__(),
49
mock.call('dbA', 'userA', '10.0.0.3'),
50
mock.call().__nonzero__()]
52
mock_helper.return_value.grant_exists.assert_has_calls(calls)
53
self.assertEqual(units, set(['unit/0', 'unit/1', 'unit/2']))