예제 #1
0
    def testWithPassedInCredential(self):
        """Tests the entire workflow of making a request against DFA.

    Uses a credential passed in to the constructor. Starts with no DFA token and
    has the library generate one.

    Since this library is tightly integrated with SOAPpy, this test mocks out
    the HTTP level rather than the SOAPpy proxy level.
    """
        oauth2_credential = OAuth2Credentials(ACCESS_TOKEN, CLIENT_ID,
                                              CLIENT_SECRET, REFRESH_TOKEN,
                                              None, OAUTH_URI, USER_AGENT)

        headers = {
            'userAgent': USER_AGENT,
            'Username': USER_NAME,
            'oauth2credentials': oauth2_credential,
            'appName': USER_AGENT
        }
        config = {'compress': False}
        client = DfaClient(headers=headers, config=config)

        placement_service = self._CreatePlacementService(client)

        page = self._MakeSoapRequest_NoDfaToken(placement_service)
        self.assertEquals(EXPECTED_RESULT, page)
예제 #2
0
    def testExpiredDfaToken(self):
        """Tests regenerating the DFA token once it has expired.

    Uses a credential passed in to the constructor. Starts with an expired DFA
    token and has the library regenerate it.

    Since this library is tightly integrated with SOAPpy, this test mocks out
    the HTTP level rather than the SOAPpy proxy level.
    """
        oauth2_credential = OAuth2Credentials(ACCESS_TOKEN, CLIENT_ID,
                                              CLIENT_SECRET, REFRESH_TOKEN,
                                              None, OAUTH_URI, USER_AGENT)

        headers = {
            'userAgent': USER_AGENT,
            'Username': USER_NAME,
            'oauth2credentials': oauth2_credential,
            'AuthToken': EXPIRED_TOKEN,
            'appName': USER_AGENT
        }
        config = {'compress': False}
        client = DfaClient(headers=headers, config=config)

        placement_service = self._CreatePlacementService(client)
        placement_service._config['compress'] = False

        page = self._MakeSoapRequest_ExpiredToken(placement_service)

        self.assertEquals(EXPECTED_RESULT, page)
  def testWithCachedRefreshToken(self):
    """Tests the entire workflow of making a request against DFA.

    Uses a cached refresh token to generate a credential. Starts with no DFA
    token and has the library generate one.

    Since this library is tightly integrated with SOAPpy, this test mocks out
    the HTTP level rather than the SOAPpy proxy level.
    """
    directory = self._CreateConfigPickles()

    try:
      with mock.patch(
          'oauth2client.client.OAuth2Credentials.refresh') as mock_refresh:
        client = DfaClient(path=directory)

        self.assertEquals(CLIENT_ID, client.oauth2credentials.client_id)
        self.assertEquals(CLIENT_SECRET, client.oauth2credentials.client_secret)
        self.assertEquals(REFRESH_TOKEN, client.oauth2credentials.refresh_token)

        def SetAccessToken(unused_http):
          client.oauth2credentials.access_token = ACCESS_TOKEN
        mock_refresh.side_effect = SetAccessToken

        placement_service = self._CreatePlacementService(client)

        page = self._MakeSoapRequest_NoDfaToken(placement_service)
        self.assertEquals(EXPECTED_RESULT, page)
        client.oauth2credentials.refresh.assert_called_once_with(mock.ANY)
    finally:
      shutil.rmtree(directory)
if len(sys.argv) != 5:
  print ('This program requires 4 command line arguments:\n'
         '\t1. DFA username\n\t2. DFA password\n'
         '\t3. Query ID number\n\t4. Output filename.\n')
  print ('Example usage: python rc_report.py username@dfa password456 12345 '
         'report.zip')
  sys.exit(1)

username = sys.argv[1]
password = sys.argv[2]
query_id = sys.argv[3]
output_file_name = sys.argv[4]

# Initialize client object.
client = DfaClient()
client._headers['Username'] = username
client._headers['Password'] = password

# Initialize appropriate service.
report_service = client.GetReportService(
    'http://advertisersapitest.doubleclick.net', 'v1.20')

# Create report request and submit it to the server.
report_request = {
    'queryId': query_id,
}
report_info = report_service.RunDeferredReport(report_request)[0]
print 'Report with ID \'%s\' has been scheduled.' % (report_info['reportId'])

report_request['reportId'] = report_info['reportId']
import os
import sys
sys.path.insert(0, os.path.join('..', '..', '..', '..'))

# Import appropriate classes from the client library.
from adspygoogle.dfa.DfaClient import DfaClient

QUERY_ID = 'INSERT_QUERY_ID_HERE'


def main(client, query_id):
    # Initialize appropriate service.
    report_service = client.GetReportService(
        'http://advertisersapitest.doubleclick.net', 'v1.19')

    # Create report search criteria structure.
    report_request = {'queryId': query_id}

    # Request generation of a report for your query.
    report_info = report_service.RunDeferredReport(report_request)[0]

    # Display success message.
    print 'Report with ID \'%s\' has been scheduled.' % (
        report_info['reportId'])


if __name__ == '__main__':
    # Initialize client object.
    client = DfaClient(path=os.path.join('..', '..', '..', '..'))
    main(client, QUERY_ID)
예제 #6
0
    print(
        'This program requires 4 command line arguments:\n'
        '\t1. DFA username\n\t2. DFA password\n'
        '\t3. Query ID number\n\t4. Output filename.\n')
    print(
        'Example usage: python rc_report.py username@dfa password456 12345 '
        'report.zip')
    sys.exit(1)

username = sys.argv[1]
password = sys.argv[2]
query_id = sys.argv[3]
output_file_name = sys.argv[4]

# Initialize client object.
client = DfaClient()
client._headers['Username'] = username
client._headers['Password'] = password

# Initialize appropriate service.
report_service = client.GetReportService(
    'http://advertisersapitest.doubleclick.net', 'v1.20')

# Create report request and submit it to the server.
report_request = {
    'queryId': query_id,
}
report_info = report_service.RunDeferredReport(report_request)[0]
print 'Report with ID \'%s\' has been scheduled.' % (report_info['reportId'])

report_request['reportId'] = report_info['reportId']