def testCreateObjectWithoutOptionalParameters(self): self.setupDefaultSchemas() client = ResudsClient(FactoryTestCase.report_file, faults=False) criteria = client.create('PublisherRevenueCriteria') criteria.startdate = '2013-05-03+00:00' criteria.enddate = '2013-06-03+00:00' criteria.publisherid = 50214056 envelope = self.getEnvelope( criteria, method='GetPublisherRevenueCSV', client=client) self.assertTrue('<criteria>' in envelope and '</criteria>' in envelope) self.assertTrue('<publisherId>50214056</publisherId>' in envelope) self.assertTrue('<startDate>2013-05-03+00:00</startDate>' in envelope) self.assertTrue('<endDate>2013-06-03+00:00</endDate>' in envelope) self.assertTrue('<endDate>2013-06-03+00:00</endDate>' in envelope) self.assertTrue('<adspaceId>' not in envelope)
def testComplicateCase(self): self.setupDefaultSchemas() with open(os.path.join(LOCALDIR, 'getReport.wsdl')) as fp: body = fp.read() HTTPretty.register_uri( HTTPretty.POST, 'http://localhost/publisher', body=body, status=200, ) client = ResudsClient('file://' + os.path.join(LOCALDIR, 'PublisherRevenueWS.wsdl'), faults=False) criteria = client.create('PublisherRevenueCriteria') criteria.publisherid = 1234 criteria.adspaceid = 1234 criteria.startdate = 12345 criteria.enddate = 12345 rev = client.GetPublisherRevenueCSV(name='', pwd='', operatorId='', criteria=criteria)
def testResponseErrorOnCreate(self): self.setupHttpPretty('responseError', status_code=500) client = ResudsClient(ResudsClientTestCase.wsdl_file) adspace = client.create('Adspace') adspace.externalid = '1' * 200 adspace.name = 'adspaceName' adspace.longtail = True adspace.mediachannelid = 2 adspace.publisherid = '' frt = self.client.create('FormatResourceType') frt.formatid = 300 adspace.formatresourcetypelist = [frt, ] try: res = client.CreateAdspace(name='', pwd='', operatorId='', Adspace=adspace) self.fail('Expect failing on create a adspace with too long externalid') except SoapException, e: self.assertEquals(e.message, u'EXTERNAL_ID_TOO_LONG [50]')
class FactoryTestCase(TestCase): wsdl_file = 'file://' + os.path.join(LOCALDIR, 'inventory_service.wsdl') report_file = 'file://' + os.path.join(LOCALDIR, 'PublisherRevenueWS.wsdl') def testIsList(self): import collections self.assertTrue(self.factory.is_list( collections.namedtuple('MyList', [])())) self.assertFalse(self.factory.is_list( collections.namedtuple('Object', [])())) def testRebuildNoneObject(self): self.assertEquals('', self.factory.rebuild(None)) def testRebuildPrimitiveType(self): self.assertEquals('12345', self.factory.rebuild(12345)) def testRebuildDateTime(self): import datetime self.assertEquals('2013-02-22 00:00:00', self.factory.rebuild( datetime.datetime(2013, 02, 22))) def testBuildEmptyList(self): self.assertEquals([], self.factory.build( self.client.client.factory, [])) def testBuildSimpleList(self): self.assertEquals([1, 4, 6, ], self.factory.build( self.client.client.factory, [1, 4, 6, ])) def testBuildComplicatedList(self): adspace = self.createAdspace() l = [adspace, ] self.assertEquals( '(AdspaceList){\n Adspace[] = \n (Adspace){\n FormatResourceTypeList = \n (FormatResourceTypeList){\n FormatResourceType[] = \n (FormatResourceType){\n ResourceTypeIdList = \n (EntityIdList){\n EntityId[] = \n 5,\n 6,\n }\n _FormatId = 5\n },\n }\n CategoryIdList = \n (EntityIdList){\n EntityId[] = \n 2345,\n 65432,\n }\n ExcludedTopicIdList = \n (EntityIdList){\n EntityId = None\n }\n _Id = ""\n _ExternalId = "externalId"\n _Name = "adspaceName"\n _Description = ""\n _PublisherId = ""\n _MediaChannelId = ""\n _PlacementWidth = ""\n _PlacementHeight = ""\n _Active = ""\n _LongTail = ""\n _EstDailyUsers = "1"\n _EstDailyImps = "1"\n _AllowCompanionFlights = ""\n _Test = "false"\n _SupportConvTracking = "false"\n _MinAllowedCPC = ""\n _MinAllowedCPM = ""\n },\n }', repr(self.factory.build(self.client.client.factory, l)) ) def testBuildSimpleObject(self): self.assertEquals('1', self.factory.build( self.client.client.factory, 1)) def testBuildComplicatedObject(self): adspace = self.createAdspace() envelope = self.getEnvelope(adspace) self.assertEquals( '<?xml version="1.0" encoding="UTF-8"?>\n<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://Amobee.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">\n <SOAP-ENV:Header/>\n <ns0:Body>\n <ns1:CreateAdspace>\n <name>name</name>\n <pwd>pwd</pwd>\n <operatorId>opId</operatorId>\n <Adspace ExternalId="externalId" Name="adspaceName" EstDailyUsers="1" EstDailyImps="1" Test="false" SupportConvTracking="false">\n <FormatResourceTypeList>\n <FormatResourceType FormatId="5">\n <ResourceTypeIdList>\n <EntityId>5</EntityId>\n <EntityId>6</EntityId>\n </ResourceTypeIdList>\n </FormatResourceType>\n </FormatResourceTypeList>\n <CategoryIdList>\n <EntityId>2345</EntityId>\n <EntityId>65432</EntityId>\n </CategoryIdList>\n </Adspace>\n </ns1:CreateAdspace>\n </ns0:Body>\n</SOAP-ENV:Envelope>', envelope ) def testCreateAdspaceSoapObject(self): self.setupDefaultSchemas() adspace = self.createAdspace() self.assertEquals(adspace.cls_name, 'Adspace') envelope = self.getEnvelope(adspace) self.assertEquals( '<?xml version="1.0" encoding="UTF-8"?>\n<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://Amobee.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">\n <SOAP-ENV:Header/>\n <ns0:Body>\n <ns1:CreateAdspace>\n <name>name</name>\n <pwd>pwd</pwd>\n <operatorId>opId</operatorId>\n <Adspace ExternalId="externalId" Name="adspaceName" EstDailyUsers="1" EstDailyImps="1" Test="false" SupportConvTracking="false">\n <FormatResourceTypeList>\n <FormatResourceType FormatId="5">\n <ResourceTypeIdList>\n <EntityId>5</EntityId>\n <EntityId>6</EntityId>\n </ResourceTypeIdList>\n </FormatResourceType>\n </FormatResourceTypeList>\n <CategoryIdList>\n <EntityId>2345</EntityId>\n <EntityId>65432</EntityId>\n </CategoryIdList>\n </Adspace>\n </ns1:CreateAdspace>\n </ns0:Body>\n</SOAP-ENV:Envelope>', envelope ) def testGetUnexistentProperty(self): adspace = self.createAdspace() self.assertRaises(AttributeError, getattr, adspace, 'dummy') def testSetUnexistentProperty(self): adspace = self.createAdspace() self.assertRaises( AttributeError, setattr, adspace, 'dummy', 'dummyvalue') def testChangeObjectProperty(self): adspace = self.createAdspace() adspace.name = 'NewName' self.assertEquals('NewName', adspace.name) def testAddListToObject(self): adspace = self.createAdspace() self.assertEquals( 5, adspace.formatresourcetypelist[0].formatid ) self.assertEquals( [5, 6, ], adspace.formatresourcetypelist[ 0].resourcetypeidlist.entityid ) def testEntityIdList(self): adspace = self.client.create('Adspace') adspace.categoryidlist.entityid = [1, 2, 3, 4, ] envelope = self.getEnvelope(adspace) self.assertTrue('<CategoryIdList>' in envelope) self.assertTrue('<EntityId>1</EntityId>' in envelope) self.assertTrue('<EntityId>2</EntityId>' in envelope) self.assertTrue('<EntityId>3</EntityId>' in envelope) self.assertTrue('<EntityId>4</EntityId>' in envelope) self.assertTrue('</CategoryIdList>' in envelope) @httprettified def testCreateObjectWithoutOptionalParameters(self): self.setupDefaultSchemas() client = ResudsClient(FactoryTestCase.report_file, faults=False) criteria = client.create('PublisherRevenueCriteria') criteria.startdate = '2013-05-03+00:00' criteria.enddate = '2013-06-03+00:00' criteria.publisherid = 50214056 envelope = self.getEnvelope( criteria, method='GetPublisherRevenueCSV', client=client) self.assertTrue('<criteria>' in envelope and '</criteria>' in envelope) self.assertTrue('<publisherId>50214056</publisherId>' in envelope) self.assertTrue('<startDate>2013-05-03+00:00</startDate>' in envelope) self.assertTrue('<endDate>2013-06-03+00:00</endDate>' in envelope) self.assertTrue('<endDate>2013-06-03+00:00</endDate>' in envelope) self.assertTrue('<adspaceId>' not in envelope) def testEntityIsListToString(self): entityIdList = EntityIdList(['value1', 'value2']) self.assertEquals( '<EntityId>value1</EntityId><EntityId>value2</EntityId>', str(entityIdList)) @httprettified def setUp(self): self.setupDefaultSchemas() self.client = ResudsClient(FactoryTestCase.wsdl_file, faults=False) self.factory = Factory def getEnvelope(self, obj, method='CreateAdspace', client=None): if not client: client = self.client soapObject = Factory.build(client.client.factory, obj) method = getattr(client.client.service, method) c = SoapClient(method.client, method.method) return str(c.method.binding.input.get_message(c.method, ('name', 'pwd', 'opId', soapObject, ), {})) def setupDefaultSchemas(self): with open(os.path.join(LOCALDIR, 'XMLSchema.xsd')) as fp: body = fp.read() HTTPretty.register_uri( HTTPretty.GET, 'http://www.w3.org/2001/XMLSchema.xsd', body=body) with open(os.path.join(LOCALDIR, 'xml.xsd')) as fp: body = fp.read() HTTPretty.register_uri( HTTPretty.GET, 'http://www.w3.org/2001/xml.xsd', body=body) def createAdspace(self): adspace = self.client.create('Adspace') adspace.name = 'adspaceName' adspace.externalid = 'externalId' frt = self.client.create('FormatResourceType') frt.formatid = 5 rtil = self.client.create('ResourceTypeIdList') rtil.entityid = [5, 6, ] frt.resourcetypeidlist = rtil adspace.formatresourcetypelist = [frt, ] cil = self.client.create('CategoryIdList') cil.entityid = [2345, 65432] adspace.categoryidlist = cil return adspace
class ResudsClientTestCase(TestCase): wsdl_file = 'file://' + os.path.join(LOCALDIR, 'inventory_service.wsdl') @httprettified def setUp(self): self.setupDefaultSchemas() self.client = ResudsClient(ResudsClientTestCase.wsdl_file, faults=False) def testGetMethods(self): self.assertEquals( self.client.methods, { 'SearchCategoryByCriteria': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('categoryCriteria', 'categoryCriteria')], 'SearchAdspaceByCriteria': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('adspaceCriteria', 'adspaceCriteria')], 'GetCategoryList': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int')], 'UpdateAdspace': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('Adspace', 'Adspace')], 'CreateAdspace': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('Adspace', 'Adspace')], 'UpdateCategory': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('Category', 'Category')], 'GetAdSpaceList': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int')], 'DeleteCategory': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('categoryId', 'int')], 'GetContextualCategoryList': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int')], 'GetAdSpaceByExternalId': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('externalId', 'string')], 'GetCategoryGroupList': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int')], 'GetCategoryById': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('categoryId', 'int')], 'DeleteAdSpace': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('adSpaceId', 'int')], 'GetAdSpaceById': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('adSpaceId', 'int')], 'CreateCategory': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('Category', 'Category')], 'GetAdSpaceSalesHouses': [('name', 'string'), ('pwd', 'string'), ('operatorId', 'int'), ('adSpaceId', 'int')] } ) def testUnexistentMethod(self): self.assertRaises(NotImplementedError, getattr, self.client, 'unexistentMethod') @httprettified def testNoSendRequest(self): self.setupDefaultSchemas() client = ResudsClient(ResudsClientTestCase.wsdl_file, nosend=True) res = client.GetAdSpaceList(name='', pwd='', operatorId='') self.assertEquals(res.__class__, RequestContext) @httprettified def testFaultRequest(self): self.setupHttpPretty('GetAdSpaceById') client = ResudsClient(ResudsClientTestCase.wsdl_file, faults=True) adspace_id = 32645 res = client.GetAdSpaceById(name='', pwd='', operatorId='', adSpaceId=adspace_id) self.assertEquals(res.cls_name, 'Adspace') @httprettified def testWebFaultExceptionOnHttpError(self): self.setupHttpPretty('InvalidGetAdSpaceById', status_code=500) client = ResudsClient(ResudsClientTestCase.wsdl_file, faults=True) adspace_id = 1234567890 self.assertRaises(SoapException, client.GetAdSpaceById, name='', pwd='', operatorId='', adSpaceId=adspace_id) @httprettified def testGetObjectList(self): self.setupHttpPretty('GetAdSpaceList') adspacelist = self.client.GetAdSpaceList(name='', pwd='', operatorId='') self.assertEquals(len(adspacelist), 3) self.assertEquals([adspace.cls_name for adspace in adspacelist], ['Adspace', ] * len(adspacelist)) @httprettified def testGetObject(self): self.setupHttpPretty('GetAdSpaceById') adspace_id = 32645 adspace = self.client.GetAdSpaceById(name='', pwd='', operatorId='', adSpaceId=adspace_id) self.assertEquals(adspace.id, adspace_id) @httprettified def testCreateAdspace(self): self.setupHttpPretty('CreateAdspace') adspace = self.client.create('Adspace') frt = self.client.create('FormatResourceType', formatid=5, resourcetypeidlist=[5, 6, ]) frtl = [frt, ] adspace.formatresourcetypelist = frtl adspace.name = 'adspaceName' adspace.longtail = 1 res = self.client.CreateAdspace(name='', pwd='', operatorId='', Adspace=adspace) self.assertTrue(res.isdigit()) @httprettified def testNoneTypeObjectInRebuild(self): self.setupHttpPretty('deleteAdspace') self.client.DeleteAdSpace(name='', pwd='', operatorId='', adSpaceId=123456) @httprettified def testComplicateCase(self): self.setupDefaultSchemas() with open(os.path.join(LOCALDIR, 'getReport.wsdl')) as fp: body = fp.read() HTTPretty.register_uri( HTTPretty.POST, 'http://localhost/publisher', body=body, status=200, ) client = ResudsClient('file://' + os.path.join(LOCALDIR, 'PublisherRevenueWS.wsdl'), faults=False) criteria = client.create('PublisherRevenueCriteria') criteria.publisherid = 1234 criteria.adspaceid = 1234 criteria.startdate = 12345 criteria.enddate = 12345 rev = client.GetPublisherRevenueCSV(name='', pwd='', operatorId='', criteria=criteria) @httprettified def testObjectListWithObjectAsChild(self): self.setupDefaultSchemas() with open(os.path.join(LOCALDIR, 'getFlightList.wsdl')) as fp: body = fp.read() HTTPretty.register_uri( HTTPretty.POST, 'http://localhost/campaign', body=body, status=200, ) client = ResudsClient('file://' + os.path.join(LOCALDIR, 'CampaignWS.wsdl')) l = client.GetFlightList(name='', pwd='', operatorId='') @httprettified def testResponseErrorOnCreate(self): self.setupHttpPretty('responseError', status_code=500) client = ResudsClient(ResudsClientTestCase.wsdl_file) adspace = client.create('Adspace') adspace.externalid = '1' * 200 adspace.name = 'adspaceName' adspace.longtail = True adspace.mediachannelid = 2 adspace.publisherid = '' frt = self.client.create('FormatResourceType') frt.formatid = 300 adspace.formatresourcetypelist = [frt, ] try: res = client.CreateAdspace(name='', pwd='', operatorId='', Adspace=adspace) self.fail('Expect failing on create a adspace with too long externalid') except SoapException, e: self.assertEquals(e.message, u'EXTERNAL_ID_TOO_LONG [50]')