def setUp(self):
        """Prepare unittest."""
        print self.id()
        if not self.__class__.service:
            self.__class__.service = client.GetOrderService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

        if self.__class__.advertiser_id == '0':
            company = {
                'name': 'Company #%s' % Utils.GetUniqueName(),
                'type': 'ADVERTISER'
            }
            self.__class__.advertiser_id = client.GetCompanyService(
                self.__class__.SERVER, self.__class__.VERSION,
                HTTP_PROXY).CreateCompany(company)[0]['id']

        if self.__class__.trafficker_id == '0':
            filter_statement = {'query': 'ORDER BY name LIMIT 500'}
            users = client.GetUserService(
                self.__class__.SERVER, self.__class__.VERSION,
                HTTP_PROXY).GetUsersByStatement(filter_statement)
            for user in users[0]['results']:
                if user['roleName'] in ('Salesperson', ):
                    self.__class__.salesperson_id = user['id']
                    continue
                elif user['roleName'] in ('Trafficker', ):
                    self.__class__.trafficker_id = user['id']
                    continue
  def testUpperStackLogging(self):
    """Tests whether we can define logger at client level and log before and
    after the API request is made.
    """
    logger = logging.getLogger(self.__class__.__name__)
    logger.setLevel(logging.DEBUG)
    fh = logging.FileHandler(self.__class__.TMP_LOG)
    fh.setLevel(logging.DEBUG)
    logger.addHandler(fh)

    # Clean up temporary log file.
    Utils.PurgeLog(self.__class__.TMP_LOG)

    logger.debug(self.__class__.DEBUG_MSG1)
    user_service = client.GetUserService(
        self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
    user_service.GetAllRoles()
    logger.debug(self.__class__.DEBUG_MSG2)

    data = Utils.ReadFile(self.__class__.TMP_LOG)
    self.assertEqual(data.find(self.__class__.DEBUG_MSG1), 0)
    self.assertEqual(data.find(self.__class__.DEBUG_MSG2),
                     len(self.__class__.DEBUG_MSG1) + 1)

    # Clean up and remove temporary log file.
    Utils.PurgeLog(self.__class__.TMP_LOG)
    os.remove(self.__class__.TMP_LOG)
 def run(self):
     """Represent thread's activity."""
     statement = {'query': 'ORDER BY name LIMIT 500'}
     DfpWebServiceTestV201103.res.append(
         client.GetUserService(DfpWebServiceTestV201103.SERVER,
                               DfpWebServiceTestV201101.VERSION,
                               HTTP_PROXY).GetUsersByStatement(statement))
 def testCallMethod(self):
     """Test whether we can call an API method indirectly."""
     filter_statement = {'query': 'ORDER BY name LIMIT 500'}
     self.assert_(
         isinstance(
             client.GetUserService(
                 self.__class__.SERVER, self.__class__.VERSION,
                 HTTP_PROXY).GetUsersByStatement(filter_statement), tuple))
    def setUp(self):
        """Prepare unittest."""
        print self.id()
        if not self.__class__.service:
            self.__class__.service = client.GetLineItemService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

        if self.__class__.order_id == '0':
            company = {
                'name': 'Company #%s' % Utils.GetUniqueName(),
                'type': 'ADVERTISER'
            }
            advertiser_id = client.GetCompanyService(
                self.__class__.SERVER, self.__class__.VERSION,
                HTTP_PROXY).CreateCompany(company)[0]['id']
            filter_statement = {'query': 'ORDER BY name LIMIT 500'}
            users = client.GetUserService(
                self.__class__.SERVER, self.__class__.VERSION,
                HTTP_PROXY).GetUsersByStatement(filter_statement)
            trafficker_id = '0'
            for user in users[0]['results']:
                if user['roleName'] in ('Trafficker', ):
                    trafficker_id = user['id']
                    break
            order = {
                'advertiserId': advertiser_id,
                'currencyCode': 'USD',
                'name': 'Order #%s' % Utils.GetUniqueName(),
                'traffickerId': trafficker_id
            }
            self.__class__.order_id = client.GetOrderService(
                self.__class__.SERVER, self.__class__.VERSION,
                HTTP_PROXY).CreateOrder(order)[0]['id']

        if self.__class__.ad_unit_id == '0':
            inventory_service = client.GetInventoryService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            network_service = client.GetNetworkService(self.__class__.SERVER,
                                                       self.__class__.VERSION,
                                                       HTTP_PROXY)
            root_ad_unit_id = \
                network_service.GetCurrentNetwork()[0]['effectiveRootAdUnitId']
            ad_unit = {
                'name': 'Ad_Unit_%s' % Utils.GetUniqueName(),
                'parentId': root_ad_unit_id,
                'sizes': [{
                    'width': '300',
                    'height': '250'
                }],
                'description': 'Ad unit description.',
                'targetWindow': 'BLANK'
            }
            self.__class__.ad_unit_id = inventory_service.CreateAdUnit(
                ad_unit)[0]['id']
 def setUp(self):
     """Prepare unittest."""
     print self.id()
     if not self.__class__.service:
         self.__class__.service = client.GetUserService(
             self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
  def setUp(self):
    """Prepare unittest."""
    print self.id()
    if not self.__class__.service:
      self.__class__.service = client.GetLineItemCreativeAssociationService(
          self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

    if (not self.__class__.creative1 or not self.__class__.creative2 or
        not self.__class__.creative3):
      company = {
        'name': 'Company #%s' % Utils.GetUniqueName(),
        'type': 'ADVERTISER'
      }
      advertiser_id = client.GetCompanyService(
          self.__class__.SERVER, self.__class__.VERSION,
          HTTP_PROXY).CreateCompany(company)[0]['id']
      creatives = []
      for i in xrange(3):
        creatives.append({
            'type': 'ImageCreative',
            'name': 'Image Creative #%s' % Utils.GetUniqueName(),
            'advertiserId': advertiser_id,
            'destinationUrl': 'http://google.com',
            'imageName': 'image.jpg',
            'imageByteArray': self.__class__.IMAGE_DATA,
            'size': {'width': '300', 'height': '250'}
        })
      creatives = client.GetCreativeService(
          self.__class__.SERVER, self.__class__.VERSION,
          HTTP_PROXY).CreateCreatives(creatives)
      self.__class__.creative1 = creatives[0]
      self.__class__.creative2 = creatives[1]
      self.__class__.creative3 = creatives[2]

    if not self.__class__.line_item_id:
      filter_statement = {'query': 'ORDER BY name LIMIT 500'}
      user_service = client.GetUserService(
          self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
      users = user_service.GetUsersByStatement(filter_statement)
      trafficker_id = '0'
      for user in users[0]['results']:
        if user['roleName'] in ('Trafficker',):
          trafficker_id = user['id']
          break
      order = {
          'advertiserId': advertiser_id,
          'currencyCode': 'USD',
          'name': 'Order #%s' % Utils.GetUniqueName(),
          'traffickerId': trafficker_id
      }
      order_id = client.GetOrderService(
          self.__class__.SERVER, self.__class__.VERSION,
          HTTP_PROXY).CreateOrder(order)[0]['id']
      inventory_service = client.GetInventoryService(
          self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
      network_service = client.GetNetworkService(
          self.__class__.SERVER, self.__class__.VERSION,
          HTTP_PROXY)
      root_ad_unit_id = \
          network_service.GetCurrentNetwork()[0]['effectiveRootAdUnitId']
      ad_unit = {
          'name': 'Ad_Unit_%s' % Utils.GetUniqueName(),
          'parentId': root_ad_unit_id,
          'sizes': [{'width': '300', 'height': '250'}],
          'description': 'Ad unit description.',
          'targetWindow': 'BLANK'
      }
      ad_unit_id = inventory_service.CreateAdUnit(ad_unit)[0]['id']
      line_item = {
          'name': 'Line item #%s' % Utils.GetUniqueName(),
          'orderId': order_id,
          'targeting': {
              'inventoryTargeting': {
                  'targetedAdUnitIds': [ad_unit_id]
              }
          },
          'creativeSizes': [
              {'width': '300', 'height': '250'},
              {'width': '120', 'height': '600'}
          ],
          'lineItemType': 'STANDARD',
          'startDateTime': {
              'date': {
                  'year': '2011',
                  'month': '9',
                  'day': '1'
              },
              'hour': '0',
              'minute': '0',
              'second': '0'
          },
          'endDateTime': {
              'date': {
                  'year': '2011',
                  'month': '9',
                  'day': '30'
              },
              'hour': '0',
              'minute': '0',
              'second': '0'
          },
          'costType': 'CPM',
          'costPerUnit': {
              'currencyCode': 'USD',
              'microAmount': '2000000'
          },
          'creativeRotationType': 'EVEN',
          'discountType': 'PERCENTAGE',
          'unitsBought': '500000',
          'unitType': 'IMPRESSIONS'
      }
      self.__class__.line_item_id = client.GetLineItemService(
          self.__class__.SERVER, self.__class__.VERSION,
          HTTP_PROXY).CreateLineItem(line_item)[0]['id']
Exemple #8
0
    def setUp(self):
        """Prepare unittest."""
        print self.id()
        if not self.__class__.service:
            self.__class__.service = client.GetForecastService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

        if self.__class__.order_id == '0':
            company = {
                'name': 'Company #%s' % Utils.GetUniqueName(),
                'type': 'ADVERTISER'
            }
            advertiser_id = client.GetCompanyService(
                self.__class__.SERVER, self.__class__.VERSION,
                HTTP_PROXY).CreateCompany(company)[0]['id']
            filter_statement = {'query': 'ORDER BY name LIMIT 500'}
            users = client.GetUserService(
                self.__class__.SERVER, self.__class__.VERSION,
                HTTP_PROXY).GetUsersByStatement(filter_statement)
            trafficker_id = '0'
            for user in users[0]['results']:
                if user['roleName'] in ('Trafficker', ):
                    trafficker_id = user['id']
                    break
            order = {
                'advertiserId': advertiser_id,
                'currencyCode': 'USD',
                'name': 'Order #%s' % Utils.GetUniqueName(),
                'traffickerId': trafficker_id
            }
            self.__class__.order_id = client.GetOrderService(
                self.__class__.SERVER, self.__class__.VERSION,
                HTTP_PROXY).CreateOrder(order)[0]['id']

        if self.__class__.ad_unit_id == '0':
            inventory_service = client.GetInventoryService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            filter_statement = {'query': 'WHERE parentId IS NULL LIMIT 500'}
            root_ad_unit_id = inventory_service.GetAdUnitsByStatement(
                filter_statement)[0]['results'][0]['id']
            ad_unit = {
                'name': 'Ad_Unit_%s' % Utils.GetUniqueName(),
                'parentId': root_ad_unit_id,
                'sizes': [{
                    'width': '300',
                    'height': '250'
                }],
                'description': 'Ad unit description.',
                'targetWindow': 'BLANK'
            }
            self.__class__.ad_unit_id = inventory_service.CreateAdUnit(
                ad_unit)[0]['id']

        if self.__class__.line_item_id == '0':
            line_item_service = client.GetLineItemService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            line_item = {
                'name':
                'Line item #%s' % Utils.GetUniqueName(),
                'orderId':
                self.__class__.order_id,
                'targeting': {
                    'inventoryTargeting': {
                        'targetedAdUnitIds': [self.__class__.ad_unit_id]
                    }
                },
                'creativeSizes': [{
                    'width': '300',
                    'height': '250'
                }, {
                    'width': '120',
                    'height': '600'
                }],
                'lineItemType':
                'STANDARD',
                'startDateTime': {
                    'date': {
                        'year': '2011',
                        'month': '9',
                        'day': '1'
                    },
                    'hour': '0',
                    'minute': '0',
                    'second': '0'
                },
                'endDateTime': {
                    'date': {
                        'year': '2011',
                        'month': '9',
                        'day': '30'
                    },
                    'hour': '0',
                    'minute': '0',
                    'second': '0'
                },
                'costType':
                'CPM',
                'costPerUnit': {
                    'currencyCode': 'USD',
                    'microAmount': '2000000'
                },
                'creativeRotationType':
                'EVEN',
                'discountType':
                'PERCENTAGE',
                'unitsBought':
                '500000',
                'unitType':
                'IMPRESSIONS'
            }
            self.__class__.line_item_id = line_item_service.CreateLineItem(
                line_item)[0]['id']