def test_process_a_key_waiting(self, mocked_is_sync_needed, mocked_sleep):
        mock_folder1 = 'a/b/'
        mocked_key1 = mock.Mock()
        mocked_key1.name = mock_folder1 + 'c'
        mocked_key1.get_contents_to_filename = mock.Mock()

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, sandbox, 2)

        s3concurrent.process_a_key(queue, 'download', 3)

        mocked_sleep.assert_called_once_with(4)
    def test_process_a_key_max_retry(self, mocked_is_sync_needed, mocked_sleep):
        mock_folder1 = 'a/b/'
        mocked_key1 = mock.Mock()
        mocked_key1.name = mock_folder1 + 'c'
        mocked_key1.get_contents_to_filename = mock.Mock()

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, sandbox, 2)

        s3concurrent.process_a_key(queue, 'download', 1)

        self.assertEquals(0, mocked_sleep.call_count)
    def test_process_a_key_waiting(self, mocked_is_sync_needed, mocked_sleep):
        mock_folder1 = 'a/b/'
        mocked_key1 = mock.Mock()
        mocked_key1.name = mock_folder1 + 'c'
        mocked_key1.get_contents_to_filename = mock.Mock()

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, sandbox, 2)

        s3concurrent.process_a_key(queue, 'download', 3)

        mocked_sleep.assert_called_once_with(4)
    def test_process_a_key_max_retry(self, mocked_is_sync_needed,
                                     mocked_sleep):
        mock_folder1 = 'a/b/'
        mocked_key1 = mock.Mock()
        mocked_key1.name = mock_folder1 + 'c'
        mocked_key1.get_contents_to_filename = mock.Mock()

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, sandbox, 2)

        s3concurrent.process_a_key(queue, 'download', 1)

        self.assertEquals(0, mocked_sleep.call_count)
    def test_download_a_key(self):
        mock_folder1 = 'a/b/'
        mocked_key1 = mock.Mock()
        mocked_key1.name = mock_folder1 + 'c'
        mocked_key1.get_contents_to_filename = mock.Mock()

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, sandbox)

        self.assertEquals(queue.enqueued_counter, 1)

        s3concurrent.process_a_key(queue, 'download', 1)

        self.assertEquals(queue.de_queue_counter, 1)
        self.assertTrue(queue.is_empty())
        mocked_key1.get_contents_to_filename.assert_called_once_with(sandbox)
    def test_download_a_key(self):
        mock_folder1 = 'a/b/'
        mocked_key1 = mock.Mock()
        mocked_key1.name = mock_folder1 + 'c'
        mocked_key1.get_contents_to_filename = mock.Mock()

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, sandbox)

        self.assertEquals(queue.enqueued_counter, 1)

        s3concurrent.process_a_key(queue, 'download', 1)

        self.assertEquals(queue.de_queue_counter, 1)
        self.assertTrue(queue.is_empty())
        mocked_key1.get_contents_to_filename.assert_called_once_with(sandbox)
    def test_upload_a_key_error(self):
        test_key_name = sandbox + 'test.txt'

        mocked_key1 = mock.Mock()
        mocked_key1.name = test_key_name
        mocked_key1.set_contents_from_filename = mock.Mock()
        mocked_key1.set_contents_from_filename.side_effect = Exception

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, sandbox)

        self.assertEquals(queue.enqueued_counter, 1)

        s3concurrent.process_a_key(queue, 'upload', 1)

        self.assertEquals(queue.de_queue_counter, 1)
        mocked_key1.set_contents_from_filename.assert_called_once_with(sandbox)
        self.assertFalse(queue.is_empty())

        self.assertEquals(queue.enqueued_counter, 2)
    def test_upload_a_key(self):
        test_key_name = sandbox + 'test.txt'

        with open(test_key_name, 'wb') as f:
            f.write('mocked file')

        mocked_key1 = mock.Mock()
        mocked_key1.name = test_key_name
        mocked_key1.set_contents_from_filename = mock.Mock()

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, test_key_name)

        self.assertEquals(queue.enqueued_counter, 1)

        s3concurrent.process_a_key(queue, 'upload', 1)

        self.assertEquals(queue.de_queue_counter, 1)
        self.assertTrue(queue.is_empty())
        mocked_key1.set_contents_from_filename.assert_called_once_with(test_key_name)
    def test_upload_a_key_error(self):
        test_key_name = sandbox + 'test.txt'

        mocked_key1 = mock.Mock()
        mocked_key1.name = test_key_name
        mocked_key1.set_contents_from_filename = mock.Mock()
        mocked_key1.set_contents_from_filename.side_effect = Exception

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, sandbox)

        self.assertEquals(queue.enqueued_counter, 1)

        s3concurrent.process_a_key(queue, 'upload', 1)

        self.assertEquals(queue.de_queue_counter, 1)
        mocked_key1.set_contents_from_filename.assert_called_once_with(sandbox)
        self.assertFalse(queue.is_empty())

        self.assertEquals(queue.enqueued_counter, 2)
    def test_upload_a_key(self):
        test_key_name = sandbox + 'test.txt'

        with open(test_key_name, 'wb') as f:
            f.write('mocked file')

        mocked_key1 = mock.Mock()
        mocked_key1.name = test_key_name
        mocked_key1.set_contents_from_filename = mock.Mock()

        queue = s3concurrent.ProcessKeyQueue()
        queue.enqueue_item(mocked_key1, test_key_name)

        self.assertEquals(queue.enqueued_counter, 1)

        s3concurrent.process_a_key(queue, 'upload', 1)

        self.assertEquals(queue.de_queue_counter, 1)
        self.assertTrue(queue.is_empty())
        mocked_key1.set_contents_from_filename.assert_called_once_with(
            test_key_name)