Beispiel #1
0
    def test_download_directory(self, mock_makedirs, mock_rmtree, mock_open):
        store = Objectstore()
        store._get_objects_list = MagicMock(return_value=[
            {'name': 'dira', 'content_type': 'application/directory'},
            {'name': 'dira/dirb', 'content_type': 'application/directory'},
            {'name': 'dira/dirb/filea.json', 'content_type': 'application/json'},
            {'name': 'dira/dirb/fileb.json', 'content_type': 'application/json'},
            {'name': 'dira/dirb/dire', 'content_type': 'application/directory'},
            {'name': 'dira/dirc', 'content_type': 'application/directory'},
            {'name': 'dira/dirc/filec.json', 'content_type': 'application/json'},
            {'name': 'dira/dird/filed.json', 'content_type': 'application/json'},
            {'name': 'dira/dirb/dirf/somefile.json', 'content_type': 'application/json'},
        ])
        store._get_object = lambda x: 'downloaded(' + x['name'] + ')'

        store.download_directory('dira/dirb', 'local/directory')

        mock_rmtree.assert_called_with('local/directory')
        mock_makedirs.assert_has_calls([
            call('local/directory'),
            call('local/directory', exist_ok=True),
            call('local/directory', exist_ok=True),
            call('local/directory/dire', exist_ok=True),
            call('local/directory/dirf', exist_ok=True),
        ])

        mock_open.assert_has_calls([
            call('local/directory/filea.json', 'wb'),
            call('local/directory/fileb.json', 'wb'),
            call('local/directory/dirf/somefile.json', 'wb'),
        ], any_order=True)

        mock_open().__enter__().write.assert_has_calls([
            call('downloaded(dira/dirb/filea.json)'),
            call('downloaded(dira/dirb/fileb.json)'),
            call('downloaded(dira/dirb/dirf/somefile.json)'),
        ], any_order=True)
Beispiel #2
0
 def test_get_object(self, mock_get_object):
     store = Objectstore()
     self.assertEqual(mock_get_object(), store._get_object('some item'))
     mock_get_object.assert_called_with(store.connection, 'some item', 'CONTAINER_BASE')