Skip to content

Mocket can't mock zip or image file upload #94

@kpradhan-cs

Description

@kpradhan-cs

By following the readme file, I tried to use Mocket to mock zip and image file upload, but it threw an error. I looked into other related issues, but couldn't find any proper solution.

#upload_test.py
import json

from mocket import mocketize
from mocket.mockhttp import Entry
import requests
import pytest

@pytest.fixture
def response():
    return {
        "integer": 1,
        "string": "asd",
        "boolean": False,
    }

@mocketize  # use its decorator
def test_json(response):
    url_to_mock = 'https://testme.org/json'
    Entry.single_register(
        Entry.POST,
        url_to_mock,
        body=response,
        headers={'content-type': 'application/json'}
    )

    data = {}
    file_obj = open('./test/data/sdk-skill.zip', 'rb')
    files = { 'content': file_obj }
    resp = requests.post(url_to_mock, files=files, data=data, verify=False)
    mocked_response = resp.json()

    assert response == mocked_response

When I run pytest test/unit/upload_test.py, it gives

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 123: invalid start byte

Screenshot 2019-06-14 at 12 57 34 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions