[lxc-devel] [pylxd/master] Add FilesManager.delete and corresponding test

duk3luk3 on Github lxc-bot at linuxcontainers.org
Wed Jan 3 08:18:05 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 312 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180103/ee487472/attachment.bin>
-------------- next part --------------
From ae4af7e01d609163afa263201ec99431fb10b821 Mon Sep 17 00:00:00 2001
From: Lukas Erlacher <erlacher at in.tum.de>
Date: Wed, 3 Jan 2018 19:16:36 +1100
Subject: [PATCH] Add FilesManager.delete and corresponding test

Fixes #261
---
 pylxd/models/container.py            |  6 ++++++
 pylxd/tests/models/test_container.py | 10 ++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/pylxd/models/container.py b/pylxd/models/container.py
index 84a0b19..528188f 100644
--- a/pylxd/models/container.py
+++ b/pylxd/models/container.py
@@ -84,6 +84,12 @@ def put(self, filepath, data):
                 params={'path': filepath}, data=data)
             return response.status_code == 200
 
+        def delete(self, filepath):
+            response = self._client.api.containers[
+                self._container.name].files.delete(
+                params={'path': filepath})
+            return response.status_code == 200
+
         def get(self, filepath):
             response = self._client.api.containers[
                 self._container.name].files.get(
diff --git a/pylxd/tests/models/test_container.py b/pylxd/tests/models/test_container.py
index 4fd15ac..042ed0a 100644
--- a/pylxd/tests/models/test_container.py
+++ b/pylxd/tests/models/test_container.py
@@ -431,13 +431,15 @@ def setUp(self):
         super(TestFiles, self).setUp()
         self.container = models.Container.get(self.client, 'an-container')
 
-    def test_put(self):
-        """A file is put on the container."""
+    def test_put_delete(self):
+        """A file is put on the container and then deleted"""
         data = 'The quick brown fox'
 
-        self.container.files.put('/tmp/putted', data)
+        res = self.container.files.put('/tmp/putted', data)
+        self.assertEqual(True, res, msg='Failed to put file, result: {}'.format(res))
 
-        # TODO: Add an assertion here
+        res = self.container.files.delete('/tmp/putted')
+        self.assertEqual(True, res, msg='Failed to delete file, result: {}'.format(res))
 
     def test_get(self):
         """A file is retrieved from the container."""


More information about the lxc-devel mailing list