Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

testing with betamax?

オープン
#212 コメント 5 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
networking

調査の方向性

Start with CacheControlAdapter.send(), the existing cachecontrol test suite, and Betamax's old_adapters handling. Define tests for cache hits and misses when CacheControl is combined with Betamax, with completion shown by requests being served from the cache when present and delegated without unintended network access otherwise.

索引モデルが issue の本文から書いたものです。

説明

is there a way to test this module alongside betamax?

the idea would be that the cachecontrol module would hit its own cache if present, otherwise bounce back into betamax. I am already using betamax extensively in my project to "mock" HTTP requests (record and replay, really) and it's been quite useful. But when I pair it with cachecontrol, I don't get good results.

either:

  1. i add cachecontrol as an "old_adapter" in the betamax session, which works in the sense that requests never hit the network, but then they never hit the cachecontrol adapter either, because the query gets cached in betamax. even if they would hit cachecontrol, they would need to hit the network first
  2. I mount cachecontrol on top of a betamax session, in which case cachecontrol completely obliterates the betamax adapter and sends requests on the network (instead of tapping in betamax)

Those two possible scenarios are pretty much covered in this ifcase:

cache_adapter = cachecontrol.CacheControlAdapter(cache=FeedContentCacheStorage(self.db_path))
# assume we mount over http and https all at once so check
# only the latter
adapter = self._session.adapters.get('https://', None)
if hasattr(adapter, 'old_adapters'):
    # looks like a betamax session was setup, hook ourselves behind it
    logging.debug('appending cache adapter (%r) to existing betamax adapter (%r)', cache_adapter, adapter)
    adapter.old_adapters['http://'] = cache_adapter
    adapter.old_adapters['https://'] = cache_adapter
else:
    logging.debug('mounting cache adapter (%r)', cache_adapter)
    # override existing adapters to use the cache adapter instead
    self._session.mount('http://', cache_adapter)
    self._session.mount('https://', cache_adapter)

That's pretty much case 1 above, which falls back to case 2 if we don't detect a "betamax" adapter in place.

And of course, it doesn't work.

What I would need is something like betamax's "old_adapters" system. Instead of calling the parent class, CacheControlAdapter.send() should allow the caller to define a list of adapters to call instead. The way betamax does this is fairly simple: there's an old_adapters parameter that you can pass and that it uses for sending its requests..

I have looked into the cachecontrol test suite to figure out if there could be inspiration there, but it seems to "mock" an http adapter instead of delegating requests... Since I don't want to reimplement the entire thing myself (and I can't figure out how to hook betamax in there either), could we add a similar functionality here?

Thanks!

PS: it seems I can mock a parent class but that seems horribly dirty - I am not sure I want to go that far...

主要言語
Python
スター
505
フォーク
153
平均マージ
5日 6時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

psf/cachecontrol のほかの issue

psf/cachecontrol の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。