class ClientTest(unittest.TestCase):

  """Tests for the adspygoogle.common.Client module."""

  def setUp(self):
    """Initialize a Client to test with."""
    self.client = Client()

  def testLoadAuthCredentials_ClientLogin(self):
    """Tests the _LoadAuthCredentials function."""
    _, filename = tempfile.mkstemp()
    auth_credentials = {
        'username': '******',
        'password': '******'
    }
    with open(filename, 'w') as handle:
      pickle.dump(auth_credentials, handle)

    try:
      Client.auth_pkl = filename
      self.assertEqual(self.client._LoadAuthCredentials(), auth_credentials)
    finally:
      Client.auth_pkl = ''

  def testLoadAuthCredentials_OAuth2(self):
    """Tests the _LoadAuthCredentials function."""
    _, filename = tempfile.mkstemp()
    client_id = 'id1234id',
    client_secret = 'shhh,itsasecret',
    refresh_token = '1/not_a_refresh_token'
    auth_credentials = {
        'clientId': client_id,
        'clientSecret': client_secret,
        'refreshToken': refresh_token
    }
    with open(filename, 'w') as handle:
      pickle.dump(auth_credentials, handle)

    try:
      Client.auth_pkl = filename
      read_credentials = self.client._LoadAuthCredentials()
      self.assertEqual(read_credentials['oauth2credentials'].refresh_token,
                       refresh_token)
      self.assertEqual(read_credentials['oauth2credentials'].client_secret,
                       client_secret)
      self.assertEqual(read_credentials['oauth2credentials'].client_id,
                       client_id)
      self.assertTrue('clientId' not in read_credentials)
      self.assertTrue('clientSecret' not in read_credentials)
      self.assertTrue('refreshToken' not in read_credentials)
    finally:
      Client.auth_pkl = ''

  def testLoadAuthCredentials_noPickle(self):
    """Tests the _LoadAuthCredentials function."""
    try:
      self.client._LoadAuthCredentials()
      self.fail('Exception should have been thrown.')
    except ValidationError, e:
      self.assertEqual(str(e), 'Authentication data is missing.')
Пример #2
0
class ClientTest(unittest.TestCase):

  """Tests for the adspygoogle.common.Client module."""

  def setUp(self):
    """Initialize a Client to test with."""
    self.client = Client()

  def testLoadAuthCredentials(self):
    """Tests the _LoadAuthCredentials function."""
    _, filename = tempfile.mkstemp()
    auth_credentials = {
        'username': '******',
        'password': '******'
    }
    with open(filename, 'w') as handle:
      pickle.dump(auth_credentials, handle)

    Client.auth_pkl = filename
    self.assertEqual(self.client._LoadAuthCredentials(), auth_credentials)
    Client.auth_pkl = ''

  def testLoadAuthCredentials_noPickle(self):
    """Tests the _LoadAuthCredentials function."""
    try:
      self.client._LoadAuthCredentials()
      self.fail('Exception should have been thrown.')
    except ValidationError, e:
      self.assertEqual(str(e), 'Authentication data is missing.')
Пример #3
0
class ClientTest(unittest.TestCase):
    """Tests for the adspygoogle.common.Client module."""
    def setUp(self):
        """Initialize a Client to test with."""
        self.client = Client()

    def testLoadAuthCredentials_ClientLogin(self):
        """Tests the _LoadAuthCredentials function."""
        _, filename = tempfile.mkstemp()
        auth_credentials = {'username': '******', 'password': '******'}
        with open(filename, 'w') as handle:
            pickle.dump(auth_credentials, handle)

        try:
            Client.auth_pkl = filename
            self.assertEqual(self.client._LoadAuthCredentials(),
                             auth_credentials)
        finally:
            Client.auth_pkl = ''

    def testLoadAuthCredentials_OAuth2(self):
        """Tests the _LoadAuthCredentials function."""
        _, filename = tempfile.mkstemp()
        client_id = 'id1234id',
        client_secret = 'shhh,itsasecret',
        refresh_token = '1/not_a_refresh_token'
        auth_credentials = {
            'clientId': client_id,
            'clientSecret': client_secret,
            'refreshToken': refresh_token
        }
        with open(filename, 'w') as handle:
            pickle.dump(auth_credentials, handle)

        try:
            Client.auth_pkl = filename
            read_credentials = self.client._LoadAuthCredentials()
            self.assertEqual(
                read_credentials['oauth2credentials'].refresh_token,
                refresh_token)
            self.assertEqual(
                read_credentials['oauth2credentials'].client_secret,
                client_secret)
            self.assertEqual(read_credentials['oauth2credentials'].client_id,
                             client_id)
            self.assertTrue('clientId' not in read_credentials)
            self.assertTrue('clientSecret' not in read_credentials)
            self.assertTrue('refreshToken' not in read_credentials)
        finally:
            Client.auth_pkl = ''

    def testLoadAuthCredentials_noPickle(self):
        """Tests the _LoadAuthCredentials function."""
        try:
            self.client._LoadAuthCredentials()
            self.fail('Exception should have been thrown.')
        except ValidationError, e:
            self.assertEqual(str(e), 'Authentication data is missing.')
 def setUp(self):
   """Initialize a Client to test with."""
   self.client = Client()
Пример #5
0
# Copyright 2010 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Settings and configuration for the unit tests."""

__author__ = '[email protected] (Stan Grinberg)'

import os
import sys
sys.path.append(os.path.join('..', '..', '..'))

from adspygoogle.common import SOAPPY
from adspygoogle.common import ZSI
from adspygoogle.common.Client import Client


HTTP_PROXY = None
client = Client(path=os.path.join('..', '..', '..'))
client.soap_lib = ZSI
Пример #6
0
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#
# Copyright 2010 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Settings and configuration for the unit tests."""

__author__ = '[email protected] (Stan Grinberg)'

import os
import sys
sys.path.insert(0, os.path.join('..', '..', '..'))

from adspygoogle.common.Client import Client

HTTP_PROXY = None
client = Client(path=os.path.join('..', '..', '..'))
Пример #7
0
 def setUp(self):
     """Initialize a Client to test with."""
     self.client = Client()