Example #1
0
    def test_erase_stored_raise(self):
        """
        Test that trying to erase the repository content of a stored
        Data node without the force flag raises.
        """
        node = Data()
        node.put_object_from_tree(self.tempdir, '')
        node.store()

        self.assertEqual(sorted(node.list_object_names()), ['c.txt', 'subdir'])
        self.assertEqual(sorted(node.list_object_names('subdir')),
                         ['a.txt', 'b.txt', 'nested'])

        self.assertRaises(ModificationNotAllowed, node._repository.erase)  # pylint: disable=protected-access
Example #2
0
    def test_erase_stored_force(self):
        """
        Test that _repository.erase removes the content of an stored
        Data node when passing force=True.
        """
        node = Data()
        node.put_object_from_tree(self.tempdir, '')
        node.store()

        self.assertEqual(sorted(node.list_object_names()), ['c.txt', 'subdir'])
        self.assertEqual(sorted(node.list_object_names('subdir')),
                         ['a.txt', 'b.txt', 'nested'])

        node._repository.erase(force=True)  # pylint: disable=protected-access
        self.assertEqual(node.list_object_names(), [])
Example #3
0
def test_store_from_cache():
    """Regression test for storing a Node with (nested) repository content with caching."""
    data = Data()
    with tempfile.TemporaryDirectory() as tmpdir:
        dir_path = os.path.join(tmpdir, 'directory')
        os.makedirs(dir_path)
        with open(os.path.join(dir_path, 'file'), 'w') as file:
            file.write('content')
        data.put_object_from_tree(tmpdir)

    data.store()

    clone = data.clone()
    clone._store_from_cache(data, with_transaction=True)  # pylint: disable=protected-access

    assert clone.is_stored
    assert clone.get_cache_source() == data.uuid
    assert data.get_hash() == clone.get_hash()