From 668157c552d537d09bcea7c7124ec97334d57372 Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Mon, 4 Mar 2019 12:50:20 +0100 Subject: [PATCH 01/11] Remove hardcoded paths for logs and frontend host. Add log path option to sample config.toml file. --- config.py | 6 ++++++ config.toml.example | 3 +++ frontend.py | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index bc7baaf..02ef632 100755 --- a/config.py +++ b/config.py @@ -54,6 +54,12 @@ def load_env(): except KeyError: pass + try: + if os.environ['LOG_PATH'] != "": + configdict['log']['log_path'] = os.environ['LOG_PATH'] + except KeyError: + pass + return configdict diff --git a/config.toml.example b/config.toml.example index eb519db..35c6316 100644 --- a/config.toml.example +++ b/config.toml.example @@ -14,3 +14,6 @@ mbox_user = "root" [database] db_path = "/var/ticketfrei/db.sqlite" + +[log] +log_path = "/var/ticketfrei/error.log" diff --git a/frontend.py b/frontend.py index 38354a6..7d7a539 100755 --- a/frontend.py +++ b/frontend.py @@ -265,7 +265,7 @@ def login_mastodon(user): logger = logging.getLogger() -fh = logging.FileHandler('/var/log/ticketfrei/error.log') +fh = logging.FileHandler(config['log']['log_path']) fh.setLevel(logging.DEBUG) logger.addHandler(fh) @@ -273,6 +273,6 @@ application = bottle.default_app() bottle.install(SessionPlugin('/')) if __name__ == '__main__': - bottle.run(host="0.0.0.0", port=config["web"]["port"]) + bottle.run(host=config["web"]["host"], port=config["web"]["port"]) else: application.catchall = False From 5535d3535f5460ee99f555829adb611548a98996 Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Mon, 4 Mar 2019 14:39:09 +0100 Subject: [PATCH 02/11] Split log into frontend and backend log. --- backend.py | 2 +- config.py | 10 ++++++++-- config.toml.example | 3 ++- frontend.py | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/backend.py b/backend.py index fd18aee..0286f77 100755 --- a/backend.py +++ b/backend.py @@ -17,7 +17,7 @@ def shutdown(): if __name__ == '__main__': logger = logging.getLogger() - fh = logging.FileHandler('/var/log/ticketfrei/backend.log') + fh = logging.FileHandler(config["log"]["log_backend"]) fh.setLevel(logging.DEBUG) logger.addHandler(fh) diff --git a/config.py b/config.py index 02ef632..ce381aa 100755 --- a/config.py +++ b/config.py @@ -55,8 +55,14 @@ def load_env(): pass try: - if os.environ['LOG_PATH'] != "": - configdict['log']['log_path'] = os.environ['LOG_PATH'] + if os.environ['LOG_FRONTEND'] != "": + configdict['log']['log_frontend'] = os.environ['LOG_FRONTEND'] + except KeyError: + pass + + try: + if os.environ['LOG_BACKEND'] != "": + configdict['log']['log_backend'] = os.environ['LOG_BACKEND'] except KeyError: pass diff --git a/config.toml.example b/config.toml.example index 35c6316..ff54708 100644 --- a/config.toml.example +++ b/config.toml.example @@ -16,4 +16,5 @@ mbox_user = "root" db_path = "/var/ticketfrei/db.sqlite" [log] -log_path = "/var/ticketfrei/error.log" +log_frontend = "/var/ticketfrei/frontend.log" +log_backend = "/var/log/ticketfrei/backend.log" diff --git a/frontend.py b/frontend.py index 7d7a539..5611796 100755 --- a/frontend.py +++ b/frontend.py @@ -265,7 +265,7 @@ def login_mastodon(user): logger = logging.getLogger() -fh = logging.FileHandler(config['log']['log_path']) +fh = logging.FileHandler(config['log']['log_frontend']) fh.setLevel(logging.DEBUG) logger.addHandler(fh) From fa3dda1c6044b4a5bfe35c09f1f9ff6127e26f7f Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Mon, 4 Mar 2019 15:16:21 +0100 Subject: [PATCH 03/11] Remove duplicate entry from gitignore and add entries for egg-info. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c20e862..1416186 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.swp *.pyc +*.egg-info/ .idea/ __pycache__/ last_mention @@ -17,4 +18,3 @@ include/ lib/ share/ local/ -venv/ From 050e641bb0dd8820b758efaeb348bbd35b49f251 Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Mon, 4 Mar 2019 18:49:12 +0100 Subject: [PATCH 04/11] Add initial tests for Web Interface. --- tests/WebApplicationTest.py | 26 ++++++++++++ tests/db.sqlite | Bin 0 -> 180224 bytes tests/errors.log | 77 ++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 tests/WebApplicationTest.py create mode 100644 tests/db.sqlite create mode 100644 tests/errors.log diff --git a/tests/WebApplicationTest.py b/tests/WebApplicationTest.py new file mode 100644 index 0000000..cc48076 --- /dev/null +++ b/tests/WebApplicationTest.py @@ -0,0 +1,26 @@ +from webtest import TestApp +import unittest +from ticketfrei import frontend + +class TestLogin(unittest.TestCase): + + def test_login_not_registered(self): + app = TestApp(frontend.application) + request = app.post('/login', {'email': 'foo@abc.de', 'pass': 'bar'}, expect_errors=True) + self.assertEqual(request.status_code, 401) + +class TestRegister(unittest.TestCase): + + def test_register(self): + app = TestApp(frontend.application) + request = app.post('/register', {'email': 'foo@abc.de', 'pass': 'bar', 'pass-repeat': 'bar', 'city': 'testcity'}, expect_errors=True) + self.assertEqual(request.status_code, 201) + + def test_getRoot(self): + app = TestApp(frontend.application) + request = app.get('/') + self.assertEqual(request.status_code, 200) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/db.sqlite b/tests/db.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..8e9d3f273ff4b477f13a9ed97b12ffbcf820f5f4 GIT binary patch literal 180224 zcmeI(%}*QY9l&u9FXI3)Bms6pvMj@r7hFhLZ-kUIT5Sn62rV%SF>Rx*WEq&U(}11z z45izuTCHJo>Oas+)l1cT&plOY4?VQ%rT;?JOVwMe_R@JZe(;RLAWt=xzK+25GtWGJ z{P{ie%=1E?Z?5a6rhdO#J1m>(!_>8uB&EKos;N|J)cTpXe*B01zR!PSJxfim!(NW2 zzW&}f`t8gk|F!ena-YJola2ra2q1s}0tg_000IagfB*uW7nm5!*o9u}e94rE00Iag zfB*srAb^7*Ht^0R#|0 z009ILKmY**5I_KdgbA?!pRj;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mrJVC5f7~nEjq`=mHofVi zVUOmmyUe+_eS+h;gR_Ur)A^Q z@Rq7o?8&4%_4CI`-^#BnZLb&AoYy2a>aY_geGbEB4$sllntyJoWR` zkUa34f$Ei;1CQj#>A&^e?f+;0uY3N|`;Xzj_xvKG4gWIrr_7_w(ADo*SyRrBeR7wI1%f!sH?2%eNUz;{!LDxVn&JMQ6+-K##UETp{Eahg z-Td6U34{!(4$HNdd)4DgcpI@hlG35uMuM+W=hj&|&?_&)25$DG*2@r5kBj!1tphT5 z3BsS#&#P7dKF_Kf1$B9&u(H0kTvV-Tzcu+6n{)16S;e)#om%va&W4=Go+6kF*+aGxaatPAiLx z(pS^&=)hmEGmdtQ-I~6m)r`g(UQ^nXpd6GVA>3zmb|>ATvzE@af8itFd?Bp9BP*XQ zh6OH&w)B2b>h$Vl#TcMwwG%54&8MC>v>X$y|X%CrM8c^e{bv1 zil*14h6dAL!)r|5+RaxFt%+}W- zS@xInv(9L|{?O|~?6JB#VxJS*q_?pU`+k@AIZhAybbaHg*a+tCx0`XeGltUp?(^5? z?p+{r&dr>yKbmpIPu{Az-(4SA%fcmZizO)So`4jTBO%xBUfJ|E_By^xv3jTNc*VOi zn@lv>RogG_2-=P0gb>>`EP2k>rtx~~4C`|DG5-I5 zS9Yyb8UX|lKmY**5I_I{1Q0*~fk*=U|Nlr_WJUl11Q0*~0R#|0009ILK%grH*#Ga! zuu*9Q5I_I{1Q0*~0R#|0009Id39$bkiHpn#AbvLKmY**5I_I{1Q0*~0R*~Ifc^ij3>%e3009ILKmY** z5I_I{1Q0+Vk^uYvk+{f=00IagfB*srAbHI-<4sb(g+}c00IagfB*sr zAb Date: Mon, 4 Mar 2019 19:04:18 +0100 Subject: [PATCH 05/11] Cleaning and refactor file structure to work as pip package. --- tests/db.sqlite | Bin 180224 -> 0 bytes tests/errors.log | 77 ------------------ .../active_bots}/__init__.py | 0 .../active_bots}/mailbot.py | 0 .../active_bots}/mastodonbot.py | 0 .../active_bots}/telegrambot.py | 0 .../active_bots}/twitterDMs.py | 0 .../active_bots}/twitterbot.py | 0 backend.py => ticketfrei/backend.py | 0 bot.py => ticketfrei/bot.py | 0 {bots => ticketfrei/bots}/mail/settings.tpl | 0 .../bots}/mastodon/settings.tpl | 0 .../bots}/telegram/settings.tpl | 0 .../bots}/twitter/settings.tpl | 0 .../bots}/twitterDMs/settings.tpl | 0 config.py => ticketfrei/config.py | 0 .../config.toml.example | 0 db.py => ticketfrei/db.py | 0 frontend.py => ticketfrei/frontend.py | 0 report.py => ticketfrei/report.py | 0 sendmail.py => ticketfrei/sendmail.py | 0 session.py => ticketfrei/session.py | 0 {static => ticketfrei/static}/bot.html | 0 {static => ticketfrei/static}/css/style.css | 0 .../static}/img/ticketfrei-og-image.jpg | Bin .../static}/img/ticketfrei_logo.png | Bin {static => ticketfrei/static}/index.html | 0 .../static}/jquery-ui-1.12.1/AUTHORS.txt | 0 .../static}/jquery-ui-1.12.1/LICENSE.txt | 0 .../external/jquery/jquery.js | 0 .../images/ui-icons_444444_256x240.png | Bin .../images/ui-icons_555555_256x240.png | Bin .../images/ui-icons_777620_256x240.png | Bin .../images/ui-icons_777777_256x240.png | Bin .../images/ui-icons_cc0000_256x240.png | Bin .../images/ui-icons_ffffff_256x240.png | Bin .../static}/jquery-ui-1.12.1/index.html | 0 .../static}/jquery-ui-1.12.1/jquery-ui.css | 0 .../static}/jquery-ui-1.12.1/jquery-ui.js | 0 .../jquery-ui-1.12.1/jquery-ui.min.css | 0 .../static}/jquery-ui-1.12.1/jquery-ui.min.js | 0 .../jquery-ui-1.12.1/jquery-ui.structure.css | 0 .../jquery-ui.structure.min.css | 0 .../jquery-ui-1.12.1/jquery-ui.theme.css | 0 .../jquery-ui-1.12.1/jquery-ui.theme.min.css | 0 .../static}/jquery-ui-1.12.1/package.json | 0 {static => ticketfrei/static}/js/functions.js | 0 .../static}/js/jquery-3.3.1.min.js | 0 {static => ticketfrei/static}/register.html | 0 {template => ticketfrei/template}/city.tpl | 0 .../template}/login-plain.tpl | 0 {template => ticketfrei/template}/login.tpl | 0 {template => ticketfrei/template}/mail.tpl | 0 .../template}/propaganda.tpl | 0 .../template}/register-plain.tpl | 0 .../template}/register.tpl | 0 .../template}/settings.tpl | 0 {template => ticketfrei/template}/wrapper.tpl | 0 user.py => ticketfrei/user.py | 0 wsgi.py => ticketfrei/wsgi.py | 0 60 files changed, 77 deletions(-) delete mode 100644 tests/db.sqlite delete mode 100644 tests/errors.log rename {active_bots => ticketfrei/active_bots}/__init__.py (100%) rename {active_bots => ticketfrei/active_bots}/mailbot.py (100%) rename {active_bots => ticketfrei/active_bots}/mastodonbot.py (100%) rename {active_bots => ticketfrei/active_bots}/telegrambot.py (100%) rename {active_bots => ticketfrei/active_bots}/twitterDMs.py (100%) rename {active_bots => ticketfrei/active_bots}/twitterbot.py (100%) rename backend.py => ticketfrei/backend.py (100%) rename bot.py => ticketfrei/bot.py (100%) rename {bots => ticketfrei/bots}/mail/settings.tpl (100%) rename {bots => ticketfrei/bots}/mastodon/settings.tpl (100%) rename {bots => ticketfrei/bots}/telegram/settings.tpl (100%) rename {bots => ticketfrei/bots}/twitter/settings.tpl (100%) rename {bots => ticketfrei/bots}/twitterDMs/settings.tpl (100%) rename config.py => ticketfrei/config.py (100%) rename config.toml.example => ticketfrei/config.toml.example (100%) rename db.py => ticketfrei/db.py (100%) rename frontend.py => ticketfrei/frontend.py (100%) rename report.py => ticketfrei/report.py (100%) rename sendmail.py => ticketfrei/sendmail.py (100%) rename session.py => ticketfrei/session.py (100%) rename {static => ticketfrei/static}/bot.html (100%) rename {static => ticketfrei/static}/css/style.css (100%) rename {static => ticketfrei/static}/img/ticketfrei-og-image.jpg (100%) rename {static => ticketfrei/static}/img/ticketfrei_logo.png (100%) rename {static => ticketfrei/static}/index.html (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/AUTHORS.txt (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/LICENSE.txt (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/external/jquery/jquery.js (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/images/ui-icons_444444_256x240.png (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/images/ui-icons_555555_256x240.png (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/images/ui-icons_777620_256x240.png (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/images/ui-icons_777777_256x240.png (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/images/ui-icons_cc0000_256x240.png (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/images/ui-icons_ffffff_256x240.png (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/index.html (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/jquery-ui.css (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/jquery-ui.js (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/jquery-ui.min.css (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/jquery-ui.min.js (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/jquery-ui.structure.css (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/jquery-ui.structure.min.css (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/jquery-ui.theme.css (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/jquery-ui.theme.min.css (100%) rename {static => ticketfrei/static}/jquery-ui-1.12.1/package.json (100%) rename {static => ticketfrei/static}/js/functions.js (100%) rename {static => ticketfrei/static}/js/jquery-3.3.1.min.js (100%) rename {static => ticketfrei/static}/register.html (100%) rename {template => ticketfrei/template}/city.tpl (100%) rename {template => ticketfrei/template}/login-plain.tpl (100%) rename {template => ticketfrei/template}/login.tpl (100%) rename {template => ticketfrei/template}/mail.tpl (100%) rename {template => ticketfrei/template}/propaganda.tpl (100%) rename {template => ticketfrei/template}/register-plain.tpl (100%) rename {template => ticketfrei/template}/register.tpl (100%) rename {template => ticketfrei/template}/settings.tpl (100%) rename {template => ticketfrei/template}/wrapper.tpl (100%) rename user.py => ticketfrei/user.py (100%) rename wsgi.py => ticketfrei/wsgi.py (100%) diff --git a/tests/db.sqlite b/tests/db.sqlite deleted file mode 100644 index 8e9d3f273ff4b477f13a9ed97b12ffbcf820f5f4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 180224 zcmeI(%}*QY9l&u9FXI3)Bms6pvMj@r7hFhLZ-kUIT5Sn62rV%SF>Rx*WEq&U(}11z z45izuTCHJo>Oas+)l1cT&plOY4?VQ%rT;?JOVwMe_R@JZe(;RLAWt=xzK+25GtWGJ z{P{ie%=1E?Z?5a6rhdO#J1m>(!_>8uB&EKos;N|J)cTpXe*B01zR!PSJxfim!(NW2 zzW&}f`t8gk|F!ena-YJola2ra2q1s}0tg_000IagfB*uW7nm5!*o9u}e94rE00Iag zfB*srAb^7*Ht^0R#|0 z009ILKmY**5I_KdgbA?!pRj;X9Rv_S009ILKmY**5I_I{1Y!_i|33y)ibMbb1Q0*~ z0R#|0009ILKpz^+5I_I{1Q0*~0R#|0AO->U|6@R(53kcOg009ILKmY**5I_I{1Q0+V1_Ac}V?d=y1Q0*~0R#|0009ILKmY**5+=a@ zf5HMnbr3)R0R#|0009ILKmY**5Qss5{r?zHDG~t$5I_I{1Q0*~0R#|00D*)Fu>YU1 zfKVL-5I_I{1Q0*~0R#|0009JI5Mcj522_ef009ILKmY**5I_I{1Q0+VVFH6Jb0N5*Fdx~Y}QM`qP|Uoy1=ZNFANER}b6t49^nDCNwEA7Ev-YWlP2 zXLa_Bx;d6s9z2k~x^0$s4m9&vH%+b9_+IDVk1ucKmx_6{xb$>Aubw}u&JL>Q9{S!{ z!dju2U(Ii+g^i+G*j`^(Ki*n(xt*VHDelOy zD(98y71x?+_dwSwrkkyp|86lfhoSA(G}EeJaIW&MssB)O>mT}ID;rz+wbg?C9cI1S zW!0_xN`5O}Sk6CJ?X+2aFDrbN>_?-rQhFTPyu2vXw9k$-!z`KAms-VcV}a>o^&i|w zD~}&br&S?_;@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IPu{Az-(4SA%fcmZizO)So`4jTBO%xBUfJ|E_By^xv3jTNc*VOi zn@lv>RogG_2-=P0gb>>`EP2k>rtx~~4C`|DG5-I5 zS9Yyb8UX|lKmY**5I_I{1Q0*~fk*=U|Nlr_WJUl11Q0*~0R#|0009ILK%grH*#Ga! zuu*9Q5I_I{1Q0*~0R#|0009Id39$bkiHpn#AbvLKmY**5I_I{1Q0*~0R*~Ifc^ij3>%e3009ILKmY** z5I_I{1Q0+Vk^uYvk+{f=00IagfB*srAbHI-<4sb(g+}c00IagfB*sr zAb Date: Mon, 4 Mar 2019 19:49:29 +0100 Subject: [PATCH 06/11] Fix reverse assertion in Tests. --- {tests => ticketfrei/tests}/WebApplicationTest.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename {tests => ticketfrei/tests}/WebApplicationTest.py (67%) diff --git a/tests/WebApplicationTest.py b/ticketfrei/tests/WebApplicationTest.py similarity index 67% rename from tests/WebApplicationTest.py rename to ticketfrei/tests/WebApplicationTest.py index cc48076..04517ed 100644 --- a/tests/WebApplicationTest.py +++ b/ticketfrei/tests/WebApplicationTest.py @@ -1,25 +1,25 @@ from webtest import TestApp import unittest -from ticketfrei import frontend +import frontend class TestLogin(unittest.TestCase): def test_login_not_registered(self): app = TestApp(frontend.application) - request = app.post('/login', {'email': 'foo@abc.de', 'pass': 'bar'}, expect_errors=True) - self.assertEqual(request.status_code, 401) + request = app.post('/login', {'email': '', 'pass': ''}, expect_errors=True) + self.assertEqual(401, request.status_code) class TestRegister(unittest.TestCase): def test_register(self): app = TestApp(frontend.application) request = app.post('/register', {'email': 'foo@abc.de', 'pass': 'bar', 'pass-repeat': 'bar', 'city': 'testcity'}, expect_errors=True) - self.assertEqual(request.status_code, 201) + self.assertEqual(200, request.status_code) def test_getRoot(self): app = TestApp(frontend.application) request = app.get('/') - self.assertEqual(request.status_code, 200) + self.assertEqual(200, request.status_code) if __name__ == '__main__': From eabc43cdba8f5e641d8462921aa027072dd945ba Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Mon, 4 Mar 2019 19:50:00 +0100 Subject: [PATCH 07/11] Add setup.py file for pip module. --- setup.py | 20 ++++++++++++++++++++ ticketfrei/__init__.py | 0 2 files changed, 20 insertions(+) create mode 100644 setup.py create mode 100644 ticketfrei/__init__.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0868531 --- /dev/null +++ b/setup.py @@ -0,0 +1,20 @@ +from setuptools import setup + +setup( + name='ticketfrei', + version='', + packages=['ticketfrei'], + url='https://github.com/ticketfrei/ticketfrei', + license='ISC', + author='', + author_email='', + description='', + install_requires=[ + 'bottle', + 'jwt', + 'mastodon.py', + 'pylibscrypt', + 'pytoml', + 'tweepy', + ], +) diff --git a/ticketfrei/__init__.py b/ticketfrei/__init__.py new file mode 100644 index 0000000..e69de29 From f5f741a5c228894c4f2412da3140fb3c20a98c75 Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Mon, 4 Mar 2019 22:46:42 +0100 Subject: [PATCH 08/11] Add more test stubs for frontend. --- .../tests/configs/webapptestconfig.toml | 20 ++++++++++++++++ .../WebApplicationLogin.py} | 23 ++++++++----------- .../webapptests/WebApplicationRegister.py | 16 +++++++++++++ 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 ticketfrei/tests/configs/webapptestconfig.toml rename ticketfrei/tests/{WebApplicationTest.py => webapptests/WebApplicationLogin.py} (56%) create mode 100644 ticketfrei/tests/webapptests/WebApplicationRegister.py diff --git a/ticketfrei/tests/configs/webapptestconfig.toml b/ticketfrei/tests/configs/webapptestconfig.toml new file mode 100644 index 0000000..ff54708 --- /dev/null +++ b/ticketfrei/tests/configs/webapptestconfig.toml @@ -0,0 +1,20 @@ +[twitter] +# You get those keys when you follow these steps: +# https://developer.twitter.com/en/docs/basics/authentication/guides/access-tokens +consumer_key = "your_consumer_key" +consumer_secret = "your_consumer_secret" + +[web] +host = "0.0.0.0" # will be used by bottle as a host. +port = 80 +contact = "b3yond@riseup.net" + +[mail] +mbox_user = "root" + +[database] +db_path = "/var/ticketfrei/db.sqlite" + +[log] +log_frontend = "/var/ticketfrei/frontend.log" +log_backend = "/var/log/ticketfrei/backend.log" diff --git a/ticketfrei/tests/WebApplicationTest.py b/ticketfrei/tests/webapptests/WebApplicationLogin.py similarity index 56% rename from ticketfrei/tests/WebApplicationTest.py rename to ticketfrei/tests/webapptests/WebApplicationLogin.py index 04517ed..3f9117f 100644 --- a/ticketfrei/tests/WebApplicationTest.py +++ b/ticketfrei/tests/webapptests/WebApplicationLogin.py @@ -2,25 +2,22 @@ from webtest import TestApp import unittest import frontend +app = TestApp(frontend.application) + class TestLogin(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + def test_login_not_registered(self): - app = TestApp(frontend.application) request = app.post('/login', {'email': '', 'pass': ''}, expect_errors=True) self.assertEqual(401, request.status_code) -class TestRegister(unittest.TestCase): - - def test_register(self): - app = TestApp(frontend.application) + def test_login_registered(self): request = app.post('/register', {'email': 'foo@abc.de', 'pass': 'bar', 'pass-repeat': 'bar', 'city': 'testcity'}, expect_errors=True) + request = app.post('/login', {'email': 'foor@abc.de', 'pass': 'bar'}, expect_errors=False) self.assertEqual(200, request.status_code) - def test_getRoot(self): - app = TestApp(frontend.application) - request = app.get('/') - self.assertEqual(200, request.status_code) - - -if __name__ == '__main__': - unittest.main() diff --git a/ticketfrei/tests/webapptests/WebApplicationRegister.py b/ticketfrei/tests/webapptests/WebApplicationRegister.py new file mode 100644 index 0000000..bc88bb2 --- /dev/null +++ b/ticketfrei/tests/webapptests/WebApplicationRegister.py @@ -0,0 +1,16 @@ +from webtest import TestApp +import unittest +import frontend + +app = TestApp(frontend.application) + +class TestRegister(unittest.TestCase): + + def test_register(self): + request = app.post('/register', {'email': 'foo@abc.de', 'pass': 'bar', 'pass-repeat': 'bar', 'city': 'testcity'}, expect_errors=True) + self.assertEqual(200, request.status_code) + + def test_getRoot(self): + request = app.get('/') + self.assertEqual(200, request.status_code) + From 9906346691cbf47ee3fb91d61087b6769c7b6551 Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Wed, 6 Mar 2019 15:39:08 +0100 Subject: [PATCH 09/11] 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 From 768a4350bd7bc83271fa893e94c18689ee83e1eb Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Wed, 6 Mar 2019 15:40:15 +0100 Subject: [PATCH 10/11] Add .eggs to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1416186..7190950 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.swp *.pyc *.egg-info/ +*.eggs .idea/ __pycache__/ last_mention From 7ef8c3e197f9ab58446702171cf15b1338cd0c75 Mon Sep 17 00:00:00 2001 From: cookietime--yay Date: Wed, 6 Mar 2019 19:40:02 +0100 Subject: [PATCH 11/11] Fix more path issues and add aliases file path to config. --- ticketfrei/config.py | 1 + ticketfrei/config.toml.example | 1 + ticketfrei/db.py | 2 +- ticketfrei/frontend.py | 4 ++-- ticketfrei/template/settings.tpl | 5 +++-- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ticketfrei/config.py b/ticketfrei/config.py index c99ca92..9c20c3c 100755 --- a/ticketfrei/config.py +++ b/ticketfrei/config.py @@ -4,6 +4,7 @@ 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', '') +BOT_DIR = os.path.join(ROOT_DIR, 'bots') def load_env(): """ diff --git a/ticketfrei/config.toml.example b/ticketfrei/config.toml.example index ff54708..ee5282a 100644 --- a/ticketfrei/config.toml.example +++ b/ticketfrei/config.toml.example @@ -11,6 +11,7 @@ contact = "b3yond@riseup.net" [mail] mbox_user = "root" +aliases_path = "/etc/aliases" [database] db_path = "/var/ticketfrei/db.sqlite" diff --git a/ticketfrei/db.py b/ticketfrei/db.py index 61100ae..3b3acfb 100644 --- a/ticketfrei/db.py +++ b/ticketfrei/db.py @@ -243,7 +243,7 @@ u\d\d?""" (uid, "bastard")) else: uid = json['uid'] - with open("/etc/aliases", "a+") as f: + with open(config['mail']['aliases_path'], "a+") as f: f.write(city + ": " + config["mail"]["mbox_user"] + "\n") self.execute("INSERT INTO email (user_id, email) VALUES(?, ?);", (uid, json['email'])) diff --git a/ticketfrei/frontend.py b/ticketfrei/frontend.py index b0a4d14..52ee5e1 100755 --- a/ticketfrei/frontend.py +++ b/ticketfrei/frontend.py @@ -95,8 +95,8 @@ def city_page(city, info=None): citydict = db.user_facing_properties(city) if citydict is not None: citydict['info'] = info - return bottle.template('template/city.tpl', **citydict) - return bottle.template('template/propaganda.tpl', + return bottle.template('city.tpl', **citydict) + return bottle.template('propaganda.tpl', **dict(info='There is no Ticketfrei bot in your city' ' yet. Create one yourself!')) diff --git a/ticketfrei/template/settings.tpl b/ticketfrei/template/settings.tpl index 2587491..995ac24 100644 --- a/ticketfrei/template/settings.tpl +++ b/ticketfrei/template/settings.tpl @@ -9,11 +9,12 @@ <% # import all the settings templates from bots/*/settings.tpl +from config import BOT_DIR import os -bots = os.listdir('bots') +bots = os.listdir(BOT_DIR) for bot in bots: - include('bots/' + bot + '/settings.tpl', csrf=csrf, city=city) + include(os.path.join(BOT_DIR, bot, 'settings.tpl'), csrf=csrf, city=city) end %>