예제 #1
0
def test_errors():
    logging.configure('DEBUG')
    with pytest.raises(KnownError):
        with tempfile.TemporaryDirectory() as temp_dir:
            load_page(INCORRECT_URL, temp_dir)
    with pytest.raises(KnownError):
        load_page(TEST_URL, INCORRECT_PASS)
예제 #2
0
def test_create_file():
    logging.configure('DEBUG')
    with tempfile.TemporaryDirectory() as temp_dir:
        with requests_mock.Mocker() as m:
            m.get(TEST_URL, text='test')
            load_page(TEST_URL, temp_dir)
        full_path = os.path.join(temp_dir, TEMP_FILE_NAME)
        assert os.path.exists(full_path) == True
예제 #3
0
def test_create_dir():
    logging.configure('DEBUG')
    with tempfile.TemporaryDirectory() as temp_dir:
        with requests_mock.Mocker() as m:
            m.get(TEST_URL, text='test')
            load_page(TEST_URL, temp_dir)
        resource_dir = os.path.join(temp_dir, CORRECT_DIR)
        assert os.path.isdir(resource_dir) == True
예제 #4
0
def test_html():
    logging.configure('DEBUG')
    with open(CORRECT_FILE, 'r') as correct_file:
        correct_result = correct_file.read()
    with tempfile.TemporaryDirectory() as temp_dir:
        load_page(TEST_URL, temp_dir)
        full_path = os.path.join(temp_dir, TEMP_FILE_NAME)
        with open(full_path, 'r') as test_file:
            test_result = test_file.read()
    assert correct_result == test_result
예제 #5
0
def main():
    parser = argparse.ArgumentParser(description='Page loader')
    parser.add_argument('url', type=str)
    parser.add_argument('-o', '--output', help='set path for saving', type=str)
    parser.add_argument(
        '-l',
        '--log_level',
        help='set logging level from DEBUG, INFO, WARNING, ERROR, CRITICAL',
        type=str,
        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
        default='WARNING')
    args = parser.parse_args()
    logging.configure(args.log_level)
    try:
        load_page(args.url, args.output)
    except KnownError:
        sys.exit(1)