mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-14 07:39:03 +00:00
Refactor into an app factory [2 of 2] (#322)
* Replace all `from nyaa import app` imports with `app = flask.current_app` (or `from flask import current_app as app` where possible) * Add a separate config object for top-level and class statements as `nyaa.extensions.config` Required because those codes don't have app context at the time of evaluation/execution. * Remove `routes.py` file and register all blueprints in `nyaa/__init__.py` * Refactor `nyaa/__init__.py` into an app factory * Update tools * Update tests (temporary, will be replaced)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from nyaa import app
|
||||
from nyaa import create_app
|
||||
|
||||
USE_MYSQL = True
|
||||
|
||||
@@ -12,6 +12,7 @@ class NyaaTestCase(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
app = create_app('config')
|
||||
app.config['TESTING'] = True
|
||||
cls.app_context = app.app_context()
|
||||
|
||||
|
||||
@@ -6,16 +6,18 @@ import nyaa
|
||||
|
||||
class NyaaTestCase(unittest.TestCase):
|
||||
|
||||
nyaa_app = nyaa.create_app('config')
|
||||
|
||||
def setUp(self):
|
||||
self.db, nyaa.app.config['DATABASE'] = tempfile.mkstemp()
|
||||
nyaa.app.config['TESTING'] = True
|
||||
self.app = nyaa.app.test_client()
|
||||
with nyaa.app.app_context():
|
||||
self.db, self.nyaa_app.config['DATABASE'] = tempfile.mkstemp()
|
||||
self.nyaa_app.config['TESTING'] = True
|
||||
self.app = self.nyaa_app.test_client()
|
||||
with self.nyaa_app.app_context():
|
||||
nyaa.db.create_all()
|
||||
|
||||
def tearDown(self):
|
||||
os.close(self.db)
|
||||
os.unlink(nyaa.app.config['DATABASE'])
|
||||
os.unlink(self.nyaa_app.config['DATABASE'])
|
||||
|
||||
def test_index_url(self):
|
||||
rv = self.app.get('/')
|
||||
|
||||
Reference in New Issue
Block a user