|
1 |
| -import replicate |
2 | 1 | import responses
|
3 | 2 | from responses import matchers
|
4 | 3 |
|
| 4 | +import replicate |
| 5 | + |
5 | 6 | from .factories import create_client, create_version
|
6 | 7 |
|
7 | 8 |
|
| 9 | +@responses.activate |
| 10 | +def test_create_works_with_webhooks(): |
| 11 | + client = create_client() |
| 12 | + version = create_version(client) |
| 13 | + |
| 14 | + rsp = responses.post( |
| 15 | + "https://api.replicate.com/v1/predictions", |
| 16 | + match=[ |
| 17 | + matchers.json_params_matcher( |
| 18 | + { |
| 19 | + "version": "v1", |
| 20 | + "input": {"text": "world"}, |
| 21 | + "webhook": "https://example.com/webhook", |
| 22 | + "webhook_events_filter": ["completed"], |
| 23 | + } |
| 24 | + ), |
| 25 | + ], |
| 26 | + json={ |
| 27 | + "id": "p1", |
| 28 | + "version": "v1", |
| 29 | + "urls": { |
| 30 | + "get": "https://api.replicate.com/v1/predictions/p1", |
| 31 | + "cancel": "https://api.replicate.com/v1/predictions/p1/cancel", |
| 32 | + }, |
| 33 | + "created_at": "2022-04-26T20:00:40.658234Z", |
| 34 | + "completed_at": "2022-04-26T20:02:27.648305Z", |
| 35 | + "source": "api", |
| 36 | + "status": "processing", |
| 37 | + "input": {"text": "world"}, |
| 38 | + "output": None, |
| 39 | + "error": None, |
| 40 | + "logs": "", |
| 41 | + }, |
| 42 | + ) |
| 43 | + |
| 44 | + prediction = client.predictions.create( |
| 45 | + version=version, |
| 46 | + input={"text": "world"}, |
| 47 | + webhook="https://example.com/webhook", |
| 48 | + webhook_events_filter=["completed"], |
| 49 | + ) |
| 50 | + |
| 51 | + assert rsp.call_count == 1 |
| 52 | + |
| 53 | + |
8 | 54 | @responses.activate
|
9 | 55 | def test_cancel():
|
10 | 56 | client = create_client()
|
|
0 commit comments