# Path: ddsc/core/consistency.py
# class UploadDetails(object):
# class ProjectChecker(object):
#     def __init__(self, dds_file, remote_path):
#     def inconsistent(self):
#     def had_error(self):
#     def is_bad(self):
#     def name(self):
#     def status_str(self):
#     def file_id(self):
#     def message(self):
#     def __init__(self, config, project):
#     def files_are_ok(self):
#     def _try_fetch_project_files(self):
#     def get_bad_uploads(self):
#     def get_bad_uploads_table_data(self):
#     def delete_bad_uploads(self):
#     def print_bad_uploads_table(self):
#     def wait_for_consistency(self, wait_sec=5):
# 
# Path: ddsc/core/ddsapi.py
# class DataServiceError(Exception):
#     """
#     Error that wraps up info about it and creates an informative string.
#     """
#     def __init__(self, response, url_suffix, request_data):
#         """
#         Create exception for failed response.
#         :param response: requests.Response response that was in error
#         :param url_suffix: str url we were trying to connect to
#         :param request_data: object data we were sending to url
#         """
#         resp_json = None
#         try:
#             resp_json = response.json()
#         except:
#             resp_json = {}
#         if response.status_code == 500:
#             if resp_json and not resp_json.get('reason'):
#                 resp_json = {'reason': 'Internal Server Error', 'suggestion': 'Contact DDS support.'}
#         Exception.__init__(self, 'Error {} on {}\nReason:{}\nSuggestion:{}'.format(
#             response.status_code, url_suffix, resp_json.get('reason', resp_json.get('error', '')),
#             resp_json.get('suggestion', '')
#         ))
#         self.response = resp_json
#         self.url_suffix = url_suffix
#         self.request_data = request_data
#         self.status_code = response.status_code


from unittest import TestCase
from ddsc.core.consistency import UploadDetails, ProjectChecker, DSResourceNotConsistentError
from ddsc.core.ddsapi import DataServiceError
from mock import Mock, patch, call

    @patch('ddsc.core.consistency.print')
    @patch('ddsc.core.consistency.UploadDetails')
    def test_print_bad_uploads_table(self, mock_upload_details, mock_print):
        mock_upload_details.return_value.is_bad.return_value = True
        mock_upload_details.return_value.name.return_value = 'file1.txt'
        mock_upload_details.return_value.status_str.return_value = 'BAD'
        mock_upload_details.return_value.message.return_value = ' file is bad'
        mock_upload_details.return_value.file_id.return_value = '123'
        mock_upload_details.return_value.remote_path = '/data/file1.txt'
        self.project.get_path_to_files.return_value.items.return_value = [
            ('/data/file1.txt', Mock())
        ]
        self.checker.print_bad_uploads_table()
        mock_print.assert_has_calls([
            call("ERROR: Project Mouse is not in a consistent state.\n"),
            call("Please wait while file uploads are checked.\nThis process can take quite a while."),
            call('File       Status    Message        FileID  RemotePath\n'
                 '---------  --------  -----------  --------  ---------------\n'
                 'file1.txt  BAD       file is bad       123  /data/file1.txt'),
            call('\nNOTE: Inconsistent files should resolve in a few minutes after starting.'),
            call('\nAn inconsistent file can be deleted by running:\n ddsclient delete -p <ProjectName> '
                 '--path <RemotePath>'),
            call()
        ])

    @patch('ddsc.core.consistency.print')
    @patch('ddsc.core.consistency.time')
    def test_wait_for_consistency(self, mock_time, mock_print):
        self.project.get_project_files_generator.side_effect = [

# Path: ddsc/core/consistency.py
# class UploadDetails(object):
# class ProjectChecker(object):
#     def __init__(self, dds_file, remote_path):
#     def inconsistent(self):
#     def had_error(self):
#     def is_bad(self):
#     def name(self):
#     def status_str(self):
#     def file_id(self):
#     def message(self):
#     def __init__(self, config, project):
#     def files_are_ok(self):
#     def _try_fetch_project_files(self):
#     def get_bad_uploads(self):
#     def get_bad_uploads_table_data(self):
#     def delete_bad_uploads(self):
#     def print_bad_uploads_table(self):
#     def wait_for_consistency(self, wait_sec=5):
# 
# Path: ddsc/core/ddsapi.py
# class DataServiceError(Exception):
#     """
#     Error that wraps up info about it and creates an informative string.
#     """
#     def __init__(self, response, url_suffix, request_data):
#         """
#         Create exception for failed response.
#         :param response: requests.Response response that was in error
#         :param url_suffix: str url we were trying to connect to
#         :param request_data: object data we were sending to url
#         """
#         resp_json = None
#         try:
#             resp_json = response.json()
#         except:
#             resp_json = {}
#         if response.status_code == 500:
#             if resp_json and not resp_json.get('reason'):
#                 resp_json = {'reason': 'Internal Server Error', 'suggestion': 'Contact DDS support.'}
#         Exception.__init__(self, 'Error {} on {}\nReason:{}\nSuggestion:{}'.format(
#             response.status_code, url_suffix, resp_json.get('reason', resp_json.get('error', '')),
#             resp_json.get('suggestion', '')
#         ))
#         self.response = resp_json
#         self.url_suffix = url_suffix
#         self.request_data = request_data
#         self.status_code = response.status_code


# Path: ddsc/core/tests/test_consistency.py
from unittest import TestCase
from ddsc.core.consistency import UploadDetails, ProjectChecker, DSResourceNotConsistentError
from ddsc.core.ddsapi import DataServiceError
from mock import Mock, patch, call


    @patch('ddsc.core.consistency.print')
    @patch('ddsc.core.consistency.UploadDetails')
    def test_print_bad_uploads_table(self, mock_upload_details, mock_print):
        mock_upload_details.return_value.is_bad.return_value = True
        mock_upload_details.return_value.name.return_value = 'file1.txt'
        mock_upload_details.return_value.status_str.return_value = 'BAD'
        mock_upload_details.return_value.message.return_value = ' file is bad'
        mock_upload_details.return_value.file_id.return_value = '123'
        mock_upload_details.return_value.remote_path = '/data/file1.txt'
        self.project.get_path_to_files.return_value.items.return_value = [
            ('/data/file1.txt', Mock())
        ]
        self.checker.print_bad_uploads_table()
        mock_print.assert_has_calls([
            call("ERROR: Project Mouse is not in a consistent state.\n"),
            call("Please wait while file uploads are checked.\nThis process can take quite a while."),
            call('File       Status    Message        FileID  RemotePath\n'
                 '---------  --------  -----------  --------  ---------------\n'
                 'file1.txt  BAD       file is bad       123  /data/file1.txt'),
            call('\nNOTE: Inconsistent files should resolve in a few minutes after starting.'),
            call('\nAn inconsistent file can be deleted by running:\n ddsclient delete -p <ProjectName> '
                 '--path <RemotePath>'),
            call()
        ])

    @patch('ddsc.core.consistency.print')
    @patch('ddsc.core.consistency.time')
    def test_wait_for_consistency(self, mock_time, mock_print):
        self.project.get_project_files_generator.side_effect = [

            DSResourceNotConsistentError(Mock(), Mock(), Mock()),