File: test_accounts.py

package info (click to toggle)
minbif 1%3A1.0.5%2Bgit20150505-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 1,216 kB
  • sloc: cpp: 12,861; ansic: 2,145; perl: 692; python: 542; sh: 152; ruby: 96; makefile: 82
file content (74 lines) | stat: -rw-r--r-- 2,386 bytes parent folder | download | duplicates (4)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/python
# -*- coding: utf-8 -*-

"""
Minbif - IRC instant messaging gateway
Copyright(C) 2009 Romain Bignon

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""

import sys
import re

from test import Test, Instance

class TestAccounts(Test):
    NAME = 'accounts'
    INSTANCES = {'minbif1': Instance()}
    TESTS = ['addaccount', 'connected', 'editaccount', 'disconnect', 'removeaccount']

    def test_addaccount(self):
        if not self['minbif1'].create_account('jabber', channel='&minbif'):
            return False

        accounts = self['minbif1'].get_accounts()
        if len(accounts) == 1:
            acc = accounts.popitem()[1]
            return acc.proto == 'jabber'
        return False

    def test_connected(self):
        return self['minbif1'].wait_connected('jabber')

    def test_editaccount(self):
        # flush
        while self['minbif1'].readline():
            pass

        acc = self['minbif1'].get_full_account('jabber')
        require_tls = acc.options['require_tls']

        self['minbif1'].write("MAP edit jabber require_tls %s" % (require_tls == "true" and "false" or "true"))
        self['minbif1'].readmsg('NOTICE', 1)

        acc = self['minbif1'].get_full_account('jabber')
        return acc.options['require_tls'] == (require_tls == "true" and "false" or "true")

    def test_disconnect(self):
        self['minbif1'].write('SQUIT jabber')
        accounts = self['minbif1'].get_accounts()
        return accounts.popitem()[1].state == 'disconnected'

    def test_removeaccount(self):
        self['minbif1'].remove_account('jabber')
        accounts = self['minbif1'].get_accounts()
        return len(accounts) == 0

if __name__ == '__main__':
    test = TestAccounts()
    if test.run():
        sys.exit(0)
    else:
        sys.exit(1)