示例#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_DATA_DIR "
         "accordingly for persistent data storage.")
示例#2
0
 def test_data_dir_env_variable(self):
     data_dir = tempfile.mkdtemp(prefix="financeager-")
     environ["FINANCEAGER_DATA_DIR"] = data_dir
     with mock.patch("os.makedirs") as mocked_makedirs:
         create_app(data_dir=None)
         mocked_makedirs.assert_called_once_with(data_dir, exist_ok=True)
     del environ["FINANCEAGER_DATA_DIR"]
示例#3
0
 def test_data_dir_env_variable(self):
     data_dir = tempfile.mkdtemp(prefix="financeager-")
     environ["FINANCEAGER_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_DATA_DIR"]
示例#4
0
 def test_bad_request(self):
     app = create_app()
     app.testing = True
     with app.test_client() as client:
         response = client.post("/periods/2000")
     # Expect Bad Request due to missing data (name and value)
     self.assertEqual(response.status_code, 400)
示例#5
0
 def launch_server():
     app = create_app(
         data_dir=TEST_DATA_DIR,
         config={
             "DEBUG": False,  # reloader can only be run in main thread
             "SERVER_NAME": cls.HOST_IP
         })
     app.run()
示例#6
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 = 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
            request.environ.get("werkzeug.server.shutdown")()
            return ""

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

        app.run()
示例#7
0
 def test_debug(self):
     app = create_app(config={"DEBUG": True})
     self.assertTrue(app.debug)
     self.assertEqual(financeager.LOGGER.handlers[0].level, 10)
示例#8
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 sys
import os

from financeager.fflask import create_app

path = os.path.expanduser('~/financeager/financeager/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=os.path.expanduser('~/.local/share/financeager'),
    config={"DEBUG": True})
示例#9
0
from financeager import fflask

app = fflask.create_app({"debug": True})

if __name__ == "__main__":
    app.run()
示例#10
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 import fflask, DATA_DIR

if __name__ == "__main__":
    # Configure to your liking
    app = fflask.create_app(
        data_dir=DATA_DIR,
        # config={"DEBUG": True},
    )
    WSGIServer(app).run()