def test_optimizers_are_loaded(self): builtin_optimizers_package_name = '../optimizers_builtin' cache = optimizer_cache.OptimizerCache(builtin_optimizers_package_name) optimizer_classes = cache.optimizer_classes self.assertEmpty(optimizer_classes)
def test_only_implementations_of_base_optimizer_are_loaded(self): builtin_optimizers_package_name = '../optimizers_builtin' cache = optimizer_cache.OptimizerCache(builtin_optimizers_package_name) optimizer_classes = cache.optimizer_classes for optimizer_class in optimizer_classes: self.assertTrue(issubclass(optimizer_class, base_optimizer.BaseOptimizer))
def test_optimizers_only_loaded_once(self): builtin_optimizers_package_name = '../optimizers_builtin' with mock.patch( 'optimizers_utils.optimizer_cache.OptimizerCache._get_optimizer_classes_in_package' ) as mock_get_optimizer_classes_in_package: cache = optimizer_cache.OptimizerCache(builtin_optimizers_package_name) # Calls the optimizer_classes property several times to make sure loading # only gets called once. _ = cache.optimizer_classes _ = cache.optimizer_classes _ = cache.optimizer_classes self.assertEqual(1, mock_get_optimizer_classes_in_package.call_count)
from optimizers_utils import optimizer_cache import original_types from util import app_util from util import attribute_miner _V1_BASE_URL = '/shoptimizer/v1' _OPTIMIZERS_BUILTIN_PACKAGE = 'optimizers_builtin' _OPTIMIZERS_PLUGINS_PACKAGE = 'optimizers_plugins' _OPTIMIZERS_THAT_USE_MINED_ATTRIBUTES = frozenset( ['title-optimizer', 'description-optimizer']) _SUPPORTED_LANGUAGES = frozenset(['en', 'ja']) # Sets logging to debug to show logging.info messages. logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) _builtin_optimizer_cache = optimizer_cache.OptimizerCache( _OPTIMIZERS_BUILTIN_PACKAGE) _plugin_optimizer_cache = optimizer_cache.OptimizerCache( _OPTIMIZERS_PLUGINS_PACKAGE) app = app_util.create_app() @app.route(f'{_V1_BASE_URL}/batch/optimize', methods=['POST']) def optimize() -> Tuple[str, http.HTTPStatus]: """Optimizes a JSON payload containing product data. The request body format should match the Content API custom batch insert request format: https://developers.google.com/shopping-content/v2/reference/v2/products/custombatch { "entries": [