Beispiel #1
0
    def test_put_json_object(self):
        store = Objectstore()
        store._put_object = MagicMock()
        store.put_json_object('filename.json', {
            'a': 'b',
            'c': {
                'd': 'e',
                'f': 4,
                'g': {
                    'h': 4
                }
            }
        })

        # Should be nicely formatted
        store._put_object.assert_called_with(
            'filename.json', """{
    "a": "b",
    "c": {
        "d": "e",
        "f": 4,
        "g": {
            "h": 4
        }
    }
}""", 'application/json')
Beispiel #2
0
 def test_clear_directory(self):
     store = Objectstore()
     store._get_objects_list = MagicMock(return_value=[
         {
             'name': 'a/b/c'
         },
         {
             'name': 'a/b/d'
         },
         {
             'name': 'a/b'
         },
         {
             'name': 'a'
         },
         {
             'name': 'a/e/f'
         },
     ])
     store._delete_object = MagicMock()
     store.clear_directory('a/b')
     store._delete_object.assert_has_calls([
         call({'name': 'a/b/c'}),
         call({'name': 'a/b/d'}),
         call({'name': 'a/b'}),
     ])
Beispiel #3
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 #4
0
 def test_put_object(self, mock_put_object):
     store = Objectstore()
     store._put_object('some name', 'contents', 'content/type')
     mock_put_object.assert_called_with(store.connection, 'CONTAINER_BASE', 'some name', 'contents', 'content/type')
Beispiel #5
0
 def test_delete_object(self, mock_delete_object):
     store = Objectstore()
     store._delete_object('some item')
     mock_delete_object.assert_called_with(store.connection, 'CONTAINER_BASE', 'some item')
Beispiel #6
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')
Beispiel #7
0
 def test_get_objects_list(self, mock_get_list):
     store = Objectstore()
     self.assertEqual(mock_get_list(), store._get_objects_list())
     mock_get_list.assert_called_with(store.connection, "CONTAINER_BASE")
Beispiel #8
0
 def test_init(self, mock_ds_factory, mock_get_ds):
     store = Objectstore()
     self.assertEqual(store.connection, mock_ds_factory.get_datastore().connection)
     mock_ds_factory.get_datastore().connect.assert_called_once()