def test_find_usage(self): response = result_fixtures.Lambda.test_lambda_response mock_conn = Mock() mock_conn.get_account_settings.return_value = response with patch('%s.connect' % pb) as mock_connect: cls = _LambdaService(21, 43) cls.conn = mock_conn assert cls._have_usage is False cls.get_limits() cls.find_usage() assert mock_connect.mock_calls == [call()] assert mock_conn.mock_calls == [call.get_account_settings()] assert cls._have_usage is True assert len(cls.limits) == 6 u = cls.limits['Function Count'].get_current_usage() assert len(u) == 1 assert u[0].get_value() == 12 u = cls.limits['Total Code Size (MiB)'].get_current_usage() assert len(u) == 1 assert u[0].get_value() == 2
def test_find_usage_connection_fail(self): def conn_err(): raise EndpointConnectionError(endpoint_url='myurl') mock_conn = Mock() mock_conn.get_account_settings.side_effect = conn_err with patch('%s.connect' % pb) as mock_connect: with patch('%s.logger' % pbm) as mock_logger: cls = _LambdaService(21, 43) cls.conn = mock_conn cls.find_usage() assert len(cls.limits) == 6 assert mock_connect.mock_calls == [call()] assert mock_conn.mock_calls == [call.get_account_settings()] assert mock_logger.mock_calls == [ call.debug('Getting limits for Lambda'), call.debug('Getting usage for Lambda metrics'), call.warn('Skipping Lambda: %s', 'Could not connect to the endpoint URL: "myurl"') ]
def test_update_limits_from_api(self): response = result_fixtures.Lambda.test_lambda_response mock_conn = Mock() mock_conn.get_account_settings.return_value = response with patch('%s.connect' % pb) as mock_connect: cls = _LambdaService(21, 43) assert len(cls.limits) == 6 cls.conn = mock_conn cls._update_limits_from_api() assert mock_connect.mock_calls == [call()] assert mock_conn.mock_calls == [call.get_account_settings()] assert len(cls.limits) == 6 lim = cls.limits['Code Size Unzipped (MiB) per Function'].get_limit() assert lim == 250 lim = cls.limits['Code Size Zipped (MiB) per Function'].get_limit() assert lim == 50 lim = cls.limits['Total Code Size (MiB)'].get_limit() assert lim == 76800 lim = cls.limits['Unreserved Concurrent Executions'].get_limit() assert lim == 1000 lim = cls.limits['Concurrent Executions'].get_limit() assert lim == 1000