Subversion Repositories SmartDukaan

Rev

Rev 122 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 25-Mar-2010

@author: ashish
'''
from shop2020.config.client.ConfigClient import ConfigClient
from thrift.transport import TSocket
from thrift.transport.TTransport import TFramedTransport
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
from shop2020.thriftpy.model.v1.catalog import CatalogService
from shop2020.thriftpy.model.v1.catalog.ttypes import CatalogServiceException,\
    Category, Vendor

class TestClient:
    
    def __init__(self):
        config_client = ConfigClient()
        self.host = config_client.get_property('catalog_service_server_host')
        self.port = config_client.get_property('catalog_service_server_port')
        self.start()
    def start(self):
        try:
            self.transport = TSocket.TSocket(self.host, self.port)
            self.transport = TFramedTransport(self.transport)
            self.protocol = TBinaryProtocol(self.transport)
            self.client = CatalogService.Client(self.protocol)
            self.transport.open()
        except:
            raise CatalogServiceException(101, 'unable to load the client')
        
    def addCategory(self):
        cat = Category()
        cat.name = 'Entertainment'
        cat.addedOn = 12345678
        self.client.addCategory(cat)
        cats = self.client.getAllCategories()
        for category in cats:
            print category.name
        
        
    def addVendor(self):
        vend = Vendor()
        vend.name = 'Nokia'
        self.client.addVendor(vend)    

if __name__=='__main__':
    test = TestClient()
    test.addCategory()