예제 #1
0
def test_permissions_exception():
    with TemporaryDirectory() as tmpdir:
        os.chmod(tmpdir, 400)
        with pytest.raises(PermissionError) as excinfo:
            url = 'https://hexlet.io/courses'
            download(tmpdir, url)
        assert 'Permission denied' in str(excinfo.value)
예제 #2
0
def test_has_local_resources():
    with TemporaryDirectory() as tmpdir:
        download(tmpdir, 'https://clojure.org')
        expected = os.path.join(
            tmpdir,
            'clojure-org_files',
        )
        assert len(os.listdir(os.path.join(expected))) != 0
예제 #3
0
def main():
    """Download and save specified webpage."""
    args = make_parser().parse_args()
    configure_logger(args.log_level)
    try:
        download(args.output, args.url)
    except Exception as e:
        if 'url' in str(e.args):
            sys.exit(1)
        elif 'Permission denied' in str(e.args):
            sys.exit(2)
    sys.exit(0)
예제 #4
0
def test_404_exception():
    with TemporaryDirectory() as tmpdir:
        with pytest.raises(HTTPError) as excinfo:
            url = 'https://grishaev.me/bookshelf2'
            download(tmpdir, url)
        assert '404 Client Error' in str(excinfo.value)
예제 #5
0
def test_download():
    with TemporaryDirectory() as tmpdir:
        download(tmpdir, 'http://example.com')
        actual = read_file(os.path.join(tmpdir, 'example-com.html'))
        expected = read_file('./tests/fixtures/example-com.html')
        assert actual == expected