def test_get_limits_again(self):
     """test that existing limits dict is returned on subsequent calls"""
     mock_limits = Mock()
     cls = _DirectoryserviceService(21, 43)
     cls.limits = mock_limits
     res = cls.get_limits()
     assert res == mock_limits
 def test_find_usage(self):
     mock_conn = Mock()
     mock_conn.get_directory_limits.return_value = {
         'DirectoryLimits': {
             'CloudOnlyDirectoriesLimit': 3,
             'CloudOnlyDirectoriesCurrentCount': 4,
             'CloudOnlyDirectoriesLimitReached': True,
             'CloudOnlyMicrosoftADLimit': 6,
             'CloudOnlyMicrosoftADCurrentCount': 1,
             'CloudOnlyMicrosoftADLimitReached': False,
             'ConnectedDirectoriesLimit': 12,
             'ConnectedDirectoriesCurrentCount': 0,
             'ConnectedDirectoriesLimitReached': False
         }
     }
     with patch('%s.connect' % pb) as mock_connect:
         cls = _DirectoryserviceService(21, 43)
         cls.conn = mock_conn
         assert cls._have_usage is False
         cls.find_usage()
     assert mock_connect.mock_calls == [call()]
     assert cls._have_usage is True
     assert mock_conn.mock_calls == [call.get_directory_limits()]
     assert cls.limits['CloudOnlyDirectories'].get_current_usage(
     )[0].get_value() == 4
     assert cls.limits['CloudOnlyMicrosoftAD'].get_current_usage(
     )[0].get_value() == 1
     assert cls.limits['ConnectedDirectories'].get_current_usage(
     )[0].get_value() == 0
예제 #3
0
 def test_find_usage(self):
     mock_conn = Mock()
     mock_conn.get_directory_limits.return_value = {
         'DirectoryLimits': {
             'CloudOnlyDirectoriesLimit': 3,
             'CloudOnlyDirectoriesCurrentCount': 4,
             'CloudOnlyDirectoriesLimitReached': True,
             'CloudOnlyMicrosoftADLimit': 6,
             'CloudOnlyMicrosoftADCurrentCount': 1,
             'CloudOnlyMicrosoftADLimitReached': False,
             'ConnectedDirectoriesLimit': 12,
             'ConnectedDirectoriesCurrentCount': 0,
             'ConnectedDirectoriesLimitReached': False
         }
     }
     with patch('%s.connect' % pb) as mock_connect:
         cls = _DirectoryserviceService(21, 43)
         cls.conn = mock_conn
         assert cls._have_usage is False
         cls.find_usage()
     assert mock_connect.mock_calls == [call()]
     assert cls._have_usage is True
     assert mock_conn.mock_calls == [call.get_directory_limits()]
     assert cls.limits['CloudOnlyDirectories'].get_current_usage(
     )[0].get_value() == 4
     assert cls.limits['CloudOnlyMicrosoftAD'].get_current_usage(
     )[0].get_value() == 1
     assert cls.limits['ConnectedDirectories'].get_current_usage(
     )[0].get_value() == 0
예제 #4
0
 def test_get_limits_again(self):
     """test that existing limits dict is returned on subsequent calls"""
     mock_limits = Mock()
     cls = _DirectoryserviceService(21, 43)
     cls.limits = mock_limits
     res = cls.get_limits()
     assert res == mock_limits
 def test_update_limits_from_api(self):
     mock_conn = Mock()
     mock_conn.get_directory_limits.return_value = {
         'DirectoryLimits': {
             'CloudOnlyDirectoriesLimit': 3,
             'CloudOnlyDirectoriesCurrentCount': 4,
             'CloudOnlyDirectoriesLimitReached': True,
             'CloudOnlyMicrosoftADLimit': 6,
             'CloudOnlyMicrosoftADCurrentCount': 1,
             'CloudOnlyMicrosoftADLimitReached': False,
             'ConnectedDirectoriesLimit': 12,
             'ConnectedDirectoriesCurrentCount': 0,
             'ConnectedDirectoriesLimitReached': False
         }
     }
     with patch('%s.connect' % pb) as mock_connect:
         cls = _DirectoryserviceService(21, 43, {}, None)
         cls.conn = mock_conn
         assert cls._have_usage is False
         cls._update_limits_from_api()
     assert mock_connect.mock_calls == [call()]
     assert mock_conn.mock_calls == [call.get_directory_limits()]
     assert cls.limits['CloudOnlyDirectories'].api_limit == 3
     assert cls.limits['CloudOnlyMicrosoftAD'].api_limit == 6
     assert cls.limits['ConnectedDirectories'].api_limit == 12
 def test_init(self):
     """test __init__()"""
     cls = _DirectoryserviceService(21, 43)
     assert cls.service_name == 'Directory Service'
     assert cls.api_name == 'ds'
     assert cls.conn is None
     assert cls.warning_threshold == 21
     assert cls.critical_threshold == 43
예제 #7
0
 def test_init(self):
     """test __init__()"""
     cls = _DirectoryserviceService(21, 43)
     assert cls.service_name == 'Directory Service'
     assert cls.api_name == 'ds'
     assert cls.conn is None
     assert cls.warning_threshold == 21
     assert cls.critical_threshold == 43
 def test_get_limits(self):
     cls = _DirectoryserviceService(21, 43)
     cls.limits = {}
     res = cls.get_limits()
     assert sorted(res.keys()) == sorted([
         'CloudOnlyDirectories',
         'CloudOnlyMicrosoftAD',
         'ConnectedDirectories',
     ])
     for name, limit in res.items():
         assert limit.service == cls
         assert limit.def_warning_threshold == 21
         assert limit.def_critical_threshold == 43
예제 #9
0
 def test_get_limits(self):
     cls = _DirectoryserviceService(21, 43)
     cls.limits = {}
     res = cls.get_limits()
     assert sorted(res.keys()) == sorted([
         'CloudOnlyDirectories',
         'CloudOnlyMicrosoftAD',
         'ConnectedDirectories',
     ])
     for name, limit in res.items():
         assert limit.service == cls
         assert limit.def_warning_threshold == 21
         assert limit.def_critical_threshold == 43
 def test_required_iam_permissions(self):
     cls = _DirectoryserviceService(21, 43)
     assert cls.required_iam_permissions() == [
         'ds:GetDirectoryLimits'
     ]
예제 #11
0
 def test_required_iam_permissions(self):
     cls = _DirectoryserviceService(21, 43)
     assert cls.required_iam_permissions() == ['ds:GetDirectoryLimits']