How to use responses with cachecontrol?

Đang mở
#780 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
testing-qa

Hướng nghiên cứu

Bắt đầu bằng cách chạy bài kiểm thử được cung cấp với responses 0.25.8, CacheControl 0.14.2, requests 2.32.4 và Python 3.12.6, sau đó so sánh với responses 0.12.1. Theo dõi cách responses xử lý requests Session và các adapter của nó; hoàn thành khi một lỗi kết nối bị buộc xảy ra trả về response đã được lưu vào cache trước đó như trong bản tái hiện.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug Waiting for: Product Owner

Hey folks,

We're trying to update some libs and hit an odd issue with updating responses. Consider this test:

import responses
import requests
from cachecontrol import CacheControl

def get_client():
    return CacheControl(requests.Session())

@responses.activate
def test_with_cachecontrol():
    client = get_client()
    responses.add(responses.GET, "http://test-website.com", body="Hello, world!")

    response = client.get("http://test-website.com")
    assert response.text == "Hello, world!"

    # force a connection error. Though since we're cached, it should return the cached response.
    responses.add(responses.GET, "http://test-website.com", body=ConnectionError())
    response = client.get("http://test-website.com")
    assert response.text == "Hello, world!"

(This is a simplified version of the test in our code, but should suffice.)

The gist here is we use responses to force a valid response, then after we try to force it to instead raise a ConnectionError. Normally this would lead to the cached version of the data coming back. However once we go to reponses==0.25.8 from where we previously were in responses=0.12.1 this no longer works. We get the ConnectionError raised instead of getting the cached response.

I think responses isn't running the adapters that are otherwise on the session anymore. Is there a way to still run them for this type of testing?

If it helps, heres some more info about dependencies:

CacheControl=0.14.2
requests=2.32.4

python 3.12.6 on Mac
Ngôn ngữ chính
Python
Star
4.3k
Fork
389
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của getsentry/responses

Tất cả issue của getsentry/responses

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.