Exemplo n.º 1
0
def test_check_file__generates_md5_hash(mocker, cli_request, request_info):
    request_info.return_value = {'ETag': '_tag_'}
    md5 = mocker.patch('hashlib.md5')
    mo = mock.mock_open(read_data=u'hashed_tag')
    with mock.patch.object(cli, 'open', mo):
        cli.check_file('https://foo.bar/filename', 'testfile')
    md5.assert_called_once_with('hashed_tag')
Exemplo n.º 2
0
def test_check_file__valid(mocker, cli_request, request_info, tag, result):
    request_info.return_value = {'ETag': '_tag_'}
    mocker.patch('hashlib.md5').return_value.hexdigest.return_value = tag
    mo = mock.mock_open(read_data=u'hashed_tag')
    with mock.patch.object(cli, 'open', mo):
        result = cli.check_file('https://foo.bar/filename', 'testfile')
    assert result == result
Exemplo n.º 3
0
def test_check_file__makes_head_request(cli_request, request_info):
    with pytest.raises(Exception):
        cli.check_file('https://foo.bar/filename', 'testfile')
    assert cli_request.return_value.get_method() == 'HEAD'
Exemplo n.º 4
0
def test_check_file__missing_etag(cli_request, request_info):
    with pytest.raises(Exception) as e:
        cli.check_file('https://foo.bar/filename', 'testfile')
    assert 'Etag not found on download url' in str(e)
Exemplo n.º 5
0
def test_check_file__requests_url(cli_request, request_info):
    with pytest.raises(Exception):
        cli.check_file('https://foo.bar/filename', 'testfile')
    cli_request.assert_called_once_with('https://foo.bar/filename')