import requests
import pytest
import json
from flexmock import flexmock
import webstore_deployer.util as util


def test_check_requests_response_status_ok():
    response = flexmock()
    response.should_receive('raise_for_status').and_return(True)

    util.handle_requests_response_status(response)


def test_check_requests_response_status_fail():
    response = flexmock()
    response.should_receive('raise_for_status').and_raise(requests.HTTPError)
    response.should_receive('json').and_return(json.dumps({"foo": "bar"}))

    with pytest.raises(requests.HTTPError):
        util.handle_requests_response_status(response)


def test_read_json_key_ok():
    assert util.read_json_key({"foo": "bar"}, "foo") == "bar"


def test_read_json_key_fail():
    with pytest.raises(KeyError):
        util.read_json_key({"foo": "bar"}, "invalid")

@@ -35,16 +35,40 @@
 rt json%0A
+import os%0Aimport shutil%0A
 from fle
@@ -861,8 +861,536 @@
 valid%22)%0A
+%0A%0Adef test_unzip():%0A    unzip_path = os.path.join('tests', 'files', 'temp_test_unzip')%0A    shutil.rmtree(unzip_path, ignore_errors=True)%0A    os.makedirs(unzip_path)%0A%0A    assert not os.path.exists(os.path.join(unzip_path, 'hello'))%0A    util.unzip('tests/files/sample_zip.zip', unzip_path)%0A%0A    assert os.path.exists(os.path.join(unzip_path, 'hello'))%0A    with open(os.path.join(unzip_path, 'hello')) as f:%0A        txt = f.read()%0A        assert txt == 'Sample content of zip %5Cn'%0A%0A    shutil.rmtree(unzip_path, ignore_errors=True)%0A

Add test for util.unzip()