00001
00002
00003
00004
00005
00006 import os, sys, unittest
00007 from ServiceTest import main, ServiceTestCase, ServiceTestSuite
00008 from ZSI import FaultException
00009 """
00010 Unittest for contacting google adwords
00011
00012 WSDL:
00013 """
00014
00015
00016 def dispatch():
00017 """Run all dispatch tests"""
00018 suite = ServiceTestSuite()
00019 suite.addTest(unittest.makeSuite(ServiceTest, 'test_dispatch'))
00020 return suite
00021
00022 def local():
00023 """Run all local tests"""
00024 suite = ServiceTestSuite()
00025 suite.addTest(unittest.makeSuite(ServiceTest, 'test_local'))
00026 return suite
00027
00028 def net():
00029 """Run all network tests"""
00030 suite = ServiceTestSuite()
00031 suite.addTest(unittest.makeSuite(ServiceTest, 'test_net'))
00032 return suite
00033
00034 def all():
00035 """Run all tests"""
00036 suite = ServiceTestSuite()
00037 suite.addTest(unittest.makeSuite(ServiceTest, 'test_'))
00038 return suite
00039
00040
00041 class TrafficEstimatorServiceTest(ServiceTestCase):
00042 """Test case for Google AdWords, sandbox v8
00043 Reads header information from a file "adwords.properties", need to format this for ConfigParser
00044
00045 [test_GoogleAdWords]
00046 email =
00047 password =
00048 useragent =
00049 applicationtoken =
00050
00051 """
00052 name = "test_GoogleAdWords"
00053 client_file_name = "TrafficEstimatorService_client.py"
00054 types_file_name = "TrafficEstimatorService_types.py"
00055 server_file_name = "TrafficEstimatorService_server.py"
00056
00057 header_info = os.path.join(os.getenv('HOME'), 'adwords.properties')
00058
00059 def __init__(self, methodName):
00060 ServiceTestCase.__init__(self, methodName)
00061 self.wsdl2py_args.append('-b')
00062
00063 def _get_soap_headers(self):
00064 from ConfigParser import ConfigParser
00065 cp = ConfigParser(); cp.read(self.header_info)
00066 p,e,a,u = map(lambda var: cp.get(self.__class__.name, var), 'password email applicationtoken useragent'.split())
00067 tns,GED = "https://adwords.google.com/api/adwords/v10", self.client_module.GED
00068
00069 password = GED(tns, "password").pyclass(p)
00070 email = GED(tns, "email").pyclass(e)
00071 atoken = GED(tns, "applicationToken").pyclass(a)
00072 useragent = GED(tns, "useragent").pyclass(u)
00073
00074
00075 dtoken = GED(tns, "developerToken").pyclass('%s++USD' %e)
00076 cemail = GED(tns, "clientEmail").pyclass('client_1+'+e)
00077
00078 return (email, password, useragent, dtoken, atoken, cemail)
00079
00080 def test_net_KeywordEstimate(self):
00081 loc = self.client_module.TrafficEstimatorServiceLocator()
00082 port = loc.getTrafficEstimatorService(**self.getPortKWArgs())
00083 msg = self.client_module.estimateKeywordListRequest()
00084
00085 kwd = msg.new_keywordRequests()
00086 kwd.Text = "flowers"
00087 kwd.MaxCpc = 50000L
00088 kwd.Type = "Broad"
00089 msg.KeywordRequests = [ kwd ]
00090
00091 rsp = port.estimateKeywordList(msg, soapheaders=self._get_soap_headers())
00092
00093 ServiceTest = TrafficEstimatorServiceTest
00094
00095 if __name__ == "__main__" :
00096 main()
00097