webtest.py :  » Network » Torrent-Swapper » swapper » 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 » Network » Torrent Swapper 
Torrent Swapper » swapper » webtest.py
from sys import argv,exit
from time import sleep

from Utility.helpers import getSocket


################################################################
#
# Class: Webclient
#
# Used to send commands to the webservice
#
################################################################
class WebClient:
    def __init__(self, ip, port):
        self.ip = ip
        self.port = port

    def sendmesg(self, mesg):
        HOST = self.ip          # The remote host
        PORT = self.port        # The same port as used by the server
        s = getSocket(HOST, PORT)
        if s is None:
            return "Can't connect ABC web service" 
            
        # if request is not close connection request
        # so it's torrent request copy .torrent
        # in backup torrent folder
        ##############################################
        s.send(mesg)
        retmesg = s.recv(5000)
        s.close()
        return retmesg

######## Test Function #########
if len(argv) != 4:
    print "Usage: webtest.py <unique key> <IP> <Port>"
    exit(0)
    
KEY     = argv[1]
IP      = argv[2]
PORT    = argv[3]

wc = WebClient(argv[2], argv[3])
print "--------------- Start Testing Web Service ---------------------"
print "Query Command : "
ret = wc.sendmesg("ID|"+ KEY + "\nQUERY|")
line = ret.split("\n")
key  = line[0].split("|")
dict = {}
for i in key:
    dict[i] = ""
if len(line) > 1:
    for i in range(1, len(line)-1):
        result = line[i].split("|")
        for j in range(0, len(key)):
            dict[key[j]] = result[j]
            print key[j] + " = " + dict[key[j]]
        print "--------"
        
print "---------------------------------------------------------------"
sleep(5)
print "Add Command : "
# TODO: find a new torrent url to use for this test that we know works
print wc.sendmesg("ID|"+ KEY + "\nADD|torrenturlthatworks")
print "---------------------------------------------------------------"
sleep(5)

print "Stop Command : "
print wc.sendmesg("ID|"+ KEY + "\nSTOP|a5051a665c837d56b21f5d612e15e9992fe68f27")
print "---------------------------------------------------------------"
sleep(5)

print "Queue Command : "
print wc.sendmesg("ID|"+ KEY + "\nQUEUE|a5051a665c837d56b21f5d612e15e9992fe68f27")
print "---------------------------------------------------------------"
sleep(5)

print "Stop Command : "
print wc.sendmesg("ID|"+ KEY + "\nSTOP|a5051a665c837d56b21f5d612e15e9992fe68f27")
print "---------------------------------------------------------------"
sleep(5)

print "Resume Command : "
print wc.sendmesg("ID|"+ KEY + "\nRESUME|a5051a665c837d56b21f5d612e15e9992fe68f27")
print "---------------------------------------------------------------"
sleep(5)

print "Clear Completed Command : "
print wc.sendmesg("ID|"+ KEY + "\nDELETE|COMPLETED")
print "---------------------------------------------------------------"
sleep(5)

print "Delete Command : "
print wc.sendmesg("ID|"+ KEY + "\nDELETE|a5051a665c837d56b21f5d612e15e9992fe68f27")
print "---------------------------------------------------------------"
sleep(5)
print "Query only filename, %ul/dl, dlsize"
print wc.sendmesg("ID|"+ KEY + "\nQUERY|filename,ratio,dlsize")
print "----------------------------------------------------------------"
sleep(5)
print "Try Query Error"
print wc.sendmesg("ID|"+KEY+"\nQUERY|filename,error,ratio")
print "----------------------------------------------------------------"
sleep(5)
print "Query ALL"
print wc.sendmesg("ID|"+ KEY + "\nQUERY|filename,progress,btstatus,eta,dlspeed,ulspeed,ratio,peers,seeds,copies,dlsize,ulsize,peeravgprogress,totalspeed,totalsize")
print "----------------------------------------------------------------"

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.