Subversion Repositories SmartDukaan

Rev

Rev 122 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
100 ashish 1
'''
2
Created on 25-Mar-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.config.client.ConfigClient import ConfigClient
7
from thrift.transport import TSocket
8
from thrift.transport.TTransport import TFramedTransport
9
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
10
from shop2020.thriftpy.model.v1.catalog import CatalogService
11
from shop2020.thriftpy.model.v1.catalog.ttypes import CatalogServiceException,\
12
    Category, Vendor
13
 
14
class TestClient:
15
 
16
    def __init__(self):
17
        config_client = ConfigClient()
18
        self.host = config_client.get_property('catalog_service_server_host')
19
        self.port = config_client.get_property('catalog_service_server_port')
20
        self.start()
21
    def start(self):
22
        try:
23
            self.transport = TSocket.TSocket(self.host, self.port)
24
            self.transport = TFramedTransport(self.transport)
25
            self.protocol = TBinaryProtocol(self.transport)
26
            self.client = CatalogService.Client(self.protocol)
27
            self.transport.open()
28
        except:
29
            raise CatalogServiceException(101, 'unable to load the client')
30
 
31
    def addCategory(self):
32
        cat = Category()
33
        cat.name = 'Entertainment'
34
        cat.addedOn = 12345678
35
        self.client.addCategory(cat)
36
        cats = self.client.getAllCategories()
37
        for category in cats:
38
            print category.name
39
 
40
 
41
    def addVendor(self):
42
        vend = Vendor()
43
        vend.name = 'Nokia'
44
        self.client.addVendor(vend)    
45
 
46
if __name__=='__main__':
47
    test = TestClient()
48
    test.addCategory()