How to use the responses.add_passthru function in responses

To help you get started, we’ve selected a few responses examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / bugbug / tests / test_repository.py View on Github external
def test_download_commits(fake_hg_repo):
    hg, local, remote = fake_hg_repo

    # Allow using the local code analysis server.
    responses.add_passthru("http://127.0.0.1")

    responses.add(
        responses.HEAD,
        "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.source.source-bugzilla-info/artifacts/public/components.json",
        status=200,
        headers={"ETag": "123"},
    )

    responses.add(
        responses.GET,
        "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.source.source-bugzilla-info/artifacts/public/components.json",
        status=200,
        json={
            "file1": ["Firefox", "Menus"],
            "file2": ["Firefox", "General"],
            "file3": ["Core", "General"],
github openelections / clarify / tests / test_jurisdiction.py View on Github external
def test_get_subjurisdictions_counties_web01(self):
        """A jurisdiction with sub-jurisdictions with Web01 in url should return a list of URLs"""
        # Avoid hitting all the summary URLs for each subjurisdiction.
        responses.add(
            method=responses.GET,
            url=re.compile(r"^https://results.enr.clarityelections.com/AR/(.+/[0-9]+/[0-9]+/Web01/en/summary.html|(.+/)?[0-9]+/[0-9]+/reports/summary.zip)$"),
            status=200,
        )

        # Construct a Jurisdiction for Arkansas 2014 General Election
        url = "https://results.enr.clarityelections.com/AR/53237/149294/Web01/en/summary.html"
        responses.add_passthru(url)
        responses.add_passthru(url.replace("summary.html", "json/electionsettings.json"))
        jurisdiction = Jurisdiction(url=url, level="state")

        subjurisdictions = jurisdiction.get_subjurisdictions()

        # A state like AR has county sub-jurisdictions with results
        expected_subjurisdiction_count = 75
        self.assertEqual(len(subjurisdictions), expected_subjurisdiction_count)
github mozilla / bugbug / tests / test_repository.py View on Github external
def test_get_touched_functions():
    # Allow using the local code analysis server.
    responses.add_passthru("http://127.0.0.1")

    repository.code_analysis_server = rust_code_analysis_server.RustCodeAnalysisServer()

    # No function touched.
    touched_functions = repository.get_touched_functions(
        "file.cpp",
        [],
        [],
        """void func1() {
    int i = 1;
}

void func2() {
    int i = 2;
}""",
    )
github getsentry / responses / test_responses.py View on Github external
def run():
        responses.add_passthru(httpserver.url)
        responses.add(responses.GET, "{}/one".format(httpserver.url), body="one")
        responses.add(responses.GET, "http://example.com/two", body="two")

        resp = requests.get("http://example.com/two")
        assert_response(resp, "two")
        resp = requests.get("{}/one".format(httpserver.url))
        assert_response(resp, "one")
        resp = requests.get(httpserver.url)
        assert_response(resp, "OK")
github openelections / clarify / tests / test_jurisdiction.py View on Github external
def test_get_subjurisdictions_counties_web01(self):
        """A jurisdiction with sub-jurisdictions with Web01 in url should return a list of URLs"""
        # Avoid hitting all the summary URLs for each subjurisdiction.
        responses.add(
            method=responses.GET,
            url=re.compile(r"^https://results.enr.clarityelections.com/AR/(.+/[0-9]+/[0-9]+/Web01/en/summary.html|(.+/)?[0-9]+/[0-9]+/reports/summary.zip)$"),
            status=200,
        )

        # Construct a Jurisdiction for Arkansas 2014 General Election
        url = "https://results.enr.clarityelections.com/AR/53237/149294/Web01/en/summary.html"
        responses.add_passthru(url)
        responses.add_passthru(url.replace("summary.html", "json/electionsettings.json"))
        jurisdiction = Jurisdiction(url=url, level="state")

        subjurisdictions = jurisdiction.get_subjurisdictions()

        # A state like AR has county sub-jurisdictions with results
        expected_subjurisdiction_count = 75
        self.assertEqual(len(subjurisdictions), expected_subjurisdiction_count)
github Cloud-CV / evalai-cli / tests / test_submissions.py View on Github external
json=json.loads(challenge_response.challenge_phase_details_slug),
            status=200,
        )

        # To get Challenge Details
        url = "{}{}"
        responses.add(
            responses.GET,
            url.format(API_HOST_URL, URLS.challenge_details.value).format(
                "10"
            ),
            json=json.loads(challenge_response.challenge_details),
            status=200,
        )

        responses.add_passthru("http+docker://localhost/")
github alexdlaird / air-quality-bot / devserver.py View on Github external
}
}
dictConfig(LOGGING)

USE_NGROK = os.environ.get("WERKZEUG_RUN_MAIN") != "true"

# Initialize the Flask app for a simple web server
app = Flask(__name__)

# Calling mock_dynamodb2() above hijacked the requests library, so using the responses
# library (that moto also used), add passthrus for HTTP requests that should still
# succeed in dev
responses.add_passthru("http://127.0.0.1")
responses.add_passthru("https://api.twilio.com")
responses.add_passthru("http://www.airnowapi.org")
responses.add_passthru("https://airnow.gov")

if USE_NGROK:
    # Get the dev server port (defaults to 5000 for Flask, can be overridden with `--port`
    # when starting the server
    port = sys.argv[sys.argv.index("--port") + 1] if "--port" in sys.argv else 5000

    # Open a ngrok tunnel to the dev server
    public_url = ngrok.connect(port)
    print(" * ngrok tunnel \"{}\" -> \"http://127.0.0.1:{}/\"".format(public_url, port))

    TWILIO_ACCOUNT_SID = os.environ.get("AIR_QUALITY_DEV_TWILIO_ACCOUNT_SID", None)
    TWILIO_AUTH_TOKEN = os.environ.get("AIR_QUALITY_DEV_TWILIO_AUTH_TOKEN", None)
    TWILIO_SMS_NUMBER = os.environ.get("AIR_QUALITY_DEV_TWILIO_SMS_NUMBER", None)

    # Update any base URLs or webhooks to use the public ngrok URL
    if TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN and TWILIO_SMS_NUMBER:
github alexdlaird / air-quality-bot / devserver.py View on Github external
"root": {
        "level": "INFO",
        "handlers": ["console"]
    }
}
dictConfig(LOGGING)

USE_NGROK = os.environ.get("WERKZEUG_RUN_MAIN") != "true"

# Initialize the Flask app for a simple web server
app = Flask(__name__)

# Calling mock_dynamodb2() above hijacked the requests library, so using the responses
# library (that moto also used), add passthrus for HTTP requests that should still
# succeed in dev
responses.add_passthru("http://127.0.0.1")
responses.add_passthru("https://api.twilio.com")
responses.add_passthru("http://www.airnowapi.org")
responses.add_passthru("https://airnow.gov")

if USE_NGROK:
    # Get the dev server port (defaults to 5000 for Flask, can be overridden with `--port`
    # when starting the server
    port = sys.argv[sys.argv.index("--port") + 1] if "--port" in sys.argv else 5000

    # Open a ngrok tunnel to the dev server
    public_url = ngrok.connect(port)
    print(" * ngrok tunnel \"{}\" -> \"http://127.0.0.1:{}/\"".format(public_url, port))

    TWILIO_ACCOUNT_SID = os.environ.get("AIR_QUALITY_DEV_TWILIO_ACCOUNT_SID", None)
    TWILIO_AUTH_TOKEN = os.environ.get("AIR_QUALITY_DEV_TWILIO_AUTH_TOKEN", None)
    TWILIO_SMS_NUMBER = os.environ.get("AIR_QUALITY_DEV_TWILIO_SMS_NUMBER", None)