~facundo/filesync-server/trunk

« back to all changes in this revision

Viewing changes to lib/metrics/tests/__init__.py

  • Committer: Facundo Batista
  • Date: 2015-08-05 13:10:02 UTC
  • Revision ID: facundo@taniquetil.com.ar-20150805131002-he7b7k704d8o7js6
First released version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2008-2015 Canonical
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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/>.
 
15
#
 
16
# For further info, check  http://launchpad.net/filesync-server
 
17
 
 
18
"""Utilities for testing code."""
 
19
 
 
20
from collections import defaultdict
 
21
 
 
22
 
 
23
class FakeMetrics(object):
 
24
    """Fake metrics behavior"""
 
25
 
 
26
    def __init__(self):
 
27
        self.namespace = None
 
28
        self.user = None
 
29
        self.mode = None
 
30
        self.meters = defaultdict(int)
 
31
 
 
32
    def meter(self, name, count=1, sample_rate=1):
 
33
        """Record call to meter()."""
 
34
        self.meters[name] += count
 
35
 
 
36
    def increment(self, counter):
 
37
        """Fake increment."""
 
38
        return
 
39
 
 
40
    def report(self, namespace, user, mode):
 
41
        """Fake report method"""
 
42
        self.namespace = namespace
 
43
        self.user = user
 
44
        self.mode = mode
 
45
 
 
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)