@patch.object(R, '_category_slugs')
    def test_metric_slugs_by_category(self, mock_category_slugs):
        # set up a mock return value for the category's redis set
        self.redis.smembers.return_value = ['Sample Category']
        # set up return value for mock call to _category_slugs
        mock_category_slugs.return_value = ['foo', 'bar']

        # Since this method all calls out to ``R.metric_slugs``, let's patch
        # that so it returns a list of all slugs, one of which will not be
        # categorized
        self.r.metric_slugs = Mock(return_value=['foo', 'bar', 'baz'])

        # Now, test the thing.
        result = self.r.metric_slugs_by_category()
        expected_result = {
            'Sample Category': ['foo', 'bar'],
            'Uncategorized': ['baz']
        }
        self.assertEqual(result, expected_result)
        self.redis.smembers.assert_called_once_with("categories")
        mock_category_slugs.assert_called_once_with("Sample Category")
        self.r.metric_slugs.assert_called_once_with()
Iterate through each item in the collection
dataset/ETHPy150Open bradmontgomery/django-redis-metrics/redis_metrics/tests/test_models.py/TestR.test_metric_slugs_by_category--crossover with--dataset/ETHPy150Open pimoroni/pibrella/pins.py/ObjectCollection.each