Example #1
0
 def test_order(self, islice_patch):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1
     })
     instance.hooks(self.test_content)
     islice_patch.assert_called_once()
     args, kwargs = islice_patch.call_args
     order = list(args[0])
     order_keys = list(map(itemgetter('name'), order))
     self.assertEqual(
         order_keys, [
             'highest', 'highest-of-triple', 'double-1', 'double-2',
             'lowest-included', 'lowest'
         ],
         "Order of ranked dictionaries is not correct or splitting it batches did not work."
     )
     self.assertEqual(args[1], 2, "Slice should be the size of the result")
Example #2
0
 def test_hook_none_value(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$i_think_none_of_it": 1
     })
     ranking = list(instance.hooks(self.test_content))
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['lowest', 'lowest-2'],
                      "Order of ranked dictionaries is not correct.")
Example #3
0
 def test_invalid_hook_weight(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": "makes no sense"
     })
     ranking = list(instance.hooks(self.test_content))
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['lowest', 'lowest-2'],
                      "Order of ranked dictionaries is not correct.")
Example #4
0
 def test_floats_as_values(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1,
         "$ban_highest": 1
     })
     ranking = list(instance.hooks(self.test_content))
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['double-1', 'double-2'],
                      "Order of ranked dictionaries is not correct.")
Example #5
0
 def test_boolean_ranking(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$is_highest": 1
     })
     ranking = list(instance.hooks(self.test_content))
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['highest', 'highest-of-triple'],
                      "Order of ranked dictionaries is not correct.")
     self.assertEqual(ranking[0]["ds_rank"]["rank"],
                      ranking[1]["ds_rank"]["rank"])
Example #6
0
 def test_ranking_with_one_hook(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1
     })
     ranking = instance.hooks(self.test_content)
     self.assertTrue(issubclass(ranking.__class__, Iterator))
     ranking = self.assert_ranking(ranking, 2, ['rank_by_value'])
     # Check order of results
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['highest', 'highest-of-triple'],
                      "Order of ranked dictionaries is not correct.")
Example #7
0
 def test_ranking_with_multiple_hooks(self):
     instance = MockRankProcessor({
         "result_size": 2,
         "batch_size": 3,
         "$rank_by_value": 1,
         "$is_double": 2
     })
     ranking = instance.hooks(self.test_content)
     self.assertTrue(issubclass(ranking.__class__, Iterator))
     ranking = self.assert_ranking(ranking, 2,
                                   ['rank_by_value', 'is_double'])
     names = list(map(itemgetter('name'), ranking))
     self.assertEqual(names, ['double-1', 'double-2'],
                      "Order of ranked dictionaries is not correct.")