# Path: dapbench/thredds/lib/configuration.py
# class Configuration(object):
#     """Checker configuration.
#     """
#     def __init__(self, key_file, cert_file, debug, recurse=False, listonly=False, quiet=False,
#                  services_to_test="", service_extensions=None, public_service_extensions=None,
#                  forbidden_service_extensions=None, required_container_properties=None,
#                  required_file_properties=None):
#         """
#         @param key_file - file containing the user's private key
#         @param cert_file - file containing the user's certificate
#         @param services_to_test - list of service types for which to test access
#         @param debug - if True, output debugging information
#         @param recurse - if True, recurse into linked catalogs
#         @param listonly - if True, only list datasets, otherwise check access
#         @param quiet - if True, produce minimal output
#         @param service_extensions - extensions for services that can have multiple extensions
#         @param public_service_extensions - service types and extensions for which public access is
#             expected
#         @param forbidden_service_extensions - service types and extensions for which no access is
#             expected
#         @param required_container_properties - dataset properties required for container datasets
#         @param required_file_properties - dataset properties required for file datasets
#         """
#         self.key_file = key_file
#         self.cert_file = cert_file
#         self.services_to_test = (
#             [s.strip() for s in services_to_test.split(',')] if services_to_test else [])
#         self.debug = debug
#         self.recurse = recurse
#         self.listonly = listonly
#         self.quiet = quiet
#         self.service_extensions = self.parse_dict_of_lists(service_extensions)
#         self.public_service_extensions = self.parse_dict_of_lists(public_service_extensions)
#         self.forbidden_service_extensions = self.parse_dict_of_lists(forbidden_service_extensions)
#         self.required_container_properties = (
#             [p.strip() for p in required_container_properties.split(',')]
#             if required_container_properties else [])
#         self.required_file_properties = (
#             [p.strip() for p in required_file_properties.split(',')]
#             if required_file_properties else [])
# 
#     @staticmethod
#     def parse_dict_of_lists(in_str):
#         """Parses a string in the format key1:item11,item12,...;key2:item21,item22...;...
#         into a dict with keys key1, key2, ... and values lists [item11, item12] and so on.
#         @param in_str - string to parse
#         @return dict of lists of items
#         """
#         result = {}
#         if in_str is not None:
#             outer_list = in_str.split(';')
#             for item in outer_list:
#                 (key, sep, inner_str) = item.partition(':')
#                 inner_list = inner_str.split(',')
#                 result[key] = inner_list
#         return result
# 
# Path: dapbench/thredds/lib/results.py
# class Results(object):
#     def __init__(self, access_allowed_count=0, access_denied_count=0, inconsistent_count=0,
#                  untested_count=0):
#         self.access_allowed_count = access_allowed_count
#         self.access_denied_count = access_denied_count
#         self.inconsistent_count = inconsistent_count
#         self.untested_count = untested_count
#         self.untested_service_types = []
# 
#     def add_access_allowed(self):
#         self.access_allowed_count += 1
# 
#     def add_access_denied(self):
#         self.access_denied_count += 1
# 
#     def add_inconsistent(self):
#         self.inconsistent_count += 1
# 
#     def add_untested(self):
#         self.untested_count += 1
# 
#     def add_untested_service_type(self, service_type):
#         """Add a service type to a sorted list.
#         """
#         if service_type not in self.untested_service_types:
#             bisect.insort(self.untested_service_types, service_type)
# 
#     def __eq__(self, other):
#         return (isinstance(other, Results)
#                 and (self.access_allowed_count == other.access_allowed_count)
#                 and (self.access_denied_count == other.access_denied_count)
#                 and (self.inconsistent_count == other.inconsistent_count)
#                 and (self.untested_count == other.untested_count)
#                 and (self.untested_service_types == other.untested_service_types))
# 
#     def __repr__(self):
#         return("(allowed=%d, denied=%d, inconsistent=%d, untested=%d %s)" %
#                (self.access_allowed_count, self.access_denied_count, self.inconsistent_count,
#                 self.untested_count, self.untested_service_types.__str__()))


import os
import unittest
import dapbench.thredds.lib.catalog_access as catalog_access
from dapbench.thredds.lib.configuration import Configuration
from dapbench.thredds.lib.results import Results
# BSD Licence
# Copyright (c) 2012, Science & Technology Facilities Council (STFC)
# All rights reserved.
#
# See the LICENSE file in the source distribution of this software for
# the full license text.

'''
Created on 30 Sep 2011

@author: rwilkinson
'''

class Test(unittest.TestCase):
    """Example test of access to catalogs.
    """
    def setUp(self):

# Path: dapbench/thredds/lib/configuration.py
# class Configuration(object):
#     """Checker configuration.
#     """
#     def __init__(self, key_file, cert_file, debug, recurse=False, listonly=False, quiet=False,
#                  services_to_test="", service_extensions=None, public_service_extensions=None,
#                  forbidden_service_extensions=None, required_container_properties=None,
#                  required_file_properties=None):
#         """
#         @param key_file - file containing the user's private key
#         @param cert_file - file containing the user's certificate
#         @param services_to_test - list of service types for which to test access
#         @param debug - if True, output debugging information
#         @param recurse - if True, recurse into linked catalogs
#         @param listonly - if True, only list datasets, otherwise check access
#         @param quiet - if True, produce minimal output
#         @param service_extensions - extensions for services that can have multiple extensions
#         @param public_service_extensions - service types and extensions for which public access is
#             expected
#         @param forbidden_service_extensions - service types and extensions for which no access is
#             expected
#         @param required_container_properties - dataset properties required for container datasets
#         @param required_file_properties - dataset properties required for file datasets
#         """
#         self.key_file = key_file
#         self.cert_file = cert_file
#         self.services_to_test = (
#             [s.strip() for s in services_to_test.split(',')] if services_to_test else [])
#         self.debug = debug
#         self.recurse = recurse
#         self.listonly = listonly
#         self.quiet = quiet
#         self.service_extensions = self.parse_dict_of_lists(service_extensions)
#         self.public_service_extensions = self.parse_dict_of_lists(public_service_extensions)
#         self.forbidden_service_extensions = self.parse_dict_of_lists(forbidden_service_extensions)
#         self.required_container_properties = (
#             [p.strip() for p in required_container_properties.split(',')]
#             if required_container_properties else [])
#         self.required_file_properties = (
#             [p.strip() for p in required_file_properties.split(',')]
#             if required_file_properties else [])
# 
#     @staticmethod
#     def parse_dict_of_lists(in_str):
#         """Parses a string in the format key1:item11,item12,...;key2:item21,item22...;...
#         into a dict with keys key1, key2, ... and values lists [item11, item12] and so on.
#         @param in_str - string to parse
#         @return dict of lists of items
#         """
#         result = {}
#         if in_str is not None:
#             outer_list = in_str.split(';')
#             for item in outer_list:
#                 (key, sep, inner_str) = item.partition(':')
#                 inner_list = inner_str.split(',')
#                 result[key] = inner_list
#         return result
# 
# Path: dapbench/thredds/lib/results.py
# class Results(object):
#     def __init__(self, access_allowed_count=0, access_denied_count=0, inconsistent_count=0,
#                  untested_count=0):
#         self.access_allowed_count = access_allowed_count
#         self.access_denied_count = access_denied_count
#         self.inconsistent_count = inconsistent_count
#         self.untested_count = untested_count
#         self.untested_service_types = []
# 
#     def add_access_allowed(self):
#         self.access_allowed_count += 1
# 
#     def add_access_denied(self):
#         self.access_denied_count += 1
# 
#     def add_inconsistent(self):
#         self.inconsistent_count += 1
# 
#     def add_untested(self):
#         self.untested_count += 1
# 
#     def add_untested_service_type(self, service_type):
#         """Add a service type to a sorted list.
#         """
#         if service_type not in self.untested_service_types:
#             bisect.insort(self.untested_service_types, service_type)
# 
#     def __eq__(self, other):
#         return (isinstance(other, Results)
#                 and (self.access_allowed_count == other.access_allowed_count)
#                 and (self.access_denied_count == other.access_denied_count)
#                 and (self.inconsistent_count == other.inconsistent_count)
#                 and (self.untested_count == other.untested_count)
#                 and (self.untested_service_types == other.untested_service_types))
# 
#     def __repr__(self):
#         return("(allowed=%d, denied=%d, inconsistent=%d, untested=%d %s)" %
#                (self.access_allowed_count, self.access_denied_count, self.inconsistent_count,
#                 self.untested_count, self.untested_service_types.__str__()))


# Path: dapbench/thredds/test/test_access.py
import os
import unittest
import dapbench.thredds.lib.catalog_access as catalog_access
from dapbench.thredds.lib.configuration import Configuration
from dapbench.thredds.lib.results import Results

# BSD Licence
# Copyright (c) 2012, Science & Technology Facilities Council (STFC)
# All rights reserved.
#
# See the LICENSE file in the source distribution of this software for
# the full license text.

'''
Created on 30 Sep 2011

@author: rwilkinson
'''

class Test(unittest.TestCase):
    """Example test of access to catalogs.
    """
    def setUp(self):

        self.config = Configuration(key_file=os.path.expanduser("~/.esg/credentials.pem"),