File: xmpp_mocks.py

package info (click to toggle)
python-nbxmpp 6.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,340 kB
  • sloc: python: 19,639; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,236 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Module with dummy classes for unit testing of XMPP and related code.
"""

from unittest.mock import Mock


class MockConnection(Mock):
    """
    Class simulating Connection class from src/common/connection.py

    It is derived from Mock in order to avoid defining all methods
    from real Connection that are called from NBClient or Dispatcher
    ( _event_dispatcher for example)
    """

    def __init__(self, *args):
        self.connect_succeeded = True
        Mock.__init__(self, *args)

    def on_connect(self, success, *args):
        """
        Method called after connecting - after receiving <stream:features>
        from server (NOT after TLS stream restart) or connect failure
        """
        self.connect_succeeded = success

    def on_auth(self, con, auth):
        """
        Method called after authentication, regardless of the result.

        :Parameters:
                con : NonBlockingClient
                        reference to authenticated object
                auth : string
                        type of authetication in case of success ('old_auth', 'sasl') or
                        None in case of auth failure
        """
        self.auth_connection = con
        self.auth = auth