class TestAdministrativeLocal(unittest.TestCase):
    def setUp(self):
        self.app = Flask(__name__)

        self.admin = AdministrativeLocal()
        self.admin.hook_to(self.app)

    def test_shutdown_works(self):
        patch_path = 'fake_ubersmith.api.administrative_local.request'
        environ_path = 'werkzeug.server.shutdown'

        with patch(patch_path, Mock(environ={environ_path: Mock()})) as m:
            with self.app.test_client() as c:
                resp = c.get('/__shutdown')

            self.assertTrue(m.environ.get('werkzeug.server.shutdown').called)

            self.assertEqual(resp.status_code, 200)
            self.assertEqual(
                json.loads(resp.data.decode('utf-8')).get('data'),
                "Shutting down server...")

    def test_shutdown_raises(self):
        patch_path = 'fake_ubersmith.api.administrative_local.request'

        with patch(patch_path, Mock(environ={})):
            with self.assertRaises(RuntimeError):
                self.admin.shutdown()
Ejemplo n.º 2
0
def run():
    # TODO (wajdi) Make configurable passed parameter
    port = 9131

    app = Flask('fake_ubersmith')

    data_store = DataStore()
    base_uber_api = UbersmithBase(data_store)

    AdministrativeLocal().hook_to(app)

    Uber(data_store).hook_to(base_uber_api)
    Order(data_store).hook_to(base_uber_api)
    Client(data_store).hook_to(base_uber_api)

    base_uber_api.hook_to(app)

    _get_logger(app)

    app.run(host="0.0.0.0", port=port)
Ejemplo n.º 3
0
    def setUp(self):
        self.app = Flask(__name__)

        self.admin = AdministrativeLocal()
        self.admin.hook_to(self.app)