1
# Copyright 2008-2015 Canonical
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
# For further info, check http://launchpad.net/filesync-server
18
"""Utilities for testing code."""
20
from collections import defaultdict
23
class FakeMetrics(object):
24
"""Fake metrics behavior"""
30
self.meters = defaultdict(int)
32
def meter(self, name, count=1, sample_rate=1):
33
"""Record call to meter()."""
34
self.meters[name] += count
36
def increment(self, counter):
40
def report(self, namespace, user, mode):
41
"""Fake report method"""
42
self.namespace = namespace
46
def make_all_assertions(self, testcase, namespace):
47
"""Make all the assertions on the metrics report."""
48
testcase.assertEqual(namespace, self.namespace)
49
testcase.assertEqual("d", self.mode)
50
# assertIsInstance is not always available
51
testcase.assertEqual(type(self.user), str)