Ejemplo n.º 1
0
 def setUp(self):
     """Creates mock objects for googleapi client."""
     super(CloudSchedulerTest, self).setUp()
     self.addCleanup(mock.patch.stopall)
     self.project_id = 'project_id'
     self.location = 'us-central1'
     self.service_account_key_file = '/tmp/service_account_key.json'
     self.mock_get_credentials = mock.patch.object(cloud_auth,
                                                   'get_credentials',
                                                   autospec=True).start()
     self.mock_build_service_client = mock.patch.object(
         cloud_auth, 'build_service_client', autospec=True).start()
     self.mock_client = mock.Mock()
     self.mock_credentials = mock.Mock(credentials.Credentials,
                                       autospec=True)
     self.mock_get_credentials.return_value = self.mock_credentials
     self.mock_build_service_client.return_value = self.mock_client
     self.fake_appengine_http_target = cloud_scheduler.AppEngineTarget(
         http_method='GET', relative_uri='/test', service='test')
     self.fake_http_target = cloud_scheduler.HttpTarget(
         http_method='POST',
         uri='https://www.google.com/',
         body='{}',
         headers={'Content-Type': 'application/json'},
         authorization_header=('*****@*****.**',
                               'my-fake-scope'))
     self.scheduler = cloud_scheduler.CloudSchedulerUtils(
         project_id=self.project_id,
         location=self.location,
         service_account_key_file=self.service_account_key_file)
Ejemplo n.º 2
0
    def test_client_initializes_with_impersonated_service_account(
            self, mock_impersonated_client):
        service_account_name = '*****@*****.**'

        cloud_scheduler.CloudSchedulerUtils(
            project_id=self.project_id,
            service_account_name=service_account_name)

        mock_impersonated_client.assert_called_once_with(
            'cloudscheduler', service_account_name, 'v1beta1')
Ejemplo n.º 3
0
 def test_client_initializes_value_error(self):
     with self.assertRaises(ValueError):
         cloud_scheduler.CloudSchedulerUtils(project_id=self.project_id)