Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
vslinko committed May 16, 2024
1 parent 370dd69 commit 20a5c47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions bookmarks/services/auto_tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def _domains_matches(expected_domain: str, actual_domain: str) -> bool:


def _qs_matches(expected_qs: str, actual_qs: str) -> bool:
expected_qs = parse_qs(expected_qs)
actual_qs = parse_qs(actual_qs)
expected_qs = parse_qs(expected_qs, keep_blank_values=True)
actual_qs = parse_qs(actual_qs, keep_blank_values=True)

for key in expected_qs:
if key not in actual_qs:
return False
for value in expected_qs[key]:
if value not in actual_qs[key]:
if value != "" and value not in actual_qs[key]:
return False

return True
35 changes: 34 additions & 1 deletion bookmarks/tests/test_auto_tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ def test_auto_tag_by_domain(self):

self.assertEqual(tags, set(["example"]))

def test_auto_tag_by_domain_ignores_case(self):
script = """
EXAMPLE.com example
"""
url = "https://example.com/"

tags = auto_tagging.get_tags(script, url)

self.assertEqual(tags, set(["example"]))

def test_auto_tag_by_domain_should_add_all_tags(self):
script = """
example.com one two three
Expand Down Expand Up @@ -55,6 +65,16 @@ def test_auto_tag_by_domain_and_path(self):

self.assertEqual(tags, set(["one"]))

def test_auto_tag_by_domain_and_path_ignores_case(self):
script = """
example.com/One one
"""
url = "https://example.com/one/"

tags = auto_tagging.get_tags(script, url)

self.assertEqual(tags, set(["one"]))

def test_auto_tag_by_domain_and_path_matches_path_ltr(self):
script = """
example.com/one one
Expand Down Expand Up @@ -127,12 +147,25 @@ def test_auto_tag_by_domain_path_and_qs(self):
example.com/page?c=d&l=p tag3 # false, l=p doesn't exists
example.com/page?a=bb tag4 # false bb != b
example.com/page?a=b&a=c tag5 # true, matches both a=b and a=c
example.com/page?a=B tag6 # true, matches a=b because case insensitive
example.com/page?A=b tag7 # true, matches a=b because case insensitive
"""
url = "https://example.com/page/some?z=x&a=b&v=b&c=d&o=p&a=c"

tags = auto_tagging.get_tags(script, url)

self.assertEqual(tags, set(["tag1", "tag2", "tag5"]))
self.assertEqual(tags, set(["tag1", "tag2", "tag5", "tag6", "tag7"]))

def test_auto_tag_by_domain_path_and_qs_with_empty_value(self):
script = """
example.com/page?a= tag1
example.com/page?b= tag2
"""
url = "https://example.com/page/some?a=value"

tags = auto_tagging.get_tags(script, url)

self.assertEqual(tags, set(["tag1"]))

def test_auto_tag_by_domain_path_and_qs_works_with_encoded_url(self):
script = """
Expand Down

0 comments on commit 20a5c47

Please sign in to comment.