How to use the mocket.Mocket.last_request function in mocket

To help you get started, we’ve selected a few mocket 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 mindflayer / python-mocket / tests / main / test_mocket.py View on Github external
def test_collect(self):
        request = 'GET /get/p/?b=2&a=1 HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: testme.org\r\nConnection: close\r\nUser-Agent: Python-urllib/2.6\r\n\r\n'
        Mocket.collect(request)
        self.assertEqual(Mocket.last_request(), request)
        self.assertEqual(Mocket._requests, [request])
github mindflayer / python-mocket / tests / main / test_redis.py View on Github external
def test_err(self):
        Entry.register_response('INCRBY counter one', ERROR('ERR value is not an integer or out of range'))
        self.assertRaises(redis.ResponseError, self.rclient.incr, 'counter', 'one')
        self.assertEqual(len(Mocket._requests), 1)
        self.assertEqual(Mocket.last_request().data, b'*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$3\r\none\r\n')
github mindflayer / python-mocket / tests / main / test_http.py View on Github external
def test_request_bodies(self):
        url = "http://bit.ly/fakeurl/{0}"

        for e in range(5):
            u = url.format(e)
            Entry.single_register(Entry.POST, u, body=str(e))
            request_body = urlencode({"key-{0}".format(e): "value={0}".format(e)})
            urlopen(u, request_body.encode("utf-8"))
            last_request = Mocket.last_request()
            assert last_request.body == request_body
github mindflayer / python-mocket / tests / main / test_http.py View on Github external
def test_multipart(self):
        url = "http://httpbin.org/post"
        data = '--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="content"\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: 68\r\n\r\nAction: comment\nText: Comment with attach\nAttachment: x1.txt, x2.txt\r\n--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="attachment_2"; filename="x.txt"\r\nContent-Type: text/plain\r\nContent-Length: 4\r\n\r\nbye\n\r\n--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="attachment_1"; filename="x.txt"\r\nContent-Type: text/plain\r\nContent-Length: 4\r\n\r\nbye\n\r\n--xXXxXXyYYzzz--\r\n'
        headers = {
            "Content-Length": "495",
            "Content-Type": "multipart/form-data; boundary=xXXxXXyYYzzz",
            "Accept": "text/plain",
            "User-Agent": "Mocket",
            "Accept-encoding": "identity",
        }
        Entry.register(Entry.POST, url)
        response = requests.post(url, data=data, headers=headers)
        self.assertEqual(response.status_code, 200)
        last_request = Mocket.last_request()
        self.assertEqual(last_request.method, "POST")
        self.assertEqual(last_request.path, "/post")
        self.assertEqual(last_request.body, data)
        sent_headers = dict(last_request.headers)
        self.assertEqualHeaders(
            sent_headers,
            {
                "accept": "text/plain",
                "accept-encoding": "identity",
                "content-length": "495",
                "content-type": "multipart/form-data; boundary=xXXxXXyYYzzz",
                "host": "httpbin.org",
                "user-agent": "Mocket",
                "connection": "keep-alive",
            },
        )
github mindflayer / python-mocket / tests / main / test_redis.py View on Github external
def test_get_unicode(self):
        Entry.register_response('GET snowman', '\u2603')
        self.assertEqual(self.rclient.get('snowman'), b'\xe2\x98\x83')
        self.assertEqual(len(Mocket._requests), 1)
        self.assertEqual(Mocket.last_request().data, b'*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n')
github mindflayer / python-mocket / tests / main / test_mocket.py View on Github external
def test_lastrequest(self):
        self.assertEqual(Mocket.last_request(), None)
        Mocket._requests.extend([1, 2, 3])
        self.assertEqual(Mocket.last_request(), 3)
github mindflayer / python-mocket / tests / main / test_redis.py View on Github external
def test_lrange(self):
        l = [b'one', b'two', b'three']
        Entry.register_response('LRANGE list 0 -1', l)
        self.assertEqual(self.rclient.lrange('list', 0, -1), l)
        self.assertEqual(len(Mocket._requests), 1)
        self.assertEqual(Mocket.last_request().data, b'*4\r\n$6\r\nLRANGE\r\n$4\r\nlist\r\n$1\r\n0\r\n$2\r\n-1\r\n')
github mindflayer / python-mocket / tests / main / test_redis.py View on Github external
def test_set(self):
        Entry.register_response('SET mocket "is awesome!"', OK)
        self.assertTrue(self.rclient.set('mocket', 'is awesome!'))
        self.assertEqual(len(Mocket._requests), 1)
        self.assertEqual(Mocket.last_request().data, b'*3\r\n$3\r\nSET\r\n$6\r\nmocket\r\n$11\r\nis awesome!\r\n')