# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Massimiliano Torromeo < massimiliano DOT torromeo AT gmail DOT com >

_name=beaker
pkgname=python-beaker
pkgver=1.13.0
pkgrel=3
arch=(any)
license=('BSD-3-Clause')
pkgdesc="Caching and sessions WSGI middleware for use with web applications and stand-alone Python scripts and applications"
url="https://beaker.readthedocs.io/en/latest/"
depends=('python')
makedepends=('python-setuptools')
checkdepends=('python-pytest' 'python-sqlalchemy'
              'python-pycryptodome' 'python-coverage' 'python-webtest' 'python-redis'
              'python-pymongo' 'python-pylibmc' 'redis' 'python-cryptography'
              'python-memcached' 'memcached' 'pifpaf' 'python-mongomock')
source=(
  "$pkgname-$pkgver.tar.gz::https://github.com/bbangert/beaker/archive/$pkgver.tar.gz"
)
sha512sums=('474a619f2cff8bddc09cb030bb666b306316569ff4dc0f49700ea52c3bd9d95755b39f09034e4054c431eb46c294f8efb30e13c7ec1dd787047262cd481a352b')

prepare() {
  # Use a fake MongoDB for tests
  sed -e '/class TestMongoDB/i import mongomock' \
      -e "s|'mongodb://localhost:27017/beaker_testdb'|mongomock.MongoClient('mongodb://localhost:27017/beaker_testdb')|" \
      -i beaker-$pkgver/tests/test_managers/test_ext_mongodb.py

  # Drop tests which require a redis cluster
  rm beaker-$pkgver/tests/test_managers/test_ext_rediscluster.py

  sed -i "s#/usr/bin/python#/usr/bin/python3#" beaker-$pkgver/beaker/crypto/pbkdf2.py
}

build() {
  cd beaker-$pkgver
  python3 setup.py build
}

check() {
  cd beaker-$pkgver
  # it_IT.UTF-8 is missing in test env
  # test_dbm_container fails with SQLite objects created in a thread can only be used in that same thread.
  pifpaf run memcached --port 11211 -- pifpaf run redis -- \
    pytest --deselect tests/test_cookie_expires.py::test_cookie_expires_different_locale \
	   --deselect tests/test_container.py::test_dbm_container \
	   --deselect tests/test_container.py::test_dbm_container_2 \
           --deselect tests/test_container.py::test_dbm_container_3
}

package() {
  cd beaker-$pkgver
  python setup.py install --root="$pkgdir" --optimize=1
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/python-beaker/
}
