applicationtest.py :  » IRC » Skype4Py » Skype4Py-1.0.32.0 » unittests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IRC » Skype4Py 
Skype4Py » Skype4Py 1.0.32.0 » unittests » applicationtest.py
import unittest

import skype4pytest
from Skype4Py.application import *


class ApplicationTest(skype4pytest.TestCase):
    def setUpObject(self):
        self.obj = Application(self.skype, 'spam')

    # Methods
    # =======

    def testConnect(self):
        # Returned type: ApplicationStream or None
        self.api.enqueue('GET APPLICATION spam STREAMS',
                         'APPLICATION spam STREAMS')
        self.api.enqueue('ALTER APPLICATION spam CONNECT eggs')
        self.api.schedule(0.1, 'APPLICATION spam STREAMS eggs:1')
        t = self.obj.Connect('eggs', WaitConnected=True)
        self.assertInstance(t, ApplicationStream)
        self.assertEqual(t.Handle, 'eggs:1')
        self.failUnless(self.api.is_empty())

    def testCreate(self):
        self.api.enqueue('CREATE APPLICATION spam')
        self.obj.Create()
        self.failUnless(self.api.is_empty())

    def testDelete(self):
        self.api.enqueue('DELETE APPLICATION spam')
        self.obj.Delete()
        self.failUnless(self.api.is_empty())

    def testSendDatagram(self):
        self.api.enqueue('GET APPLICATION spam STREAMS',
                         'APPLICATION spam STREAMS eggs:1')
        self.api.enqueue('ALTER APPLICATION spam DATAGRAM eggs:1 sausage')
        self.obj.SendDatagram('sausage')
        self.failUnless(self.api.is_empty())

    # Properties
    # ==========

    def testConnectableUsers(self):
        # Readable, Type: UserCollection
        self.api.enqueue('GET APPLICATION spam CONNECTABLE',
                         'APPLICATION spam CONNECTABLE eggs, ham')
        t = self.obj.ConnectableUsers
        self.assertInstance(t, UserCollection)
        self.assertEqual(len(t), 2)
        self.failUnless(self.api.is_empty())

    def testConnectingUsers(self):
        # Readable, Type: UserCollection
        self.api.enqueue('GET APPLICATION spam CONNECTING',
                         'APPLICATION spam CONNECTING eggs, ham, sausage')
        t = self.obj.ConnectingUsers
        self.assertInstance(t, UserCollection)
        self.assertEqual(len(t), 3)
        self.failUnless(self.api.is_empty())

    def testName(self):
        # Readable, Type: unicode
        t = self.obj.Name
        self.assertInstance(t, unicode)
        self.assertEqual(t, 'spam')

    def testReceivedStreams(self):
        # Readable, Type: ApplicationStreamCollection
        self.api.enqueue('GET APPLICATION spam RECEIVED',
                         'APPLICATION spam RECEIVED sausage:1 eggs:3')
        t = self.obj.ReceivedStreams
        self.assertInstance(t, ApplicationStreamCollection)
        self.assertEqual(len(t), 2)
        self.failUnless(self.api.is_empty())

    def _testSendingStreams(self):
        # Readable, Type: ApplicationStreamCollection
        self.api.enqueue('GET APPLICATION spam SENDING',
                         'APPLICATION spam SENDING eggs:2 ham:5 bacon:7')
        t = self.obj.SendingStreams
        self.assertInstance(t, ApplicationStreamCollection)
        self.assertEqual(len(t), 7)
        self.failUnless(self.api.is_empty())

    def testStreams(self):
        # Readable, Type: ApplicationStreamCollection
        self.api.enqueue('GET APPLICATION spam STREAMS',
                         'APPLICATION spam STREAMS bacon:1')
        t = self.obj.Streams
        self.assertInstance(t, ApplicationStreamCollection)
        self.assertEqual(len(t), 1)
        self.failUnless(self.api.is_empty())


class ApplicationStreamTest(skype4pytest.TestCase):
    def setUpObject(self):
        app = Application(self.skype, 'spam')
        self.obj = ApplicationStream(app, 'eggs:1')

    # Methods
    # =======

    def testDisconnect(self):
        self.api.enqueue('ALTER APPLICATION spam DISCONNECT eggs:1')
        self.obj.Disconnect()
        self.failUnless(self.api.is_empty())

    def testRead(self):
        # Returned type: unicode
        self.api.enqueue('ALTER APPLICATION spam READ eggs:1',
                         'ALTER APPLICATION spam READ eggs:1 ham')
        t = self.obj.Read()
        self.assertInstance(t, unicode)
        self.assertEqual(t, 'ham')
        self.failUnless(self.api.is_empty())

    def testSendDatagram(self):
        self.api.enqueue('ALTER APPLICATION spam DATAGRAM eggs:1 ham',
                         'ALTER APPLICATION spam DATAGRAM eggs:1')
        self.obj.SendDatagram('ham')
        self.failUnless(self.api.is_empty())

    def testWrite(self):
        self.api.enqueue('ALTER APPLICATION spam WRITE eggs:1 ham',
                         'ALTER APPLICATION spam WRITE eggs:1')
        self.obj.Write('ham')
        self.failUnless(self.api.is_empty())

    # Properties
    # ==========

    def testApplication(self):
        # Readable, Type: Application
        t = self.obj.Application
        self.assertInstance(t, Application)
        self.assertEqual(t.Name, 'spam')

    def testApplicationName(self):
        # Readable, Type: unicode
        t = self.obj.ApplicationName
        self.assertInstance(t, unicode)
        self.assertEqual(t, 'spam')

    def testDataLength(self):
        # Readable, Type: int
        self.api.enqueue('GET APPLICATION spam SENDING',
                         'APPLICATION spam SENDING')
        self.api.enqueue('GET APPLICATION spam RECEIVED',
                         'APPLICATION spam RECEIVED eggs:1=123')
        t = self.obj.DataLength
        self.assertInstance(t, int)
        self.assertEqual(t, 123)
        self.failUnless(self.api.is_empty())

    def testHandle(self):
        # Readable, Type: str
        t = self.obj.Handle
        self.assertInstance(t, str)
        self.assertEqual(t, 'eggs:1')

    def testPartnerHandle(self):
        # Readable, Type: str
        t = self.obj.PartnerHandle
        self.assertInstance(t, str)
        self.assertEqual(t, 'eggs')


def suite():
    return unittest.TestSuite([
        unittest.defaultTestLoader.loadTestsFromTestCase(ApplicationTest),
        unittest.defaultTestLoader.loadTestsFromTestCase(ApplicationStreamTest),
    ])


if __name__ == '__main__':
    unittest.main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.