def test_check_thresholds(self): self.mock_svc1.check_thresholds.return_value = { 'foo': 'bar', 'baz': 'blam', } self.mock_svc2.check_thresholds.return_value = {} res = self.cls.check_thresholds() assert res == { 'SvcFoo': { 'foo': 'bar', 'baz': 'blam', } } assert self.mock_ta.mock_calls == [ call.update_limits(), ] assert self.mock_svc1.mock_calls == [ call._update_service_quotas(), call.check_thresholds() ] assert self.mock_svc2.mock_calls == [ call._update_limits_from_api(), call._update_service_quotas(), call.check_thresholds() ]
def test_find_usage_no_ta(self): self.cls.find_usage(use_ta=False) assert self.mock_svc1.mock_calls == [ call._update_service_quotas(), call.find_usage() ] assert self.mock_svc2.mock_calls == [ call._update_limits_from_api(), call._update_service_quotas(), call.find_usage() ] assert self.mock_ta.mock_calls == []
def test_find_usage(self): self.cls.find_usage() assert self.mock_svc1.mock_calls == [ call._update_service_quotas(), call.find_usage() ] assert self.mock_svc2.mock_calls == [ call._update_limits_from_api(), call._update_service_quotas(), call.find_usage() ] assert self.mock_ta.mock_calls == [ call.update_limits_per_service(svc.service_name) for svc in self.cls.services.values() ]
def test_get_limits_no_ta(self): limits = sample_limits() self.mock_svc1.get_limits.return_value = limits['SvcFoo'] self.mock_svc2.get_limits.return_value = limits['SvcBar'] res = self.cls.get_limits(use_ta=False) assert res == limits assert self.mock_ta.mock_calls == [] assert self.mock_svc1.mock_calls == [ call._update_service_quotas(), call.get_limits() ] assert self.mock_svc2.mock_calls == [ call._update_limits_from_api(), call._update_service_quotas(), call.get_limits() ]
def test_find_usage_service(self): self.cls.find_usage(service=['SvcFoo']) assert self.mock_svc1.mock_calls == [ call._update_service_quotas(), call.find_usage() ] assert self.mock_svc2.mock_calls == [] assert self.mock_ta.mock_calls == [call.update_limits()]
def test_get_limits(self): limits = sample_limits() self.mock_svc1.get_limits.return_value = limits['SvcFoo'] self.mock_svc2.get_limits.return_value = limits['SvcBar'] res = self.cls.get_limits() assert res == limits assert self.mock_ta.mock_calls == [ call.update_limits_per_service(sname) for sname in self.cls.services.keys() ] assert self.mock_svc1.mock_calls == [ call._update_service_quotas(), call.get_limits() ] assert self.mock_svc2.mock_calls == [ call._update_limits_from_api(), call._update_service_quotas(), call.get_limits() ]
def test_find_usage_service(self): self.cls.find_usage(service=['SvcFoo']) assert self.mock_svc1.mock_calls == [ call._update_service_quotas(), call.find_usage() ] assert self.mock_svc2.mock_calls == [] svc_name = self.cls.services['SvcFoo'].service_name assert self.mock_ta.mock_calls == [ call.update_limits_per_service(svc_name) ]
def test_get_limits_service(self): limits = sample_limits() self.mock_svc1.get_limits.return_value = limits['SvcFoo'] self.mock_svc2.get_limits.return_value = limits['SvcBar'] res = self.cls.get_limits(service=['SvcFoo']) assert res == {'SvcFoo': limits['SvcFoo']} assert self.mock_ta.mock_calls == [call.update_limits()] assert self.mock_svc1.mock_calls == [ call._update_service_quotas(), call.get_limits() ] assert self.mock_svc2.mock_calls == []
def test_check_thresholds_service(self): self.mock_svc1.check_thresholds.return_value = {'foo': 'bar'} self.mock_svc2.check_thresholds.return_value = {'baz': 'blam'} res = self.cls.check_thresholds(service=['SvcFoo']) assert res == { 'SvcFoo': { 'foo': 'bar', } } assert self.mock_ta.mock_calls == [ call.update_limits_per_service('SvcFoo') ] assert self.mock_svc1.mock_calls == [ call._update_service_quotas(), call.check_thresholds() ] assert self.mock_svc2.mock_calls == []