How to use the treq.testing.StubTreq function in treq

To help you get started, we’ve selected a few treq 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 twisted / treq / docs / examples / testing_seq.py View on Github external
def test_418_teapot(self):
        """On an unexpected response code, raise an exception"""
        req_seq = RequestSequence([
            ((b'get', 'http://an.example/foo', {b'a': [b'b']},
              HasHeaders({'Accept': ['application/json']}), b''),
             (418, {b'Content-Type': b'text/plain'}, b"I'm a teapot!"))
        ])
        treq = StubTreq(StringStubbingResource(req_seq))

        with req_seq.consume(self.fail):
            failure = self.failureResultOf(make_a_request(treq))

        self.assertEqual(u"Got an error from the server: I'm a teapot!",
                         failure.getErrorMessage())
github rackerlabs / otter / otter / integration / lib / test_mimic.py View on Github external
def test_set_clb_attributes(self):
        """
        :func:`set_clb_attributes` calls
        ``PATCH .../loadbalancer/lb_id/attributes`` with given key-value pairs
        """
        stubs = RequestSequence(
            [(("patch", "http://host/loadbalancer/3/attributes", {}, mock.ANY,
               '{"a": "b"}'),
              (204, {}, ""))],
            self.fail)
        self.clb.treq = StubTreq(StringStubbingResource(stubs))
        with stubs.consume(self.fail):
            self.clb.set_clb_attributes(self.rcs, 3, {"a": "b"})
github rackerlabs / otter / otter / integration / lib / test_mimic.py View on Github external
def test_update_clb_node_status(self):
        """
        :func:`update_clb_node_status` calls
        ``PUT .../loadbalancers/lb_id/nodes/node_id/status`` with given status
        in body
        """
        stubs = RequestSequence(
            [(("put", "http://host/loadbalancers/3/nodes/2/status", {},
               mock.ANY, '{"status": "ONLINE"}'),
              (200, {}, ""))],
            self.fail)
        self.clb.treq = StubTreq(StringStubbingResource(stubs))
        with stubs.consume(self.fail):
            self.clb.update_clb_node_status(self.rcs, 3, 2, "ONLINE")
github twisted / treq / docs / examples / testing_seq.py View on Github external
def test_200_ok(self):
        """On a 200 response, return the response's JSON."""
        req_seq = RequestSequence([
            ((b'get', 'http://an.example/foo', {b'a': [b'b']},
              HasHeaders({'Accept': ['application/json']}), b''),
             (http.OK, {b'Content-Type': b'application/json'}, b'{"status": "ok"}'))
        ])
        treq = StubTreq(StringStubbingResource(req_seq))

        with req_seq.consume(self.fail):
            result = self.successResultOf(make_a_request(treq))

        self.assertEqual({"status": "ok"}, result)
github RasaHQ / rasa / tests / base / test_server.py View on Github external
_, nlu_log_file = tempfile.mkstemp(suffix="_rasa_nlu_logs.json")
    _config = {
        'write': nlu_log_file,
        'port': -1,  # unused in test app
        "pipeline": "keyword",
        "path": tmpdir_factory.mktemp("projects").strpath,
        "server_model_dirs": {},
        "data": "./data/demo-restaurants.json",
        "emulate": "wit",
        "max_training_processes": 1
    }

    config = RasaNLUConfig(cmdline_args=_config)
    rasa = RasaNLU(config, testing=True)
    return StubTreq(rasa.app.resource())
github botfront / rasa-for-botfront / _pytest / test_server.py View on Github external
_, nlu_log_file = tempfile.mkstemp(suffix="_rasa_nlu_logs.json")
    _config = {
        'write': nlu_log_file,
        'port': -1,  # unused in test app
        "pipeline": "keyword",
        "path": tmpdir_factory.mktemp("models").strpath,
        "server_model_dirs": {},
        "data": "./data/demo-restaurants.json",
        "emulate": "wit",
        "max_training_processes": 1
    }

    config = RasaNLUConfig(cmdline_args=_config)
    rasa = RasaNLU(config, testing=True)
    return StubTreq(rasa.app.resource())
github RasaHQ / rasa / tests / nlu / base / test_server.py View on Github external
@pytest.fixture(scope="module")
def app(tmpdir_factory):
    """Use IResource interface of Klein to mock Rasa HTTP server.

    :param component_builder:
    :return:
    """

    _, nlu_log_file = tempfile.mkstemp(suffix="_rasa_nlu_logs.json")

    router = DataRouter(tmpdir_factory.mktemp("projects").strpath)

    rasa = RasaNLU(router,
                   logfile=nlu_log_file,
                   testing=True)
    return StubTreq(rasa.app.resource())
github RasaHQ / rasa / tests / base / test_multitenancy.py View on Github external
"""

    if "TRAVIS_BUILD_DIR" in os.environ:
        root_dir = os.environ["TRAVIS_BUILD_DIR"]
    else:
        root_dir = os.getcwd()

    _, nlu_log_file = tempfile.mkstemp(suffix="_rasa_nlu_logs.json")

    train_models(component_builder,
                 os.path.join(root_dir, "data/examples/rasa/demo-rasa.json"))

    router = DataRouter(os.path.join(root_dir, "test_projects"))
    rasa = RasaNLU(router, logfile=nlu_log_file, testing=True)

    return StubTreq(rasa.app.resource())
github RasaHQ / rasa / tests / nlu / base / test_multitenancy.py View on Github external
"""

    if "TRAVIS_BUILD_DIR" in os.environ:
        root_dir = os.environ["TRAVIS_BUILD_DIR"]
    else:
        root_dir = os.getcwd()

    _, nlu_log_file = tempfile.mkstemp(suffix="_rasa_nlu_logs.json")

    train_models(component_builder,
                 os.path.join(root_dir, "data/examples/rasa/demo-rasa.json"))

    router = DataRouter(os.path.join(root_dir, "test_projects"))
    rasa = RasaNLU(router, logfile=nlu_log_file, testing=True)

    return StubTreq(rasa.app.resource())
github LeastAuthority / leastauthority.com / src / lae_automation / stripe.py View on Github external
def memory_stripe_client(state):
    return _StripeClient(
        b"http://127.0.0.0/",
        StubTreq(_stripe_resource(state)),
    )