tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_reporting.py (3119B)


      1 import copy
      2 
      3 from qm_try_analysis.report import remove_duplicates
      4 
      5 
      6 class MockClient:
      7    def __init__(self, search_results, remote_bugs):
      8        self.search_results = copy.deepcopy(search_results)
      9        self.remote_bugs = copy.deepcopy(remote_bugs)
     10 
     11    def get_bug(self, bug_id):
     12        for item in self.search_results:
     13            if bug_id == item["id"]:
     14                return copy.deepcopy(item)
     15        for item in self.remote_bugs:
     16            if bug_id == item["id"]:
     17                return copy.deepcopy(item)
     18        return {"id": bug_id, "dupe_of": None}
     19 
     20 
     21 def test_duplicate_bug_removal():
     22    test_cases = [
     23        {
     24            "search_results": [
     25                {"id": "k1", "dupe_of": "k4"},
     26                {"id": "k3", "dupe_of": "k5"},
     27                {"id": "k2", "dupe_of": "k6"},
     28            ],
     29            "remote_bugs": [
     30                {"id": "k4", "dupe_of": "k2"},
     31                {"id": "k5", "dupe_of": None},
     32                {"id": "k6", "dupe_of": "k3"},
     33            ],
     34            "expected": [{"id": "k5", "dupe_of": None}],
     35        },
     36        {
     37            "search_results": [
     38                {"id": "k2", "dupe_of": "k6"},
     39                {"id": "k3", "dupe_of": "k5"},
     40                {"id": "k1", "dupe_of": "k4"},
     41            ],
     42            "remote_bugs": [
     43                {"id": "k4", "dupe_of": "k2"},
     44                {"id": "k5", "dupe_of": None},
     45                {"id": "k6", "dupe_of": "k3"},
     46            ],
     47            "expected": [{"id": "k5", "dupe_of": None}],
     48        },
     49        {
     50            "search_results": [
     51                {"id": "k1", "dupe_of": "k3"},
     52                {"id": "k2", "dupe_of": "k4"},
     53            ],
     54            "remote_bugs": [
     55                {"id": "k3", "dupe_of": "k2"},
     56                {"id": "k4", "dupe_of": None},
     57            ],
     58            "expected": [{"id": "k4", "dupe_of": None}],
     59        },
     60        {
     61            "search_results": [
     62                {"id": "k1", "dupe_of": "k3"},
     63                {"id": "k2", "dupe_of": None},
     64            ],
     65            "remote_bugs": [
     66                {"id": "k3", "dupe_of": "k4"},
     67                {"id": "k4", "dupe_of": "k2"},
     68            ],
     69            "expected": [{"id": "k2", "dupe_of": None}],
     70        },
     71        {
     72            "search_results": [
     73                {"id": "k1", "dupe_of": "k3"},
     74                {"id": "k2", "dupe_of": None},
     75            ],
     76            "remote_bugs": [{"id": "k3", "dupe_of": "k2"}],
     77            "expected": [{"id": "k2", "dupe_of": None}],
     78        },
     79        {
     80            "search_results": [
     81                {"id": "k1", "dupe_of": None},
     82                {"id": "k2", "dupe_of": "k3"},
     83            ],
     84            "remote_bugs": [{"id": "k3", "dupe_of": "k1"}],
     85            "expected": [{"id": "k1", "dupe_of": None}],
     86        },
     87    ]
     88 
     89    for test_case in test_cases:
     90        search_results = test_case["search_results"]
     91        remote_bugs = test_case["remote_bugs"]
     92        expected = test_case["expected"]
     93 
     94        mock_client = MockClient(search_results, remote_bugs)
     95 
     96        assert remove_duplicates(search_results, mock_client) == expected