#169 improve testing
Merged 3 years ago by kparal. Opened 3 years ago by kparal.

file modified
+2 -2
@@ -55,7 +55,7 @@ 

  test: $(VENV)

  	set -e

  	source $(VENV)/bin/activate;

- 	TEST='true' py.test --cov-report=term-missing --cov $(MODULENAME);

+ 	pytest --cov-report=term-missing --cov $(MODULENAME);

  	deactivate

  

  .PHONY: test-ci
@@ -63,7 +63,7 @@ 

  test-ci: $(VENV)

  	set -e

  	source $(VENV)/bin/activate

- 	TEST='true' py.test --cov-report=xml --cov $(MODULENAME)

+ 	pytest --cov-report=xml --cov $(MODULENAME)

  	deactivate

  

  .PHONY: pylint

file modified
+33 -30
@@ -1,37 +1,46 @@ 

- from flask import Flask, render_template

- from flask_fas_openid import FAS

- from flask_sqlalchemy import SQLAlchemy

  import logging

  import logging.handlers

  import os

  

- from . import config

+ from flask import Flask, render_template

+ from flask_fas_openid import FAS

+ from flask_sqlalchemy import SQLAlchemy

  

+ from . import config

  from .util.login import FakeFas

  

  # the version as used in setup.py and docs

  __version__ = "1.1.0"

  

- 

  # Flask App

  app = Flask(__name__)

- 

  fas = None

- 

  # Is this an OpenShift deployment?

  openshift = os.getenv('OPENSHIFT_PROD')

  

+ # set up basic logging so that initial messages are not lost (until we

+ # configure logging properly)

+ _logging_fmt = '[%(name)-15s] %(asctime)s %(levelname)-7s %(message)s'

+ _logging_fmt_debug = '[%(name)-23s:%(lineno)-3d] %(asctime)s %(levelname)-7s %(message)s'

+ _logging_datefmt = '%Y-%m-%d %H:%M:%S'

+ logging.basicConfig(format=_logging_fmt_debug, datefmt=_logging_datefmt)

+ logging.getLogger().setLevel(logging.DEBUG)

+ 

  # load default configuration

  if os.getenv('DEV') == 'true':

+     app.logger.debug('Using development config')

      app.config.from_object('blockerbugs.config.DevelopmentConfig')

      fas = FakeFas(app)

  elif os.getenv('TEST') == 'true' or openshift == "0":

-     fas = FAS(app)

+     app.logger.debug('Using testing config')

      app.config.from_object('blockerbugs.config.TestingConfig')

- else:

      fas = FAS(app)

+ else:

+     app.logger.debug('Using production config')

      app.config.from_object('blockerbugs.config.ProductionConfig')

+     fas = FAS(app)

  if openshift:

+     app.logger.debug('Using openshift config')

      config.openshift_config(app.config, openshift)

  

  # load real configuration values to override defaults
@@ -54,31 +63,19 @@ 

  

  # Make sure config URLs end with a slash, so that we have them all in an

  # expected format

- def end_with_slash(url):

-     if not url.endswith('/'):

-         return url + '/'

-     else:

-         return url

- 

  for key in ['BUGZILLA_URL', 'KOJI_URL', 'BODHI_URL', 'FAS_BASE_URL',

-     'PAGURE_URL', 'PAGURE_API']:

-     app.config[key] = end_with_slash(app.config[key])

- 

- # "Hotfix" for proxy handling on current deployment, my guess is that the proxy

- # server is set differently than it was, but what do I know...

- if app.config["BEHIND_PROXY"]:

-     from werkzeug.contrib.fixers import ProxyFix

-     app.wsgi_app = ProxyFix(app.wsgi_app, num_proxies=1)

+             'PAGURE_URL', 'PAGURE_API']:

+     if not app.config[key].endswith('/'):

+         app.config[key] = app.config[key] + '/'

  

  

  def setup_logging():

-     fmt = '[%(filename)s:%(lineno)d] ' if app.debug else '%(module)-12s '

-     fmt += '%(asctime)s %(levelname)-7s %(message)s'

-     datefmt = '%Y-%m-%d %H:%M:%S'

+     formatter = logging.Formatter(

+         fmt=_logging_fmt_debug if app.debug else _logging_fmt,

+         datefmt=_logging_datefmt)

      loglevel = logging.DEBUG if app.debug else logging.INFO

-     formatter = logging.Formatter(fmt=fmt, datefmt=datefmt)

  

-     root_logger = logging.getLogger('')

+     root_logger = logging.getLogger()

      root_logger.setLevel(logging.DEBUG)

      root_logger.handlers.clear()

      app.logger.handlers.clear()
@@ -109,13 +106,19 @@ 

  

  setup_logging()

  

+ # database

  if app.config['SHOW_DB_URI']:

      app.logger.debug('using DBURI: %s' % app.config['SQLALCHEMY_DATABASE_URI'])

- 

- # database

  db = SQLAlchemy(app)

  

+ # "Hotfix" for proxy handling on current deployment, my guess is that the proxy

+ # server is set differently than it was, but what do I know...

+ if app.config["BEHIND_PROXY"]:

+     from werkzeug.contrib.fixers import ProxyFix

+     app.wsgi_app = ProxyFix(app.wsgi_app, num_proxies=1)

+ 

  

+ # === Flask views and stuff ===

  @app.template_filter('tagify')

  def tagify(value):

      return value.replace(' ', '')

file modified
+1
@@ -96,6 +96,7 @@ 

  

  class TestingConfig(Config):

      TESTING = True

+     SHOW_DB_URI = True

  

  

  def openshift_config(config_object, openshift_production):

file modified
+1 -5
@@ -131,8 +131,4 @@ 

  Unit tests have been written using `pytest <http://pytest.org/>`_ and can be

  run from the root project directory with::

  

-   TEST='true' py.test testing/

- 

- The ``TEST='true'`` part is rather important as some of the tests will wipe the

- database and fill it with less useful data. The ``TEST`` configuration forces

- the use of an in-memory SQLite3 database.

+   pytest

file modified
+1
@@ -2,3 +2,4 @@ 

  minversion = 2.0

  python_functions=test should

  python_files=test_* testfunc_*

+ testpaths = testing

file modified
+2 -30
@@ -1,5 +1,5 @@ 

  #

- # conftest.py - utils for py.test

+ # conftest.py - utils for pytest

  #

  # Copyright 2011, Red Hat, Inc.

  #
@@ -19,38 +19,10 @@ 

  #

  # Author: Tim Flink <tflink@redhat.com>

  

- import pytest

  import os

  

  

- def pytest_addoption(parser):

-     """

-     Add an option to the py.test parser to detect when the functional tests

-     should be detected and run

-     """

- 

-     parser.addoption('--functional', action='store_true', default=True,

-                      help='Add functional tests')

- 

- 

- def pytest_ignore_collect(path, config):

-     """Prevents collection of any files named testfunc* to speed up non

-         integration tests"""

-     if path.fnmatch('*testfunc*'):

-         try:

-             is_functional = config.getvalue('functional')

-         except KeyError:

-             return True

- 

-         return not is_functional

- 

- 

  def pytest_configure(config):

-     """This is a bit of a hack to detect whether or not we are running inside

-         a test environment"""

-     import sys

- 

-     sys._called_from_test = True

- 

+     """This is executed before testing starts"""

      # make sure that the testing config is used

      os.environ['TEST'] = 'true'

Please see individual commits for a description.

Build succeeded.

I forgot to add, the logging output has been changed a little, it's now more aligned and with better information, I think.

Commit d9a4321 fixes this pull-request

Pull-Request has been merged by kparal

3 years ago