

@run_only_if_pymongo_is_available
@patch('pymongo.Connection')
@patch.object(Collector, 'publish')
def test_should_ignore_unneeded_collections(self, publish_mock, connector_mock):
    data = {
        'more_keys': long(1),
        'key': 2,
        'string': 'str',
    }
    self._annotate_connection(connector_mock, data)
    self.connection['db1'].collection_names.return_value = ['collection1', 'tmp.mr.tmp1']
    self.connection['db1'].command.return_value = {
        'key': 2,
        'string': 'str',
    }
    self.collector.collect()
    self.connection.db.command.assert_called_once_with('serverStatus')
    self.connection['db1'].collection_names.assert_called_once_with()
    self.connection['db1'].command.assert_any_call('dbStats')
    self.connection['db1'].command.assert_any_call('collstats', 'collection1')
    assert (call('collstats', 'tmp.mr.tmp1') not in self.connection['db1'].command.call_args_list)
    metrics = {
        'databases.db1.collection1.key': 2,
    }
    self.assertPublishedMany(publish_mock, self)

dataset/ETHPy150Open BrightcoveOS/Diamond/src/collectors/mongodb/test/testmongodb.py TestMongoDBCollector.test_should_ignore_unneeded_collections/VarMisuse@211/339 `metrics`->`self`