source: PythonClient/src/client/ClientTest.py @ 80

Last change on this file since 80 was 80, checked in by stoda, 11 years ago

first commit

File size: 1.9 KB
Line 
1'''
2Created on 04/07/2013
3
4@author: sergi
5'''
6import unittest
7from Client import Client
8import time
9
10class Test(unittest.TestCase):
11    env = {'user': 'guest', 'pass':'guest', 'host' : 'localhost', 'port': 5672, 'exchange': 'rpc_exchange'}
12   
13    client = Client(env)
14
15    def testAsync(self):
16        self.client.async_call("calculator", "fibonacci", [10])
17   
18    def testSyncAdd(self):
19        x = 10
20        y = 5
21        expected = x + y
22        actual = self.client.sync_call("calculator", "add", [x, y])
23        self.assertEqual(expected, actual)
24   
25    def testMultiSyncAdd(self):
26        x = 20
27        y = 10
28        expected = x + y
29        actual = self.client.multi_sync_call("calculator", "add", [x, y], 2)
30        self.assertEqual(expected, actual[0])
31        self.assertEqual(expected, actual[1])
32       
33    def testPi(self):
34        expected = 3.1415
35        actual = self.client.sync_call("calculator", "getPi", [])
36        self.assertEqual(expected, actual)
37   
38    def testContact(self):
39        address = {"street":"calle falsa", "number":2, "town":"Tgn"}
40        emails = ["asdf@gmail.com", "asdf@hotmail.com"]
41   
42        name1 = "Superman"
43        contact = {"name":name1, "surname":"T", "phone":"1234", "age":21, "address": address, "emails":emails}
44        self.client.async_call("list", "setContact", [contact])
45        time.sleep(1)
46   
47        name2 = "Batman"
48        contact = {"name":name2, "surname":"S", "phone":"1234", "age":22, "address": address, "emails":emails}
49        self.client.async_call("list", "setContact", [contact])
50        time.sleep(1)
51   
52        clist = self.client.sync_call("list", "getContacts", [])
53        c1 = clist[0]
54        c2 = clist[1]
55       
56        self.assertEqual(name1, c1['name'])
57        self.assertEqual(name2, c2['name'])
58   
59if __name__ == "__main__":
60    # import sys;sys.argv = ['', 'Test.testName']
61    unittest.main()
Note: See TracBrowser for help on using the repository browser.