Index: tests/test_stats/test_filtehits_loader.py |
diff --git a/tests/test_stats/test_filtehits_loader.py b/tests/test_stats/test_filtehits_loader.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4a490537f97af09e02d7355c7c552af1a90d4797 |
--- /dev/null |
+++ b/tests/test_stats/test_filtehits_loader.py |
@@ -0,0 +1,53 @@ |
+# This file is part of Adblock Plus <https://adblockplus.org/>, |
+# Copyright (C) 2006-present eyeo GmbH |
+# |
+# Adblock Plus is free software: you can redistribute it and/or modify |
+# it under the terms of the GNU General Public License version 3 as |
+# published by the Free Software Foundation. |
+# |
+# Adblock Plus is distributed in the hope that it will be useful, |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+# GNU General Public License for more details. |
+# |
+# You should have received a copy of the GNU General Public License |
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ |
+import pytest |
+import py |
+ |
+from abp.stats.filterhits import load_filterhit_statistics |
+ |
+ |
+@pytest.fixture |
+def filterhits_file(): |
+ return py.path.local(__file__).dirpath('data').join('filterhits.csv') |
+ |
+ |
+def test_filterhits_load_no_filtering(filterhits_file): |
+ entries = load_filterhit_statistics(str(filterhits_file)) |
+ |
+ count = 0 |
+ |
+ for entry in entries: |
+ count += 1 |
+ assert isinstance(entry['hits'], int) |
+ assert isinstance(entry['onehour_sessions'], int) |
+ |
+ assert count == 9 |
+ |
+ |
+@pytest.mark.parametrize('sources,exp_count', [ |
+ (['https://easylist-downloads.adblockplus.org/easylist.txt'], 4), |
+ (['https://easylist-downloads.adblockplus.org/exceptionrules.txt'], 4), |
+ (['inexistent_source', 'foo', 'bar'], 0), |
+]) |
+def test_filterhits_load_with_filtering(sources, exp_count, filterhits_file): |
+ entries = load_filterhit_statistics(str(filterhits_file), sources) |
+ |
+ count = 0 |
+ |
+ for entry in entries: |
+ count += 1 |
+ |
+ assert count == exp_count |