Exemplo n.º 1
0
    def test_reader(self):
        client_collection = make_client_collection()
        df = DiskFile(client_collection, 'a', 'c', 'o', use_splice=False,
                      logger=logging.root)

        reader = df.reader()
        self.assertTrue(isinstance(reader, DiskFileReader))
Exemplo n.º 2
0
    def test_create(self, mock_http):
        client_collection = make_client_collection()
        df = DiskFile(client_collection, 'a', 'c', 'o', use_splice=False,
                      logger=logging.root)

        with df.create() as writer:
            self.assertTrue(isinstance(writer, DiskFileWriter))
Exemplo n.º 3
0
    def test_read_metadata(self, mock_get_meta):
        client_collection = make_client_collection()
        df = DiskFile(client_collection, 'a', 'c', 'o', use_splice=False,
                      logger=logging.root)

        metadata = df.read_metadata()

        self.assertEqual({'name': 'o'}, metadata)
Exemplo n.º 4
0
    def test_open(self, mock_get_meta):
        client_collection = make_client_collection()
        df = DiskFile(client_collection, 'a', 'c', 'o', use_splice=False,
                      logger=logging.root)

        df.open()

        self.assertEqual({'name': 'o', 'mf': {}, 'df': {'name': 'o'}}, df._metadata)
Exemplo n.º 5
0
    def test_delete(self, mock_del_object):
        acc, cont, obj = 'a', 'c', 'o'

        client_collection = make_client_collection()
        df = DiskFile(client_collection, acc, cont, obj, use_splice=False,
                      logger=logging.root)

        df.delete("ignored")

        mock_del_object.assert_called_once_with(self.hash_str([acc, cont, obj]))
Exemplo n.º 6
0
    def test_timestamp(self, mock_timestamp):
        client_collection = make_client_collection()
        df = DiskFile(client_collection, 'a', 'c', 'o', use_splice=False,
                      logger=logging.root)

        df._metadata = mock.Mock()
        df.timestamp

        df._metadata.get.assert_called_once_with('X-Timestamp')
        mock_timestamp.assert_called_once_with(df._metadata.get())
Exemplo n.º 7
0
    def test_create(self, mock_http):
        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      'a',
                      'c',
                      'o',
                      use_splice=False,
                      logger=logging.root)

        with df.create() as writer:
            self.assertTrue(isinstance(writer, DiskFileWriter))
Exemplo n.º 8
0
    def test_reader(self):
        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      'a',
                      'c',
                      'o',
                      use_splice=False,
                      logger=logging.root)

        reader = df.reader()
        self.assertTrue(isinstance(reader, DiskFileReader))
Exemplo n.º 9
0
    def test_write_metadata(self, mock_put_meta):
        acc, cont, obj = 'a', 'c', 'o'

        client_collection = make_client_collection()
        df = DiskFile(client_collection, acc, cont, obj, use_splice=False,
                      logger=logging.root)

        df.write_metadata({'k': 'v'})

        mock_put_meta.assert_called_once_with(self.hash_str([acc, cont, obj]),
                                              {'k': 'v'})
Exemplo n.º 10
0
    def test_read_metadata(self, mock_get_meta):
        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      'a',
                      'c',
                      'o',
                      use_splice=False,
                      logger=logging.root)

        metadata = df.read_metadata()

        self.assertEqual({'name': 'o'}, metadata)
Exemplo n.º 11
0
    def test_write_metadata(self, mock_put_meta):
        acc, cont, obj = 'a', 'c', 'o'

        client_collection = make_client_collection()
        df = DiskFile(client_collection, acc, cont, obj, use_splice=False,
                      logger=logging.root)

        df.write_metadata({'k': 'v'})

        mock_put_meta.assert_called_once_with(self.hash_str([acc, cont, obj]), {
            'df': {'name': 'ae541120074a053234ef14e1b050ee3a7433099c'},
            'k': 'v',
            'mf': {'k': 'v'}
        })
Exemplo n.º 12
0
    def test_timestamp(self, mock_timestamp):
        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      'a',
                      'c',
                      'o',
                      use_splice=False,
                      logger=logging.root)

        df._metadata = mock.Mock()
        df.timestamp

        df._metadata.get.assert_called_once_with('X-Timestamp')
        mock_timestamp.assert_called_once_with(df._metadata.get())
Exemplo n.º 13
0
    def test_delete(self, mock_del_object):
        acc, cont, obj = 'a', 'c', 'o'

        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      acc,
                      cont,
                      obj,
                      use_splice=False,
                      logger=logging.root)

        df.delete("ignored")

        mock_del_object.assert_called_once_with(self.hash_str([acc, cont,
                                                               obj]))
Exemplo n.º 14
0
    def test_write_metadata(self, mock_put_meta):
        acc, cont, obj = 'a', 'c', 'o'

        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      acc,
                      cont,
                      obj,
                      use_splice=False,
                      logger=logging.root)

        df.write_metadata({'k': 'v'})

        mock_put_meta.assert_called_once_with(self.hash_str([acc, cont, obj]),
                                              {'k': 'v'})
Exemplo n.º 15
0
    def test_get_metadata_when_diskfile_not_open(self):
        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      'a',
                      'c',
                      'o',
                      use_splice=False,
                      logger=logging.root)

        self.assertRaises(swift.common.exceptions.DiskFileNotOpen,
                          df.get_metadata)
Exemplo n.º 16
0
    def test_init_quotes_object_path(self):
        acc, cont, obj = 'a', '@/', '/ob/j'

        sproxyd_client = SproxydClient(['http://host:81/path/'],
                                       logger=mock.Mock())
        df = DiskFile(sproxyd_client,
                      acc,
                      cont,
                      obj,
                      use_splice=False,
                      logger=logging.root)
        self.assertEqual(self.hash_str([acc, cont, obj]), df._name)
Exemplo n.º 17
0
    def test_open_when_no_metadata(self, mock_get_meta):
        acc, cont, obj = 'a', 'c', 'o'

        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      acc,
                      cont,
                      obj,
                      use_splice=False,
                      logger=logging.root)

        self.assertRaises(swift.common.exceptions.DiskFileDeleted, df.open)
        mock_get_meta.assert_called_once_with(self.hash_str([acc, cont, obj]))
Exemplo n.º 18
0
    def test_open_expired_file(self, mock_get_meta):
        acc, cont, obj = 'a', 'c', 'o'
        mock_get_meta.return_value = {'X-Delete-At': time.time() - 10}

        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      acc,
                      cont,
                      obj,
                      use_splice=False,
                      logger=logging.root)
        self.assertRaises(swift.common.exceptions.DiskFileExpired, df.open)
        mock_get_meta.assert_called_once_with(self.hash_str([acc, cont, obj]))
Exemplo n.º 19
0
    def test_timestamps_when_no_metadata(self):
        client_collection = make_client_collection()
        df = DiskFile(client_collection,
                      'a',
                      'c',
                      'o',
                      use_splice=False,
                      logger=logging.root)

        # assertRaises expects a `callable`, but `timestamp` is a property
        # We could use the `with self.assertRaises(exc):` form but that's
        # Python 2.7+ only
        self.assertRaises(swift.common.exceptions.DiskFileNotOpen,
                          lambda: df.timestamp)
        self.assertRaises(swift.common.exceptions.DiskFileNotOpen,
                          lambda: df.data_timestamp)