Ejemplo n.º 1
0
 def test_PASS(self):
     cit = CitConn()
     cit.USER('test')
     expected = ('test', '3', '5', '0', '15888', '2', '1128198236')[0]
     actual = cit.PASS('testing')[0]
     self.assertEqual(expected, actual)
     cit.QUIT()
Ejemplo n.º 2
0
    def setUp(self):
        self.cit = CitConn()
        self.cit._listen = 0
        self.cit.USER('test')
        self.cit.PASS('testing')

        # bootstrapping a bit here
        self.rmmsgs()
Ejemplo n.º 3
0
 def test_LOUT(self):
     cit = CitConn()
     cit.USER('test')
     cit.PASS('testing')
     expected = None
     actual = cit.LOUT()
     self.assertEqual(expected, actual)
     cit.QUIT()
Ejemplo n.º 4
0
class Citadel:
    """Represent a citadel server.

    This offers a higher level of abstraction than CitConn.

    """
    def __init__(self, host=u'localhost', port=504):
        self.host = host
        self.port = port
        self.cit = CitConn(host, port)

    def __repr__(self):
        return u"<Citadel at %s:%d>" % (self.host, self.port)

    __str__ = __repr__

    # Users
    # =====

    def login(self, username, password):
        self.cit.USER(username)
        self.cit.PASS(password)

    def logout(self):
        self.cit.LOUT()

    def keep_alive(self):
        self.cit.NOOP()

    def close(self):
        self.cit.QUIT()

    # Floors
    # ======

    def floors(self, d=False):
        raw = self.cit.LFLR()
        floors = {}
        for floor in raw:
            floors[floor[1]] = (floor[0], floor[2])
        return d and floors or floors.keys()

    def __getattr__(self, name):
        """Return a floor object.
        """
        floors = self.floors(1)
        if name in floors:
            return Floor(self.cit, name, floors[name][0])
        else:
            raise AttributeError(u"No known floor named %s" % name)

    def __getitem__(self, key):
        """Return a floor object.
        """
        try:
            return getattr(self, key)
        except AttributeError:
            raise KeyError(u"No known floor named %s" % name)
Ejemplo n.º 5
0
class TestCitConn(unittest.TestCase):


    def setUp(self):
        self.cit = CitConn()
        self.cit.USER('test')
        self.cit.PASS('testing')

    def tearDown(self):
        self.cit.LOUT()
        self.cit.QUIT()



    def test_LFLR(self):
        expected = (0, 'Main Floor', 17)
        floors = self.cit.LFLR()
        self.assert_(len(floors) == 1)
        actual = floors[0]
        self.assertEqual(expected, actual)

    def test_LFLR_notLoggedIn(self):
        self.cit.LOUT()
        self.assertRaises(CitError, self.cit.LFLR)
Ejemplo n.º 6
0
 def setUp(self):
     self.cit = CitConn()
     #self.cit._listen = True
     self.cit.USER('test')
     self.cit.PASS('testing')
Ejemplo n.º 7
0
class TestRooms(unittest.TestCase):
    def setUp(self):
        self.cit = CitConn()
        #self.cit._listen = True
        self.cit.USER('test')
        self.cit.PASS('testing')

    def tearDown(self):
        self.cit.LOUT()
        self.cit.QUIT()

    def test_LR(self):
        rooms = self.cit.LKRA()
        mailroom = rooms[1]
        self.assertEqual(mailroom[0], 'Mail')
        self.assertEqual(mailroom[1].QR_PERMANENT, True)
        self.assertEqual(mailroom[1].QR_PRIVATE, False)
        self.assertEqual(mailroom[1].QR_PASSWORDED, False)
        self.assertEqual(mailroom[1].QR_GUESSNAME, False)
        self.assertEqual(mailroom[1].QR_DIRECTORY, False)
        self.assertEqual(mailroom[1].QR_UPLOAD, False)
        self.assertEqual(mailroom[1].QR_DOWNLOAD, False)
        self.assertEqual(mailroom[1].QR_VISDIR, False)
        self.assertEqual(mailroom[1].QR_ANONONLY, False)
        self.assertEqual(mailroom[1].QR_ANON2, False)
        self.assertEqual(mailroom[1].QR_NETWORK, False)
        self.assertEqual(mailroom[1].QR_PREFONLY, True)
        self.assertEqual(mailroom[1].QR_READONLY, True)
        self.assertEqual(mailroom[2].QR2_SYSTEM, False)
        self.assertEqual(mailroom[2].QR2_SELFLIST, False)
        self.assertEqual(mailroom[3], 0)
        self.assertEqual(mailroom[4], 0)
        self.assertEqual(mailroom[5].UA_KNOWN, True)
        self.assertEqual(mailroom[5].UA_GOTOALLOWED, True)
        self.assertEqual(mailroom[5].UA_HASNEWMSGS, True)
        self.assertEqual(mailroom[5].UA_ZAPPED, False)

    def test_LR_notLoggedIn(self):
        self.cit.LOUT()
        self.assertRaises(CitError, self.cit.LKRA)

    def test_LKRA(self):
        expected = [
            'Contacts', 'Mail', 'Sent Items', 'Aide', 'Global Address Book',
            'Lobby', 'Trashcan'
        ]
        actual = [r[0] for r in self.cit.LKRA()]
        self.assertEqual(expected, actual)

    def test_LZRM(self):
        expected = []
        actual = [r[0] for r in self.cit.LZRM()]
        self.assertEqual(expected, actual)

    def test_LKRN(self):
        expected = ['Mail', 'Aide', 'Global Address Book', 'Lobby']
        actual = [r[0] for r in self.cit.LKRN()]
        self.assertEqual(expected, actual)

    def test_LKRO(self):
        expected = ['Contacts', 'Sent Items', 'Trashcan']
        actual = [r[0] for r in self.cit.LKRO()]
        self.assertEqual(expected, actual)

    def test_LPRM(self):
        expected = ['Lobby', 'Trashcan']
        actual = [r[0] for r in self.cit.LPRM()]
        self.assertEqual(expected, actual)

    def test_LRMS(self):
        expected = [
            'Contacts', 'Mail', 'Sent Items', 'Aide', 'Global Address Book',
            'Lobby', 'Trashcan'
        ]
        actual = [r[0] for r in self.cit.LRMS()]
        self.assertEqual(expected, actual)
Ejemplo n.º 8
0
class Tests(unittest.TestCase):


    def setUp(self):
        self.cit = CitConn()
        self.cit._listen = 0
        self.cit.USER('test')
        self.cit.PASS('testing')

        # bootstrapping a bit here
        self.rmmsgs()

    def tearDown(self):
        self.cit.LOUT()
        self.cit.QUIT()

    def addmsg(self):
        self.cit.ENT0(subject='cheese', message = 'BLAM!!!!!!!')

    def addmsgs(self, r):
        for i in range(r):
            self.addmsg()
        self.assert_(len(self.cit.MSGS()) == r)

    def rmmsgs(self):
        for msgnum in self.cit.MSGS():
            self.cit.DELE(msgnum)


    # DELE

    def test_DELE(self):
        self.addmsgs(3)
        for message in self.cit.MSGS():
            self.cit.DELE(message)
        self.assert_(len(self.cit.MSGS()) == 0)

    def test_DELE_takesInt(self):
        self.addmsgs(1)
        for msgnum in self.cit.MSGS():
            self.assert_(isinstance(msgnum, int))
            self.cit.DELE(msgnum)
        self.assert_(len(self.cit.MSGS()) == 0)

    def test_DELE_takesLongInt(self):
        self.addmsgs(1)
        for msgnum in self.cit.MSGS():
            msgnum = long(msgnum)
            self.assert_(isinstance(msgnum, long))
            self.cit.DELE(msgnum)
        self.assert_(len(self.cit.MSGS()) == 0)

    def test_DELE_otherTypesFail(self):
        self.assertRaises(TypeError, self.cit.DELE, 'foo')
        self.assertRaises(TypeError, self.cit.DELE, None)
        self.assertRaises(TypeError, self.cit.DELE, [])
        self.assertRaises(TypeError, self.cit.DELE, 4.5)


    # ENT0

    def test_ENT0(self):
        self.cit.ENT0(subject="cheese", message='BLAM!!!!!!!!!!!')
        messages = self.cit.MSGS()
        self.assertEqual(len(messages), 1)

    def test_ENT0_badPost(self):
        self.assertRaises( ValueError
                         , self.cit.ENT0
                         , post=None
                          )

    def test_ENT0_badTo(self):
        self.assertRaises( TypeError
                         , self.cit.ENT0
                         , to=None
                          )

    def test_ENT0_200(self):
        val = self.cit.ENT0(0, subject="cheese", message='BLAM!!!!!!!!!!!')
        self.assertEqual(('',), val)

    def _test_ENT0_200_error(self):
        # Not quite sure how to trigger this yet.
        pass

    def test_ENT0_400(self):
        val = self.cit.ENT0(subject="cheese", message='BLAM!!!!!!!!!!!')
        self.assertEqual(None, val)

    def test_ENT0_800_success(self):
        expected = (879, 'Message accepted.', '')
        actual = self.cit.ENT0(confirm=True, subject="cheese", message='BLAM!')
        self.assertEqual(int, type(actual[0]))
        self.assertEqual(expected[1:], actual[1:])

    def _test_ENT0_800_failure(self):
        # Not quite sure how to trigger this yet.
        pass


    # MSGx

    def test_MSG0(self):
        self.addmsg()
        msgnum = self.cit.MSGS()[0]
        expected = ({ 'node': 'josemaria'
                    , 'from': 'test'
                    , 'room': 'Lobby'
                    , 'hnod': 'Josemaria'
                    , 'subj': 'cheese'
                    , 'time': '1128617111'
                    , 'path': 'cit2'
                    , 'msgn': '*****@*****.**'
                   #, 'type': '0'}, 'BLAM!!!!!!!\n') blemish in Citadel\UX
                    , 'type': '0'}, 'BLAM!!!!!!! \n')
        actual = self.cit.MSG0(msgnum)
        self.assertEqual(expected[0]['from'], actual[0]['from'])
        self.assertEqual(expected[1], actual[1])


    # MSG1

    def test_MSG1(self):
        # This mostly tests CitError actually :^)
        self.assertRaises(CitError, self.cit.MSG1)
        try:
            self.cit.MSG1()
        except CitError, err:
            self.assertEqual(str(err), "[530] Command not supported.")
Ejemplo n.º 9
0
 def __init__(self, host=u'localhost', port=504):
     self.host = host
     self.port = port
     self.cit = CitConn(host, port)
Ejemplo n.º 10
0
 def setUp(self):
     self.cit = CitConn()
     self.cit.USER('test')
     self.cit.PASS('testing')
Ejemplo n.º 11
0
 def test_PASS_badPassword(self):
     cit = CitConn()
     actual = cit.USER('test')
     self.assertRaises(CitError, cit.PASS, 'bad password!')
     cit.QUIT()
Ejemplo n.º 12
0
 def test_USER_notThere(self):
     cit = CitConn()
     self.assertRaises(CitError, cit.USER, 'not-there!')
     cit.QUIT()
Ejemplo n.º 13
0
 def test_USER(self):
     cit = CitConn()
     expected = None
     actual = cit.USER('test')
     self.assertEqual(expected, actual)
     cit.QUIT()
Ejemplo n.º 14
0
 def test_NOOP(self):
     cit = CitConn()
     expected = None
     actual = cit.NOOP()
     self.assertEqual(expected, actual)
Ejemplo n.º 15
0
 def test_QUIT(self):
     cit = CitConn()
     cit.QUIT()
     expected = None
     actual = cit._sock
     self.assertEqual(expected, actual)
Ejemplo n.º 16
0
 def testConnection(self):
     cit = CitConn()
     expected = '127.0.0.1'
     actual = cit._sock.getsockname()[0]
     self.assertEqual(expected, actual)
     cit._sock.close()