Beispiel #1
0
class TestMTPDriver(unittest.TestCase):
    def setUp(self):
        self.maxDiff = None

        self.mock_executor = MagicMock(spec=Executor)

        self.test_model = MTPDriver(self.mock_executor)

    def tearDown(self):
        return

    def __get_resource(self, resource_name):
        contents = ''
        with open('test/resources/' + resource_name, 'r') as f:
            contents = f.read()

        return contents

    def test_it_should_know_if_no_devices_are_connected(self):
        self.mock_executor.execute_output.return_value = self.__get_resource(MTP_DETECT_NOT_CONNECTED_RESOURCE)
        self.assertFalse(self.test_model.detect_device())

    def test_it_should_know_if_a_device_is_connected(self):
        self.mock_executor.execute_output.return_value = self.__get_resource(MTP_DETECT_CONNECTED_RESOURCE)
        self.assertEqual(EXPECTED_DEVICE_INFO, self.test_model.detect_device())

    def test_it_should_accurately_describe_the_devices_folders(self):
        self.mock_executor.execute_output.return_value = self.__get_resource(MTP_FOLDERS_CONNECTED_RESOURCE)
        actual_folder_list = self.test_model.get_folder_list()
        self.assertItemsEqual(actual_folder_list, EXPECTED_FOLDER_STRUCTURE)

    def test_it_should_accurately_describe_the_file_structure(self):
        self.mock_executor.execute_output.return_value = self.__get_resource(MTP_FILES_CONNECTED_RESOURCE)
        actual_file_list = self.test_model.get_filelisting()
        self.assertEqual(actual_file_list, EXPECTED_FILE_STRUCTURE)

    def test_it_should_properly_copy_a_file(self):
        self.test_model.get_file_to_file(42, '/root/staging/id/file.jpg')
        self.mock_executor.execute.assert_called_once_with(['mtp-getfile', '42', '/root/staging/id/file.jpg'])

    def test_it_should_properly_delete_a_file(self):
        self.test_model.delete_object(42)
        self.mock_executor.execute.assert_called_once_with(['mtp-delfile', '-n', '42'])
Beispiel #2
0
    def setUp(self):
        self.maxDiff = None

        self.mock_executor = MagicMock(spec=Executor)

        self.test_model = MTPDriver(self.mock_executor)