def test_dummy_app_logging_nosecret(self): temp = get_temp_folder(__file__, 'temp_dummy_app_logging_nosecret') self.app = dummy_application(secret=None, folder=temp) bodyin = json_dumps({'X': [0.1, 0.2]}) result = self.simulate_post('/', body=bodyin) self.assertEqual(result.status, falcon.HTTP_201) d = json_loads(result.content) self.assertTrue('Y' in d) self.assertIsInstance(d['Y'], (list, numpy.ndarray)) self.assertEqual(len(d['Y']), 1) self.assertEqual(len(d['Y'][0]), 3) res = list(enumerate_parsed_logs(temp, secret=None)) self.assertEqual(len(res), 2) for r in res: self.assertIn('dt', r) self.assertIn('code', r) self.assertIn('data', r) for _ in range(0, 10): result = self.simulate_post('/', body=bodyin) self.assertEqual(result.status, falcon.HTTP_201)
def process_server(host, port): from lightmlrestapi.testing import dummy_application app = dummy_application() from waitress import serve serve(app, host=host, port=port)
def setUp(self): super(TestDummyApp, self).setUp() self.app = dummy_application(self.app)
def _get_app(name, options, secret, users): """ Get application. """ try: from ..testing import dummy_application, dummy_application_image, dummy_application_fct from ..testing import dummy_application_neighbors, dummy_application_neighbors_image except (ImportError, ValueError): folder = os.path.normpath(os.path.join( os.path.abspath(os.path.dirname(__file__)), "..", "..")) sys.path.append(folder) from lightmlrestapi.testing import dummy_application, dummy_application_image, dummy_application_fct from lightmlrestapi.testing import dummy_application_neighbors, dummy_application_neighbors_image if name == "dummy": # Dummy application. if users: raise NotImplementedError("users not None, not implemented") app = dummy_application() elif name == "dummyfct": # Dummy application with a function. name = options if not os.path.exists(name): raise FileNotFoundError("Unable to find '{0}'.".format(name)) path, loc = os.path.split(name) if path not in sys.path: sys.path.append(path) rem = True else: rem = False loc = os.path.splitext(loc)[0] try: mod = __import__(loc) except ImportError as e: if rem: sys.path.pop() with open(name, "r") as f: code = f.read() raise ImportError( "Unable to compile file '{0}'\n{1}".format(name, code)) from e if rem: sys.path.pop() if not hasattr(mod, 'restapi_version'): with open(name, "r") as f: code = f.read() raise AttributeError( "Unable to find function 'restapi_version' in file '{0}'\n{1}".format(name, code)) if not hasattr(mod, 'restapi_load'): with open(name, "r") as f: code = f.read() raise AttributeError( "Unable to find function 'restapi_load' in file '{0}'\n{1}".format(name, code)) if not hasattr(mod, 'restapi_predict'): with open(name, "r") as f: code = f.read() raise AttributeError( "Unable to find function 'restapi_predict' in file '{0}'\n{1}".format(name, code)) if secret == '': secret = None app = dummy_application_fct(mod.restapi_load, mod.restapi_predict, secret=secret, version=mod.restapi_version, users=users) elif name == "dummyimg": # Dummy application with an image. if users: raise NotImplementedError("users not None, not implemented") app = dummy_application_image(options=options, secret=secret) elif name == "dummyknn": # Dummy application with neighbors. if users: raise NotImplementedError("users not None, not implemented") app = dummy_application_neighbors() elif name == "dummyknnimg": # Dummy application with neighbors and an image. if users: raise NotImplementedError("users not None, not implemented") app = dummy_application_neighbors_image(options=options, secret=secret) elif '.py' in name: raise NotImplementedError( "Unable to get application from filename '{}'. Not implemented.".format(name)) else: raise NotImplementedError( "Application '{}' is not implemented.".format(name)) return app
def setUp(self): super(TestDummyAppLogging2, self).setUp() self.temp = get_temp_folder(__file__, 'temp_dummy_app_logging2') self.app = dummy_application( self.app, secret='dummys', folder=self.temp)