# Path: devicecloud/file_system_service.py
# class FileSystemServiceException(Exception):
# class ResponseParseError(FileSystemServiceException):
# class ErrorInfo(object):
# class FileInfo(object):
# class DirectoryInfo(object):
# class FileSystemServiceCommandBlock(object):
# class FileSystemServiceCommandABC(object):
# class LsCommand(FileSystemServiceCommandABC):
# class GetCommand(FileSystemServiceCommandABC):
# class PutCommand(FileSystemServiceCommandABC):
# class DeleteCommand(FileSystemServiceCommandABC):
# class FileSystemServiceAPI(SCIAPIBase):
# def _parse_command_response(response):
# def _parse_error_tree(error):
#     def __init__(self, errno, message):
#     def __str__(self):
#     def __init__(self, fssapi, device_id, path, last_modified, size, hash, hash_type):
#     def get_data(self):
#     def delete(self):
#     def __str__(self):
#     def __eq__(self, other):
#     def __init__(self, fssapi, device_id, path, last_modified):
#     def list_contents(self):
#     def __str__(self):
#     def __eq__(self, other):
#     def __init__(self):
#     def add_command(self, command):
#     def get_command_string(self):
#     def get_etree(self):
#     def get_etree(self):
#     def parse_response(cls, response, **kwargs):
#     def __init__(self, path, hash='any'):
#     def get_etree(self):
#     def parse_response(cls, response, device_id=None, fssapi=None, **kwargs):
#     def __init__(self, path, offset=None, length=None):
#     def get_etree(self):
#     def parse_response(cls, response, **kwargs):
#     def __init__(self, path, file_data=None, server_file=None, offset=None, truncate=False):
#     def get_etree(self):
#     def parse_response(cls, response, **kwargs):
#     def __init__(self, path):
#     def get_etree(self):
#     def parse_response(cls, response, **kwargs):
#     def send_command_block(self, target, command_block):
#     def list_files(self, target, path, hash='any'):
#     def get_file(self, target, path, offset=None, length=None):
#     def put_file(self, target, path, file_data=None, server_file=None, offset=None, truncate=False):
#     def delete_file(self, target, path):
#     def get_modified_items(self, target, path, last_modified_cutoff):
#     def exists(self, target, path, path_sep="/"):
# FILE_SYSTEM_COMMANDS = [LsCommand, GetCommand, PutCommand, DeleteCommand]
# 
# Path: devicecloud/sci.py
# class AllTarget(TargetABC):
#     """Target all devices"""
# 
#     def __init__(self):
#         pass
# 
#     def to_xml(self):
#         return '<device id="all"/>'
# 
# Path: devicecloud/test/unit/test_utilities.py
# class HttpTestBase(unittest.TestCase):
#     def setUp(self):
#         httpretty.enable()
#         # setup Device Cloud ping response
#         self.prepare_response("GET", "/ws/DeviceCore?size=1", "", status=200)
#         self.dc = DeviceCloud('user', 'pass')
# 
#     def tearDown(self):
#         httpretty.disable()
#         httpretty.reset()
# 
#     def _get_last_request(self):
#         return httpretty.last_request()
# 
#     def _get_last_request_params(self):
#         # Get the query params from the last request as a dictionary
#         params = urllib_parse.parse_qs(urllib_parse.urlparse(self._get_last_request().path).query)
#         return {k: v[0] for k, v in params.items()}  # convert from list values to single-value
# 
#     def prepare_response(self, method, path, data=None, status=200, match_querystring=False, **kwargs):
#         # TODO:
#         #   Should probably assert on more request headers and
#         #   respond with correct content type, etc.
#         if data is not None:
#             kwargs['body'] = data
#         httpretty.register_uri(method,
#                                "https://devicecloud.digi.com{}".format(path),
#                                match_querystring=match_querystring,
#                                status=status,
#                                **kwargs)
# 
#     def prepare_json_response(self, method, path, data, status=200):
#         self.prepare_response(method, path, json.dumps(data), status=status)


import base64
import unittest
import mock
import six
from xml.etree import ElementTree as ET
from devicecloud.file_system_service import FileInfo, DirectoryInfo, FileSystemServiceException, \
    _parse_command_response, ResponseParseError, \
    ErrorInfo, LsInfo, _parse_error_tree, LsCommand, GetCommand, PutCommand, DeleteCommand, \
    FileSystemServiceCommandBlock
from devicecloud.sci import AllTarget
from devicecloud.test.unit.test_utilities import HttpTestBase
        self.assertEqual(0, len(list(et)))
        self.assertEqual(None, et.text)

    def test_init_values(self):
        getcommand = GetCommand(path='/a/path/here', offset=5, length=10)
        et = getcommand.get_etree()
        self.assertEqual(et.tag, 'get_file')
        self.assertEqual('/a/path/here', et.get('path'))
        self.assertEqual('5', et.get('offset', None))
        self.assertEqual('10', et.get('length', None))
        self.assertEqual(0, len(list(et)))
        self.assertEqual(None, et.text)

    def test_parse_empty(self):
        data = GetCommand.parse_response(ET.fromstring(GET_FILE_BLOCK.format(data='')))
        self.assertEqual(six.b(""), data)

    def test_parse(self):
        data_str = base64.b64encode(six.b("File Data")).decode('ascii')
        data = GetCommand.parse_response(ET.fromstring(GET_FILE_BLOCK.format(data=data_str)))
        self.assertEqual(six.b("File Data"), data)

    def test_parse_error(self):
        errinfo = GetCommand.parse_response(
            ET.fromstring(ERROR_BLOCK.format(command='get_file', errno=1, errtext="error text")))

        self.assertEqual(errinfo.errno, 1)
        self.assertEqual(errinfo.message, "error text")

    def test_parse_wrong_response(self):

# Path: devicecloud/file_system_service.py
# class FileSystemServiceException(Exception):
# class ResponseParseError(FileSystemServiceException):
# class ErrorInfo(object):
# class FileInfo(object):
# class DirectoryInfo(object):
# class FileSystemServiceCommandBlock(object):
# class FileSystemServiceCommandABC(object):
# class LsCommand(FileSystemServiceCommandABC):
# class GetCommand(FileSystemServiceCommandABC):
# class PutCommand(FileSystemServiceCommandABC):
# class DeleteCommand(FileSystemServiceCommandABC):
# class FileSystemServiceAPI(SCIAPIBase):
# def _parse_command_response(response):
# def _parse_error_tree(error):
#     def __init__(self, errno, message):
#     def __str__(self):
#     def __init__(self, fssapi, device_id, path, last_modified, size, hash, hash_type):
#     def get_data(self):
#     def delete(self):
#     def __str__(self):
#     def __eq__(self, other):
#     def __init__(self, fssapi, device_id, path, last_modified):
#     def list_contents(self):
#     def __str__(self):
#     def __eq__(self, other):
#     def __init__(self):
#     def add_command(self, command):
#     def get_command_string(self):
#     def get_etree(self):
#     def get_etree(self):
#     def parse_response(cls, response, **kwargs):
#     def __init__(self, path, hash='any'):
#     def get_etree(self):
#     def parse_response(cls, response, device_id=None, fssapi=None, **kwargs):
#     def __init__(self, path, offset=None, length=None):
#     def get_etree(self):
#     def parse_response(cls, response, **kwargs):
#     def __init__(self, path, file_data=None, server_file=None, offset=None, truncate=False):
#     def get_etree(self):
#     def parse_response(cls, response, **kwargs):
#     def __init__(self, path):
#     def get_etree(self):
#     def parse_response(cls, response, **kwargs):
#     def send_command_block(self, target, command_block):
#     def list_files(self, target, path, hash='any'):
#     def get_file(self, target, path, offset=None, length=None):
#     def put_file(self, target, path, file_data=None, server_file=None, offset=None, truncate=False):
#     def delete_file(self, target, path):
#     def get_modified_items(self, target, path, last_modified_cutoff):
#     def exists(self, target, path, path_sep="/"):
# FILE_SYSTEM_COMMANDS = [LsCommand, GetCommand, PutCommand, DeleteCommand]
# 
# Path: devicecloud/sci.py
# class AllTarget(TargetABC):
#     """Target all devices"""
# 
#     def __init__(self):
#         pass
# 
#     def to_xml(self):
#         return '<device id="all"/>'
# 
# Path: devicecloud/test/unit/test_utilities.py
# class HttpTestBase(unittest.TestCase):
#     def setUp(self):
#         httpretty.enable()
#         # setup Device Cloud ping response
#         self.prepare_response("GET", "/ws/DeviceCore?size=1", "", status=200)
#         self.dc = DeviceCloud('user', 'pass')
# 
#     def tearDown(self):
#         httpretty.disable()
#         httpretty.reset()
# 
#     def _get_last_request(self):
#         return httpretty.last_request()
# 
#     def _get_last_request_params(self):
#         # Get the query params from the last request as a dictionary
#         params = urllib_parse.parse_qs(urllib_parse.urlparse(self._get_last_request().path).query)
#         return {k: v[0] for k, v in params.items()}  # convert from list values to single-value
# 
#     def prepare_response(self, method, path, data=None, status=200, match_querystring=False, **kwargs):
#         # TODO:
#         #   Should probably assert on more request headers and
#         #   respond with correct content type, etc.
#         if data is not None:
#             kwargs['body'] = data
#         httpretty.register_uri(method,
#                                "https://devicecloud.digi.com{}".format(path),
#                                match_querystring=match_querystring,
#                                status=status,
#                                **kwargs)
# 
#     def prepare_json_response(self, method, path, data, status=200):
#         self.prepare_response(method, path, json.dumps(data), status=status)


# Path: devicecloud/test/unit/test_file_system_service.py
import base64
import unittest
import mock
import six
from xml.etree import ElementTree as ET
from devicecloud.file_system_service import FileInfo, DirectoryInfo, FileSystemServiceException, \
    _parse_command_response, ResponseParseError, \
    ErrorInfo, LsInfo, _parse_error_tree, LsCommand, GetCommand, PutCommand, DeleteCommand, \
    FileSystemServiceCommandBlock
from devicecloud.sci import AllTarget
from devicecloud.test.unit.test_utilities import HttpTestBase

        self.assertEqual(0, len(list(et)))
        self.assertEqual(None, et.text)

    def test_init_values(self):
        getcommand = GetCommand(path='/a/path/here', offset=5, length=10)
        et = getcommand.get_etree()
        self.assertEqual(et.tag, 'get_file')
        self.assertEqual('/a/path/here', et.get('path'))
        self.assertEqual('5', et.get('offset', None))
        self.assertEqual('10', et.get('length', None))
        self.assertEqual(0, len(list(et)))
        self.assertEqual(None, et.text)

    def test_parse_empty(self):
        data = GetCommand.parse_response(ET.fromstring(GET_FILE_BLOCK.format(data='')))
        self.assertEqual(six.b(""), data)

    def test_parse(self):
        data_str = base64.b64encode(six.b("File Data")).decode('ascii')
        data = GetCommand.parse_response(ET.fromstring(GET_FILE_BLOCK.format(data=data_str)))
        self.assertEqual(six.b("File Data"), data)

    def test_parse_error(self):
        errinfo = GetCommand.parse_response(
            ET.fromstring(ERROR_BLOCK.format(command='get_file', errno=1, errtext="error text")))

        self.assertEqual(errinfo.errno, 1)
        self.assertEqual(errinfo.message, "error text")

    def test_parse_wrong_response(self):

        self.assertRaises(ResponseParseError, GetCommand.parse_response, ET.fromstring('<rm />'))