Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bukuserver test cache #661

Merged
merged 5 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
rev: 1.5.1
hooks:
- id: darker
args: [--line-length, '139']
args: [--line-length, '139', --skip-string-normalization]
- repo: https://github.com/PyCQA/pylint/
rev: v2.15.5
hooks:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'py>=1.5.0',
'pylint>=1.7.2',
'pytest-cov',
'pytest-vcr>=1.0.2',
'pytest-recording>=0.12.1',
'pytest>=6.2.1',
'PyYAML>=4.2b1',
'setuptools>=41.0.1',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip,deflate
Cookie:
- ''
DNT:
- '1'
User-Agent:
- Mozilla/5.0 (X11; Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0
method: GET
uri: http://example.com/
response:
body:
string: !!binary |
H4sIAMIVqF0AA31UTXPbIBC9+1ds1UsyIyQnaRqPLWn6mWkPaQ9pDz0SsbKYCFAByfZ08t+7Qo4j
N5makYFdeLvvsZC9Eqb0uxah9qopZtljh1wUM6Bf5qVvsPi85aptED4ZxaXO0tE6G5co9BzKmluH
Po86X7FFBGkxcdbetwx/d7LPo49Ge9SeDWEjKMdZHnnc+nQIvzpAvYSkucI86iVuWmP9ZP9GCl/n
AntZIguTGKSWXvKGuZI3mJ89QTm/IzJDBvvApXPR6LszYgd/wjBMeXm/tqbTgpWmMXYJr6s5tfPV
YYnidi31EuZPppYLIfX6yFZRpqziSja7JTDekpzM7ZxHFcPYs07G8KGR+v6Gl7fBdE2bYohucW0Q
fn6NaPy9RQ23XLth8gWbHr0sOXzDDslyMMTw3hJ3wqalzKGV1VMuYfAQ/oXsJ3SDcEt4O5+32+cM
L1EB77x5geg5qtV/RRPUJhncGSvQMsuF7BzplFweAZgtczUXZkPI7RYu6Luibxjb9R0/mcehJfPz
09WEDF8O6sXU99JJj2JC7TGTi8WbxWKSyXD+TGBpLPfSEEttNE5B3ykUksOJ4lu21+dq0Od0An6s
4lFV/KPYROVjx8MkZJaGCi3CWWXpeB1n2VCbdDsp2L6O67NnN5NMo68tftTSgQh2oFFlLHQOYZg1
Tef8QLhHwBHBDQ56DjpF98kl8Mt0RGIXtnhCGqtlj6ahIXkJoLNIdHxtOg+tlRSiNHS0Ugcxgebc
3VOFhOgtWiWdI0eSpe0hz4weCItVHg3PhFum6WazSSTXPDF2nY4hXbpPMypujB1IEKAKQZKE0HgR
ELM0iJOle6nS8UH7CyjrfG/oBAAA
headers:
Age:
- '83814'
Cache-Control:
- max-age=604800
Content-Encoding:
- gzip
Content-Length:
- '648'
Content-Type:
- text/html; charset=UTF-8
Date:
- Sat, 07 Jan 2023 07:50:26 GMT
Etag:
- '"3147526947+ident+gzip"'
Expires:
- Sat, 14 Jan 2023 07:50:26 GMT
Last-Modified:
- Thu, 17 Oct 2019 07:18:26 GMT
Server:
- ECS (sab/56BA)
Vary:
- Accept-Encoding
X-Cache:
- HIT
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip,deflate
Cookie:
- ''
DNT:
- '1'
User-Agent:
- Mozilla/5.0 (X11; Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0
method: HEAD
uri: http://example.com/page1.txt
response:
body:
string: ''
headers:
Cache-Control:
- max-age=604800
Content-Encoding:
- gzip
Content-Length:
- '648'
Content-Type:
- text/html; charset=UTF-8
Date:
- Sat, 07 Jan 2023 07:50:27 GMT
Expires:
- Sat, 14 Jan 2023 07:50:27 GMT
Server:
- EOS (vny/0451)
Vary:
- Accept-Encoding
status:
code: 404
message: Not Found
version: 1

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/test_buku.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def test_sigint_handler(capsys):
assert err == "\nInterrupted.\n"


@pytest.mark.vcr("tests/vcr_cassettes/test_network_handler_with_url.yaml")
@pytest.mark.parametrize(
"url, exp_res",
[
Expand Down
26 changes: 6 additions & 20 deletions tests/test_bukuDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# Unit test cases for buku
#
import logging
import math
import os
import re
Expand All @@ -12,24 +11,17 @@
import unittest
import urllib
import zipfile

# fmt: off
from tempfile import NamedTemporaryFile, TemporaryDirectory
from unittest import mock
from genericpath import exists
# fmt: on

import pytest
import vcr
import yaml
from genericpath import exists
from hypothesis import example, given, settings
from hypothesis import strategies as st

from buku import BukuDb, parse_tags, prompt

logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from vcrpy
vcr_log = logging.getLogger("vcr")
vcr_log.setLevel(logging.INFO)

def get_temp_dir_path():
with TemporaryDirectory(prefix="bukutest_") as dir_obj:
Expand Down Expand Up @@ -380,9 +372,7 @@ def test_search_by_tag(self):
expected[0] += tuple([0])
self.assertEqual(results, expected)

@vcr.use_cassette(
"tests/vcr_cassettes/test_search_by_multiple_tags_search_any.yaml"
)
@pytest.mark.vcr("tests/vcr_cassettes/test_search_by_multiple_tags_search_any.yaml")
def test_search_by_multiple_tags_search_any(self):
# adding bookmarks
for bookmark in self.bookmarks:
Expand Down Expand Up @@ -432,9 +422,7 @@ def test_search_by_multiple_tags_search_any(self):
]
self.assertEqual(results, expected)

@vcr.use_cassette(
"tests/vcr_cassettes/test_search_by_multiple_tags_search_all.yaml"
)
@pytest.mark.vcr("tests/vcr_cassettes/test_search_by_multiple_tags_search_all.yaml")
def test_search_by_multiple_tags_search_all(self):
# adding bookmarks
for bookmark in self.bookmarks:
Expand Down Expand Up @@ -564,9 +552,7 @@ def test_search_by_tags_exclusion(self):
]
self.assertEqual(results, expected)

@vcr.use_cassette(
"tests/vcr_cassettes/test_search_by_tags_enforces_space_seprations_exclusion.yaml"
)
@pytest.mark.vcr("tests/vcr_cassettes/test_search_by_tags_enforces_space_seprations_exclusion.yaml")
def test_search_by_tags_enforces_space_seprations_exclusion(self):

bookmark1 = [
Expand Down Expand Up @@ -653,7 +639,7 @@ def test_search_and_open_in_broswer_by_range(self):
# checking if browse called with expected arguments
self.assertEqual(arg_list, expected)

@vcr.use_cassette("tests/vcr_cassettes/test_search_and_open_all_in_browser.yaml")
@pytest.mark.vcr("tests/vcr_cassettes/test_search_and_open_all_in_browser.yaml")
def test_search_and_open_all_in_browser(self):
# adding bookmarks
for bookmark in self.bookmarks:
Expand Down Expand Up @@ -1219,7 +1205,7 @@ def test_edit_update_rec_with_invalid_input(get_system_editor_retval, index, exp
assert res == exp_res


@vcr.use_cassette("tests/vcr_cassettes/test_browse_by_index.yaml")
@pytest.mark.vcr("tests/vcr_cassettes/test_browse_by_index.yaml")
@given(
low=st.integers(min_value=-2, max_value=3),
high=st.integers(min_value=-2, max_value=3),
Expand Down