Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion docs/migrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,61 @@ respx.route(url="https://example.org/").pass_through()

## requests-mock

*todo ... contribution welcome* ;-)
### Decorator

```python
@requests_mock.mock()
def test_some_call(self, m: requests_mock.mock):
m.get(requests_mock.ANY, json={})
```
```python
@respx.mock
def test_some_call(self):
respx.mock.get().respond(json={})
```

### Context manager

```python
with requests_mock.mock() as m:
m.get(requests_mock.ANY, json=json)
```
```python
with respx.mock:
respx.mock.get().respond(json=json)
```

### Raising an exception

```python
m.post(requests_mock.ANY, exc=JSONDecodeError("nope", "ok", 1))
```
```python
respx.mock.post().side_effect = JSONDecodeError("nope", "ok", 1)
```

### Specifying a list of responses

```python
m.get(requests_mock.ANY, responses)
```
```python
respx.get().side_effect = responses
```

### Assertions

```python
self.assertTrue(m.called_once)
self.assertEqual(m.last_request.url, "https://api.io/example/endpoint")
self.assertEqual(m.last_request.json(), {"key": "value"})
```

```python
respx.calls.assert_called_once()
self.assertEqual(
str(respx.calls.last.request.url),
"https://api.io/example/endpoint",
)
self.assertEqual(json.loads(respx.calls.last.request.content), {"key": "value"})
```