예제 #1
0
 def test_warning(self, mocked_warning):
     create_app()
     mocked_warning.assert_called_once_with(
         "'data_dir' not given. Application data is stored in "
         "memory and is lost when the flask app terminates. Set "
         "the environment variable FINANCEAGER_FLASK_DATA_DIR "
         "accordingly for persistent data storage.")
예제 #2
0
 def test_data_dir_env_variable(self):
     data_dir = tempfile.mkdtemp(prefix="financeager-")
     environ["FINANCEAGER_FLASK_DATA_DIR"] = data_dir
     with mock.patch("os.makedirs") as mocked_makedirs:
         create_app(data_dir=None)
         # First call is from inside setup_log_file_handler()
         self.assertEqual(mocked_makedirs.call_count, 2)
         mocked_makedirs.assert_called_with(data_dir, exist_ok=True)
     del environ["FINANCEAGER_FLASK_DATA_DIR"]
예제 #3
0
 def test_bad_request(self):
     app = create_app()
     app.testing = True
     with app.test_client() as client:
         response = client.post("/pockets/2000")
     # Expect Bad Request due to missing data (name and value)
     self.assertEqual(response.status_code, 400)
예제 #4
0
    def launch_server():
        # Patch DATA_DIR inside the thread to avoid having it
        # created/interfering with logs on actual machine
        import financeager
        financeager.DATA_DIR = TEST_DATA_DIR
        app = fflask.create_app(
            data_dir=TEST_DATA_DIR,
            config={
                "DEBUG": False,  # reloader can only be run in main thread
                "SERVER_NAME": CliFlaskTestCase.HOST_IP,
            })

        def shutdown():
            from flask import request
            app._server.run('stop')
            request.environ.get("werkzeug.server.shutdown")()
            return ""

        # For testing, add rule to shutdown Flask app
        app.add_url_rule("/stop", "stop", shutdown)

        app.run()
예제 #5
0
 def test_debug(self):
     app = create_app(config={"DEBUG": True})
     self.assertTrue(app.debug)
     self.assertEqual(financeager.LOGGER.handlers[0].level, 10)
예제 #6
0
    AuthUserFile /var/www/virtual/USER/.htuser
    Require valid-user

On the client side, specify user and password in the config file as documented
in the main README.

You can prettify the URL format by adding a file ~/html/.htaccess with content
    RewriteEngine On
    RewriteRule ^financeager/(.*)$ /fcgi-bin/financeager.fcgi/$1 [QSA,L]

Force a restart of the FCGI app by killing the existing one.
This allows you to access via
    http://USER.STAR.uberspace.de/financeager

Further reading:
https://blog.lucas-hild.de/flask-uberspace
https://gist.github.com/tocsinDE/98c423da2724d23c02ff
https://docs.python.org/3.4/howto/webservers.html
https://wiki.uberspace.de/webserver:htaccess#verzeichnisschutz
"""
from flipflop import WSGIServer

from financeager_flask import DATA_DIR, fflask

if __name__ == "__main__":
    # Configure to your liking
    app = fflask.create_app(data_dir=DATA_DIR,
                            # config={"DEBUG": True},
                            )
    WSGIServer(app).run()
예제 #7
0
# This is an examplatory WSGI configuration file. I use it to run financeager on
# pythonanywhere.
# It is assumed that the financeager project is cloned to the home directory and
# all requirements are installed.

import os
import sys

from financeager_flask import DATA_DIR
from financeager_flask.fflask import create_app

path = os.path.expanduser('~/financeager-flask/financeager_flask/fflask.py')
if path not in sys.path:
    sys.path.append(path)

# the 'application' object will be used by the WSGI server
application = create_app(
    data_dir=DATA_DIR,
    config={"DEBUG": True},
)