|
| 1 | +import pytest |
| 2 | +from django.urls import reverse |
| 3 | +from rest_framework.status import HTTP_201_CREATED |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.parametrize("question__type", ["files"]) |
| 7 | +def test_minio_callback_view(transactional_db, client, answer, minio_mock, settings): |
| 8 | + file = answer.files.first() |
| 9 | + data = { |
| 10 | + "EventName": "s3:ObjectCreated:Put", |
| 11 | + "Key": "caluma-media/218b2504-1736-476e-9975-dc5215ef4f01_test.png", |
| 12 | + "Records": [ |
| 13 | + { |
| 14 | + "eventVersion": "2.0", |
| 15 | + "eventSource": "minio:s3", |
| 16 | + "awsRegion": "", |
| 17 | + "eventTime": "2020-07-17T06:38:23.221Z", |
| 18 | + "eventName": "s3:ObjectCreated:Put", |
| 19 | + "userIdentity": {"principalId": "minio"}, |
| 20 | + "requestParameters": { |
| 21 | + "accessKey": "minio", |
| 22 | + "region": "", |
| 23 | + "sourceIPAddress": "172.20.0.1", |
| 24 | + }, |
| 25 | + "responseElements": { |
| 26 | + "x-amz-request-id": "162276DB8350E531", |
| 27 | + "x-minio-deployment-id": "5db7c8da-79cb-4d3a-8d40-189b51ca7aa6", |
| 28 | + "x-minio-origin-endpoint": "http://172.20.0.2:9000", |
| 29 | + }, |
| 30 | + "s3": { |
| 31 | + "s3SchemaVersion": "1.0", |
| 32 | + "configurationId": "Config", |
| 33 | + "bucket": { |
| 34 | + "name": "caluma-media", |
| 35 | + "ownerIdentity": {"principalId": "minio"}, |
| 36 | + "arn": "arn:aws:s3:::caluma-media", |
| 37 | + }, |
| 38 | + "object": { |
| 39 | + "key": "{file_id}_name".format(file_id=file.id), |
| 40 | + "size": 299758, |
| 41 | + "eTag": "af1421c17294eed533ec99eb82b468fb", |
| 42 | + "contentType": "application/pdf", |
| 43 | + "userMetadata": {"content-variant": "application/pdf"}, |
| 44 | + "versionId": "1", |
| 45 | + "sequencer": "162276DB83A9F895", |
| 46 | + }, |
| 47 | + }, |
| 48 | + "source": { |
| 49 | + "host": "172.20.0.1", |
| 50 | + "port": "", |
| 51 | + "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.15.0 Chrome/80.0.3987.163 Safari/537.36", |
| 52 | + }, |
| 53 | + } |
| 54 | + ], |
| 55 | + } |
| 56 | + |
| 57 | + assert file.is_draft is True |
| 58 | + response = client.post( |
| 59 | + reverse("minio-callback"), data=data, content_type="application/json" |
| 60 | + ) |
| 61 | + file.refresh_from_db() |
| 62 | + assert file.is_draft is False |
| 63 | + assert response.status_code == HTTP_201_CREATED |
0 commit comments