Browse Source

cli and testing fixes

master
phryk 1 year ago
parent
commit
8bdf79f6cb
4 changed files with 25 additions and 2 deletions
  1. +1
    -1
      example.py
  2. +6
    -0
      poobrains/__init__.py
  3. +8
    -0
      poobrains/cli/__init__.py
  4. +10
    -1
      poobrains/testing.py

+ 1
- 1
example.py View File

@@ -117,4 +117,4 @@ def list_nonexposed(listing):
if __name__ == '__main__':

#app.run()
poobrains.app.cli()
poobrains.app.main()

+ 6
- 0
poobrains/__init__.py View File

@@ -222,6 +222,7 @@ class Poobrain(flask.Flask):
super(Poobrain, self).__init__(*args, **kwargs)

self.cronjobs = []

@click.group(cls=flask.cli.FlaskGroup, create_app=lambda x: self)
@click.option('--database', default="sqlite:///%s.db" % project_name)
def cli(database):
@@ -306,6 +307,11 @@ class Poobrain(flask.Flask):
self.site = Pooprint('site', 'site')
self.admin = Pooprint('admin', 'admin')

def main(self):
#self.cli(obj={})
self.cli()


def select_jinja_autoescape(self, filename):
if filename is None:


+ 8
- 0
poobrains/cli/__init__.py View File

@@ -225,6 +225,14 @@ def install(**options):
os.mkdir(type_dir, mode=0o770)


if isinstance(poobrains.app.db, peewee.SqliteDatabase):
prefix = 'sqlite:///'
else:
prefix = 'postgres://'

options['database'] = '%s%s' % (prefix, poobrains.app.db.database)


config = mkconfig('config', **options)
config_fd = open(os.path.join(app.root_path, 'config.py'), 'w')
config_fd.write(config)


+ 10
- 1
poobrains/testing.py View File

@@ -7,6 +7,7 @@ import random
import datetime

import OpenSSL
import peewee

import poobrains
from click.testing import CliRunner
@@ -516,7 +517,15 @@ def run_all():
pass

try:
os.unlink('%s.db' % poobrains.project_name)
if 'DATABASE' in poobrains.app.config and poobrains.app.config['DATABASE'].startswith('sqlite://'):
db_file = poobrains.app.config['DATABASE'].split('/')[-1]
os.unlink(db_name)
except:
pass

try:
if isinstance(poobrains.app.db, peewee.SqliteDatabase):
os.unlink(poobrains.app.db.database)
except:
pass



Loading…
Cancel
Save