# Path: gslib/exception.py
# NO_URLS_MATCHED_PREFIX = 'No URLs matched'
# NO_URLS_MATCHED_GENERIC = (NO_URLS_MATCHED_PREFIX +
#                            '. Do the files you\'re operating on exist?')
# NO_URLS_MATCHED_TARGET = NO_URLS_MATCHED_PREFIX + ': %s'
# class AbortException(StandardError):
# class CommandException(StandardError):
# class ControlCException(Exception):
# class GcloudStorageTranslationError(Exception):
# class HashMismatchException(Exception):
# class IamChOnResourceWithConditionsException(Exception):
# class InvalidUrlError(Exception):
# class ExternalBinaryError(Exception):
#   def __init__(self, reason):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, reason, informational=False):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForGS(reason):
#   if not RUN_S3_TESTS:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForJSON(reason):
#   if USING_JSON_API:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForXML(reason):
#   """Skips the test if running S3 tests, or if prefer_api isn't set to json."""
#   if not USING_JSON_API or RUN_S3_TESTS:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func


import re
import gslib.tests.testcase as testcase
from gslib import exception
from gslib.tests.testcase.integration_testcase import SkipForGS
from gslib.tests.testcase.integration_testcase import SkipForJSON
from gslib.tests.testcase.integration_testcase import SkipForXML
from gslib.tests.util import ObjectToURI as suri
from gslib.tests.util import SetBotoConfigForTest
  @SkipForXML('Autoclass only runs on GCS JSON API.')
  def test_turning_on_and_off(self):
    bucket_uri = self.CreateBucket()

    stdout = self.RunGsUtil(self._set_autoclass_cmd +
                            ['on', suri(bucket_uri)],
                            return_stdout=True)
    self.assertRegex(
        stdout,
        re.escape('Setting Autoclass on for {}\n'.format(
            str(bucket_uri).rstrip('/'))))

    stdout = self.RunGsUtil(self._get_autoclass_cmd + [suri(bucket_uri)],
                            return_stdout=True)
    self.assertRegex(stdout, r'Enabled: True')
    self.assertRegex(stdout, r'Toggle Time: \d+')

    stdout = self.RunGsUtil(self._set_autoclass_cmd +
                            ['off', suri(bucket_uri)],
                            return_stdout=True)
    self.assertRegex(
        stdout,
        re.escape('Setting Autoclass off for {}\n'.format(
            str(bucket_uri).rstrip('/'))))

    stdout = self.RunGsUtil(self._get_autoclass_cmd + [suri(bucket_uri)],
                            return_stdout=True)
    self.assertRegex(stdout, r'Enabled: False')
    self.assertRegex(stdout, r'Toggle Time: \d+')


# Path: gslib/exception.py
# NO_URLS_MATCHED_PREFIX = 'No URLs matched'
# NO_URLS_MATCHED_GENERIC = (NO_URLS_MATCHED_PREFIX +
#                            '. Do the files you\'re operating on exist?')
# NO_URLS_MATCHED_TARGET = NO_URLS_MATCHED_PREFIX + ': %s'
# class AbortException(StandardError):
# class CommandException(StandardError):
# class ControlCException(Exception):
# class GcloudStorageTranslationError(Exception):
# class HashMismatchException(Exception):
# class IamChOnResourceWithConditionsException(Exception):
# class InvalidUrlError(Exception):
# class ExternalBinaryError(Exception):
#   def __init__(self, reason):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, reason, informational=False):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForGS(reason):
#   if not RUN_S3_TESTS:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForJSON(reason):
#   if USING_JSON_API:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForXML(reason):
#   """Skips the test if running S3 tests, or if prefer_api isn't set to json."""
#   if not USING_JSON_API or RUN_S3_TESTS:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func


# Path: gslib/tests/test_autoclass.py
import re
import gslib.tests.testcase as testcase
from gslib import exception
from gslib.tests.testcase.integration_testcase import SkipForGS
from gslib.tests.testcase.integration_testcase import SkipForJSON
from gslib.tests.testcase.integration_testcase import SkipForXML
from gslib.tests.util import ObjectToURI as suri
from gslib.tests.util import SetBotoConfigForTest

  @SkipForXML('Autoclass only runs on GCS JSON API.')
  def test_turning_on_and_off(self):
    bucket_uri = self.CreateBucket()

    stdout = self.RunGsUtil(self._set_autoclass_cmd +
                            ['on', suri(bucket_uri)],
                            return_stdout=True)
    self.assertRegex(
        stdout,
        re.escape('Setting Autoclass on for {}\n'.format(
            str(bucket_uri).rstrip('/'))))

    stdout = self.RunGsUtil(self._get_autoclass_cmd + [suri(bucket_uri)],
                            return_stdout=True)
    self.assertRegex(stdout, r'Enabled: True')
    self.assertRegex(stdout, r'Toggle Time: \d+')

    stdout = self.RunGsUtil(self._set_autoclass_cmd +
                            ['off', suri(bucket_uri)],
                            return_stdout=True)
    self.assertRegex(
        stdout,
        re.escape('Setting Autoclass off for {}\n'.format(
            str(bucket_uri).rstrip('/'))))

    stdout = self.RunGsUtil(self._get_autoclass_cmd + [suri(bucket_uri)],
                            return_stdout=True)
    self.assertRegex(stdout, r'Enabled: False')
    self.assertRegex(stdout, r'Toggle Time: \d+')


  @SkipForXML('Autoclass only runs on GCS JSON API.')