Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: tests/test_filter_block.py

Issue 30053555: Issue 7471 - Add an API for working with blocks of filters (Closed) Base URL: https://hg.adblockplus.org/python-abp
Patch Set: Created May 8, 2019, 4:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « abp/filters/blocks.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-present eyeo GmbH
3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation.
7 #
8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15
16 from __future__ import unicode_literals
17
18 import pytest
19
20 from abp.filters import parse_line, SelectorType, FilterAction, ParseError
21 from abp.filters.blocks import to_blocks, FilterBlock
22
23 BLOCKS = """
24 ! Example block
25 !:foo=bar
26 !:baz=some_tricky?variable=with&funny=chars#and-stuff
27 ! Another comment
28 ||block.ing/filter$domain=foo.com|~bar.com
29 white.list.ing#@#hiding.filter
30 ! Second block
31 @@whateve.rs
32 """
33
34 BLOCK_LINES = list(map(parse_line, BLOCKS.splitlines()))
35
36
37 def test_to_blocks():
38 blocks = list(to_blocks(BLOCK_LINES))
39 assert len(blocks) == 2
40 block = blocks[0]
41 assert block.foo == 'bar'
42 assert block.baz == 'some_tricky?variable=with&funny=chars#and-stuff'
43 assert block.description == 'Example block\nAnother comment'
44 # Don't test the filters thouroughly: filter parsing is tested elsewhere.
45 assert len(block.filters) == 2
46 assert block.filters[0].selector['type'] == SelectorType.URL_PATTERN
47 assert block.filters[1].action == FilterAction.SHOW
48
49
50 def test_asdict():
51 blocks = list(to_blocks(BLOCK_LINES))
52 d = blocks[0]._asdict()
53 assert d['foo'] == 'bar'
54 assert d['baz'] == 'some_tricky?variable=with&funny=chars#and-stuff'
55 assert d['description'] == 'Example block\nAnother comment'
56 assert len(d['filters']) == 2
57 assert d['filters'][0]['selector']['type'] == SelectorType.URL_PATTERN
58 assert d['filters'][1]['action'] == FilterAction.SHOW
59
60
61 @pytest.mark.parametrize('line', [
62 '!:__dict__=foo',
63 '!:_var=bar',
64 '!:filters=stuff',
65 '!:description=he he',
66 ])
67 def test_illegal_vars(line):
68 """Check that illegal variable names are not allowed."""
69 with pytest.raises(ParseError):
70 FilterBlock([parse_line(line)], [])
OLDNEW
« no previous file with comments | « abp/filters/blocks.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld