From 9906346691cbf47ee3fb91d61087b6769c7b6551 Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Wed, 6 Mar 2019 15:39:08 +0100 Subject: [PATCH] Add ROOT_DIR, TEMPLATE_DIR to config.py. Make paths platform-independent. Add template/ to bottle TEMPLATE_PATH (you can add bots/ this way after complete refactoring). Rename tests to work with pytests. Change setup.py to run pytests. --- setup.cfg | 2 ++ setup.py | 25 +++++++++++--- ticketfrei/config.py | 7 ++-- ticketfrei/frontend.py | 34 ++++++++++--------- ticketfrei/template/city.tpl | 2 +- ticketfrei/template/login.tpl | 4 +-- ticketfrei/template/mail.tpl | 2 +- ticketfrei/template/propaganda.tpl | 6 ++-- ticketfrei/template/register.tpl | 4 +-- ticketfrei/template/settings.tpl | 2 +- .../{WebApplicationLogin.py => test_login.py} | 0 ticketfrei/tests/webapptests/test_logout.py | 0 .../tests/webapptests/test_mailhandling.py | 0 ...pplicationRegister.py => test_register.py} | 0 ticketfrei/tests/webapptests/test_settings.py | 0 ticketfrei/tests/webapptests/test_statics.py | 0 16 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 setup.cfg rename ticketfrei/tests/webapptests/{WebApplicationLogin.py => test_login.py} (100%) create mode 100644 ticketfrei/tests/webapptests/test_logout.py create mode 100644 ticketfrei/tests/webapptests/test_mailhandling.py rename ticketfrei/tests/webapptests/{WebApplicationRegister.py => test_register.py} (100%) create mode 100644 ticketfrei/tests/webapptests/test_settings.py create mode 100644 ticketfrei/tests/webapptests/test_statics.py diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..b7e4789 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[aliases] +test=pytest diff --git a/setup.py b/setup.py index 0868531..483bef3 100644 --- a/setup.py +++ b/setup.py @@ -1,20 +1,37 @@ from setuptools import setup +import sys +import os + +PACKAGE_NAME = "ticketfrei" + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), PACKAGE_NAME)) setup( - name='ticketfrei', + name=PACKAGE_NAME, version='', - packages=['ticketfrei'], + packages=[ + PACKAGE_NAME + ], url='https://github.com/ticketfrei/ticketfrei', license='ISC', author='', author_email='', description='', + setup_requires=[ + 'pytest-runner', + ], install_requires=[ 'bottle', - 'jwt', - 'mastodon.py', + 'gitpython', + 'pyjwt', + 'Markdown', + 'Mastodon.py', 'pylibscrypt', 'pytoml', 'tweepy', + 'twx', + ], + tests_require=[ + 'pytest', ], ) diff --git a/ticketfrei/config.py b/ticketfrei/config.py index ce381aa..c99ca92 100755 --- a/ticketfrei/config.py +++ b/ticketfrei/config.py @@ -1,6 +1,9 @@ import pytoml as toml import os +ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) +TEMPLATE_DIR = os.path.join(ROOT_DIR, 'template', '') +STATIC_DIR = os.path.join(ROOT_DIR, 'static', '') def load_env(): """ @@ -9,7 +12,7 @@ def load_env(): :return: config dictionary of dictionaries. """ - with open('config.toml.example') as defaultconf: + with open(os.path.join(ROOT_DIR, 'config.toml.example')) as defaultconf: configdict = toml.load(defaultconf) try: @@ -71,7 +74,7 @@ def load_env(): # read config in TOML format (https://github.com/toml-lang/toml#toml) try: - with open('config.toml') as configfile: + with open(os.path.join(ROOT_DIR, 'config.toml')) as configfile: config = toml.load(configfile) except FileNotFoundError: config = load_env() diff --git a/ticketfrei/frontend.py b/ticketfrei/frontend.py index 5611796..b0a4d14 100755 --- a/ticketfrei/frontend.py +++ b/ticketfrei/frontend.py @@ -2,7 +2,7 @@ import bottle from os import listdir, path from bottle import get, post, redirect, request, response, view -from config import config +from config import config, STATIC_DIR, TEMPLATE_DIR from db import db import logging import tweepy @@ -19,13 +19,13 @@ def url(route): @get('/') -@view('template/propaganda.tpl') +@view('propaganda.tpl') def propaganda(): pass @post('/register') -@view('template/register.tpl') +@view('register.tpl') def register_post(): try: email = request.forms['email'] @@ -55,7 +55,7 @@ def register_post(): @get('/confirm//') -@view('template/propaganda.tpl') +@view('propaganda.tpl') def confirm(city, token): # check whether city already exists if db.by_city(city): @@ -76,7 +76,7 @@ def version(): @post('/login') -@view('template/login.tpl') +@view('login.tpl') def login_post(): # check login try: @@ -102,7 +102,7 @@ def city_page(city, info=None): @get('/city/mail/') -@view('template/mail.tpl') +@view('mail.tpl') def display_mail_page(city): user = db.by_city(city) return user.state() @@ -139,34 +139,34 @@ def unsubscribe(token): @get('/settings') -@view('template/settings.tpl') +@view('settings.tpl') def settings(user): return user.state() @post('/settings/markdown') -@view('template/settings.tpl') +@view('settings.tpl') def update_markdown(user): user.set_markdown(request.forms['markdown']) return user.state() @post('/settings/mail_md') -@view('template/settings.tpl') +@view('settings.tpl') def update_mail_md(user): user.set_mail_md(request.forms['mail_md']) return user.state() @post('/settings/goodlist') -@view('template/settings.tpl') +@view('settings.tpl') def update_trigger_patterns(user): user.set_trigger_words(request.forms['goodlist']) return user.state() @post('/settings/blocklist') -@view('template/settings.tpl') +@view('settings.tpl') def update_badwords(user): user.set_badwords(request.forms['blocklist']) return user.state() @@ -187,12 +187,12 @@ def register_telegram(user): @get('/static/') def static(filename): - return bottle.static_file(filename, root='static') + return bottle.static_file(filename, root=STATIC_DIR) - -@get('/guides/') -def guides(filename): - return bottle.static_file(filename, root='guides') +# IS THIS USED? +#@get('/guides/') +#def guides(filename): +# return bottle.static_file(filename, root='guides') @get('/logout/') @@ -269,6 +269,8 @@ fh = logging.FileHandler(config['log']['log_frontend']) fh.setLevel(logging.DEBUG) logger.addHandler(fh) +# TODO change TEMPLATE_PATH to BOTS_DIR after refactoring +bottle.TEMPLATE_PATH.insert(0, TEMPLATE_DIR) application = bottle.default_app() bottle.install(SessionPlugin('/')) diff --git a/ticketfrei/template/city.tpl b/ticketfrei/template/city.tpl index 5613168..feba2ae 100644 --- a/ticketfrei/template/city.tpl +++ b/ticketfrei/template/city.tpl @@ -1,4 +1,4 @@ -% rebase('template/wrapper.tpl') +% rebase('wrapper.tpl') <% import markdown as md diff --git a/ticketfrei/template/login.tpl b/ticketfrei/template/login.tpl index 6d1e3d9..bbb5406 100644 --- a/ticketfrei/template/login.tpl +++ b/ticketfrei/template/login.tpl @@ -1,2 +1,2 @@ -% rebase('template/wrapper.tpl', title='Login') -% include('template/login-plain.tpl') +% rebase('wrapper.tpl', title='Login') +% include('login-plain.tpl') diff --git a/ticketfrei/template/mail.tpl b/ticketfrei/template/mail.tpl index 58b58e9..77f81a4 100644 --- a/ticketfrei/template/mail.tpl +++ b/ticketfrei/template/mail.tpl @@ -1,4 +1,4 @@ -% rebase('template/wrapper.tpl') +% rebase('wrapper.tpl') <% import markdown as md diff --git a/ticketfrei/template/propaganda.tpl b/ticketfrei/template/propaganda.tpl index d8e013f..20f8244 100644 --- a/ticketfrei/template/propaganda.tpl +++ b/ticketfrei/template/propaganda.tpl @@ -1,4 +1,4 @@ -% rebase('template/wrapper.tpl') +% rebase('wrapper.tpl') % if defined('info'):
@@ -7,7 +7,7 @@

% end -% include('template/login-plain.tpl') +% include('login-plain.tpl')

Features

Don't pay for public transport. Instead, warn each other @@ -45,7 +45,7 @@ share it with us, so others can use it, too! -% include('template/register-plain.tpl') +% include('register-plain.tpl')

Our Mission

Public transportation is meant to provide an easy and diff --git a/ticketfrei/template/register.tpl b/ticketfrei/template/register.tpl index 43b9c08..24ff577 100644 --- a/ticketfrei/template/register.tpl +++ b/ticketfrei/template/register.tpl @@ -1,4 +1,4 @@ -% rebase('template/wrapper.tpl', title='Register') +% rebase('wrapper.tpl', title='Register') % if defined('info'):

@@ -6,5 +6,5 @@
% else: -% include('template/register-plain.tpl') +% include('register-plain.tpl') % end diff --git a/ticketfrei/template/settings.tpl b/ticketfrei/template/settings.tpl index 49baacd..2587491 100644 --- a/ticketfrei/template/settings.tpl +++ b/ticketfrei/template/settings.tpl @@ -1,4 +1,4 @@ -% rebase('template/wrapper.tpl') +% rebase('wrapper.tpl') % if enabled: diff --git a/ticketfrei/tests/webapptests/WebApplicationLogin.py b/ticketfrei/tests/webapptests/test_login.py similarity index 100% rename from ticketfrei/tests/webapptests/WebApplicationLogin.py rename to ticketfrei/tests/webapptests/test_login.py diff --git a/ticketfrei/tests/webapptests/test_logout.py b/ticketfrei/tests/webapptests/test_logout.py new file mode 100644 index 0000000..e69de29 diff --git a/ticketfrei/tests/webapptests/test_mailhandling.py b/ticketfrei/tests/webapptests/test_mailhandling.py new file mode 100644 index 0000000..e69de29 diff --git a/ticketfrei/tests/webapptests/WebApplicationRegister.py b/ticketfrei/tests/webapptests/test_register.py similarity index 100% rename from ticketfrei/tests/webapptests/WebApplicationRegister.py rename to ticketfrei/tests/webapptests/test_register.py diff --git a/ticketfrei/tests/webapptests/test_settings.py b/ticketfrei/tests/webapptests/test_settings.py new file mode 100644 index 0000000..e69de29 diff --git a/ticketfrei/tests/webapptests/test_statics.py b/ticketfrei/tests/webapptests/test_statics.py new file mode 100644 index 0000000..e69de29