class TestBaseGcpSystem(unittest.TestCase, LoggingMixin): def __init__(self, method_name, gcp_key, project_extra=None): super().__init__(methodName=method_name) self.gcp_authenticator = GcpAuthenticator(gcp_key=gcp_key, project_extra=project_extra) self.setup_called = False @staticmethod def skip_check(key_name): return GcpAuthenticator(key_name).full_key_path is None @staticmethod def skip_long(key_name): if os.environ.get('GCP_ENABLE_LONG_TESTS') == 'True': return GcpAuthenticator(key_name).full_key_path is None return True def setUp(self): self.gcp_authenticator.gcp_store_authentication() self.gcp_authenticator.gcp_authenticate() # We checked that authentication works. Ne we revoke it to make # sure we are not relying on the default authentication self.gcp_authenticator.gcp_revoke_authentication() self.setup_called = True # noinspection PyPep8Naming def tearDown(self): self.gcp_authenticator.gcp_restore_authentication()
parser = argparse.ArgumentParser(description='Create and remove a bucket for system tests.') parser.add_argument( '--action', dest='action', required=True, choices=('create-bucket', 'delete-bucket', 'before-tests', 'after-tests'), ) action = parser.parse_args().action helper = GCPVisionTestHelper() gcp_authenticator = GcpAuthenticator(GCP_AI_KEY) helper.log.info('Starting action: {}'.format(action)) gcp_authenticator.gcp_store_authentication() try: gcp_authenticator.gcp_authenticate() if action == 'before-tests': pass elif action == 'after-tests': pass elif action == 'create-bucket': helper.create_bucket() elif action == 'delete-bucket': helper.delete_bucket() else: raise Exception("Unknown action: {}".format(action)) finally: gcp_authenticator.gcp_restore_authentication() helper.log.info('Finishing action: {}'.format(action))