# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=python-httpretty
pkgver=1.1.4
pkgrel=13
pkgdesc="HTTP client mock for Python"
arch=('any')
url="https://github.com/gabrielfalcao/httpretty"
license=('MIT')
depends=('python'
         'python-urllib3')
makedepends=('python-build'
             'python-installer'
             'python-wheel'
             'python-setuptools')
checkdepends=('openssl'
              'python-boto3'
              'python-cryptography'
              'python-eventlet'
              'python-freezegun'
              'python-httplib2'
              'python-httpx'
              'python-mccabe'
              'python-ndg-httpsclient'
              'python-pyopenssl'
              'python-pytest'
              'python-redis'
              'python-requests'
              'python-requests-toolbelt'
              'python-sure'
              'python-tornado')
source=("$url/archive/$pkgver/$pkgname-$pkgver.tar.gz"
        # https://github.com/gabrielfalcao/HTTPretty/pull/452
        "$pkgname-drop-mock.patch::$url/commit/9fd8e0bdd9e45041d15be1d8ee7983005d9f3199.patch"
        # https://github.com/gabrielfalcao/HTTPretty/pull/453
        "$pkgname-functional-tests-pytest-compatibility.patch::$url/commit/299d50c9cb0ba73343d1a88c202e17f6599fde54.patch"
        # https://github.com/gabrielfalcao/HTTPretty/pull/479
        "$pkgname-fix-failing-requests-tests.patch::$url/commit/929cc89c2afced0c42bd08e3b9440ab1f4ec22a8.patch"
        # https://github.com/gabrielfalcao/HTTPretty/pull/485
        "$pkgname-urllib3-2.3-compatibility.patch::$url/commit/8e96b1e312d473429fbd08bc867376e9932ad42a.patch")
sha512sums=('58c733ba4719f97e06e2313bb6b94f1c6609d3facb2e0262ac37be97f1c3430eac661611ba9b3712c9c1809846e177b61f3fc2945f3770d475f70b81bea2aced'
            '5520594ddb2e73d75c6eb8476dc1984464306614d915627c0c9e69815a5671d65e286e90f3ee926daa040f9f24a81835eb5c7993e620a5b67aaaefa06571dcb2'
            'c9f1668be03210ef5efc7fe6f4783af31549aa812ebb32154a27034b88866e7e81df59648a3bb68f8f6c08c2734abc4b012c9e8b90d19d8570940c20391294e9'
            '0b890bfd1dad70cf27aef5720e3158225697a4ccbe735fd7dd7e2b0887b60cc158750b9724d3e192311a6f32400480ce6ded4b01f01ed885085753ef13fc939e'
            '483cb20c64872b68dbef35a3325fc7f93d5e550c3e4cb266425a0d0ecac172b97674de8f837b2b48d63145ff0a24d3a89af1871cb84bfec9eeb70b1bea803a34')

prepare() {
  cd HTTPretty-$pkgver
  patch -p1 -i ../$pkgname-drop-mock.patch
  patch -p1 -i ../$pkgname-functional-tests-pytest-compatibility.patch
  patch -p1 -i ../$pkgname-fix-failing-requests-tests.patch
  patch -p1 -i ../$pkgname-urllib3-2.3-compatibility.patch
  sed -i -e '/rednose/d' -e '/cover/d' setup.cfg
}

build() {
  cd HTTPretty-$pkgver
  python -m build -wn
}

check() {
  cd HTTPretty-$pkgver
  # https://github.com/gabrielfalcao/HTTPretty/issues/457
  PYTHONPATH=. pytest \
    --deselect tests/functional/test_requests.py::test_httpretty_should_handle_paths_starting_with_two_slashes
}

package() {
  cd HTTPretty-$pkgver
  python -m installer -d "$pkgdir" dist/*.whl
  install -Dm644 COPYING -t "$pkgdir"/usr/share/licenses/$pkgname/
}
