<s> """<STR_LIT>""" <EOL> import unittest <EOL> try : <EOL> import oauth2client <EOL> import httplib2 <EOL> from luigi . contrib import dataproc <EOL> from googleapiclient import discovery <EOL> default_credentials = oauth2client . client . GoogleCredentials . get_application_default ( ) <EOL> default_client = discovery . build ( '<STR_LIT>' , '<STR_LIT>' , credentials = default_credentials , http = httplib2 . Http ( ) ) <EOL> dataproc . set_dataproc_client ( default_client ) <EOL> except ImportError : <EOL> raise unittest . SkipTest ( '<STR_LIT>' ) <EOL> import luigi <EOL> import os <EOL> import time <EOL> from nose . plugins . attrib import attr <EOL> PROJECT_ID = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> CLUSTER_NAME = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> REGION = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class _DataprocBaseTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> pass <EOL> def tearDown ( self ) : <EOL> pass <EOL> @ attr ( '<STR_LIT>' ) <EOL> class DataprocTaskTest ( _DataprocBaseTestCase ) : <EOL> def test_1_create_cluster ( self ) : <EOL> success = luigi . run ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + PROJECT_ID , <EOL> '<STR_LIT>' + CLUSTER_NAME ] ) <EOL> self . assertTrue ( success ) <EOL> def test_2_create_cluster_should_notice_existing_cluster_and_return_immediately ( self ) : <EOL> job_start = time . time ( ) <EOL> success = luigi . run ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + PROJECT_ID , <EOL> '<STR_LIT>' + CLUSTER_NAME ] ) <EOL> self . assertTrue ( success ) <EOL> self . assertLess ( time . time ( ) - job_start , <NUM_LIT:3> ) <EOL> def test_3_submit_minimal_job ( self ) : <EOL> luigi . run ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + PROJECT_ID , <EOL> '<STR_LIT>' + CLUSTER_NAME , <EOL> '<STR_LIT>' ] ) <EOL> response = dataproc . get_dataproc_client ( ) . projects ( ) . regions ( ) . jobs ( ) . list ( projectId = PROJECT_ID , region = REGION , clusterName = CLUSTER_NAME ) . execute ( ) <EOL> lastJob = response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> self . assertEquals ( lastJob [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_4_submit_spark_job ( self ) : <EOL> luigi . run ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + PROJECT_ID , <EOL> '<STR_LIT>' + CLUSTER_NAME , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> response = dataproc . get_dataproc_client ( ) . projects ( ) . regions ( ) . jobs ( ) . list ( projectId = PROJECT_ID , region = REGION , clusterName = CLUSTER_NAME ) . execute ( ) <EOL> lastJob = response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> self . assertEquals ( lastJob [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEquals ( lastJob [ '<STR_LIT>' ] , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEquals ( lastJob [ '<STR_LIT:args>' ] , [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] ) <EOL> def test_5_submit_pyspark_job ( self ) : <EOL> luigi . run ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + PROJECT_ID , <EOL> '<STR_LIT>' + CLUSTER_NAME , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> response = dataproc . get_dataproc_client ( ) . projects ( ) . regions ( ) . jobs ( ) . list ( projectId = PROJECT_ID , region = REGION , clusterName = CLUSTER_NAME ) . execute ( ) <EOL> lastJob = response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> self . assertEquals ( lastJob [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEquals ( lastJob [ '<STR_LIT>' ] , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEquals ( lastJob [ '<STR_LIT:args>' ] , [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] ) <EOL> def test_6_delete_cluster ( self ) : <EOL> success = luigi . run ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + PROJECT_ID , <EOL> '<STR_LIT>' + CLUSTER_NAME ] ) <EOL> self . assertTrue ( success ) <EOL> def test_7_delete_cluster_should_return_immediately_if_no_cluster ( self ) : <EOL> job_start = time . time ( ) <EOL> success = luigi . run ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + PROJECT_ID , <EOL> '<STR_LIT>' + CLUSTER_NAME ] ) <EOL> self . assertTrue ( success ) <EOL> self . assertLess ( time . time ( ) - job_start , <NUM_LIT:3> ) </s>
