diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 459: Fix unit tests so they don't execute commands using sudo.

Message ID 20111115080912.14609.70826.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Mattias Backman Nov. 15, 2011, 8:09 a.m. UTC
Merge authors:
  Mattias Backman (mabac)
Related merge proposals:
  https://code.launchpad.net/~mabac/linaro-image-tools/bug-888694-fix-sudo-tests/+merge/82155
  proposed by: Mattias Backman (mabac)
  review: Approve - Guilherme Salgado (salgado)
------------------------------------------------------------
revno: 459 [merge]
committer: Mattias Backman <mattias.backman@linaro.org>
branch nick: linaro-image-tools
timestamp: Tue 2011-11-15 09:07:46 +0100
message:
  Fix unit tests so they don't execute commands using sudo.
modified:
  linaro_image_tools/media_create/tests/test_media_create.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
--- linaro_image_tools/media_create/tests/test_media_create.py	2011-11-14 15:14:29 +0000
+++ linaro_image_tools/media_create/tests/test_media_create.py	2011-11-15 08:07:46 +0000
@@ -2402,7 +2402,17 @@ 
         self.assertFalse(
             has_space_left_for_swap('/', swap_size_in_megs))
 
+    def mock_write_data_to_protected_file(self, path, data):
+        # Duplicate of write_data_to_protected_file() but does not sudo.
+        _, tmpfile = tempfile.mkstemp()
+        with open(tmpfile, 'w') as fd:
+            fd.write(data)
+            cmd_runner.run(['mv', '-f', tmpfile, path], as_root=False).wait()
+
     def test_update_interfaces_no_interfaces_no_update(self):
+        self.useFixture(MockSomethingFixture(
+                rootfs, 'write_data_to_protected_file',
+                self.mock_write_data_to_protected_file))
         tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
         os.makedirs(os.path.join(tempdir, 'etc', 'network'))
         if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces')
@@ -2413,6 +2423,9 @@ 
         self.assertFalse(os.path.exists(if_path))
 
     def test_update_interfaces_creates_entry(self):
+        self.useFixture(MockSomethingFixture(
+                rootfs, 'write_data_to_protected_file',
+                self.mock_write_data_to_protected_file))
         tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
         os.makedirs(os.path.join(tempdir, 'etc', 'network'))
         if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces')
@@ -2425,6 +2438,9 @@ 
         self.assertEqual(expected, open(if_path).read())
 
     def test_update_interfaces_creates_entries(self):
+        self.useFixture(MockSomethingFixture(
+                rootfs, 'write_data_to_protected_file',
+                self.mock_write_data_to_protected_file))
         tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
         os.makedirs(os.path.join(tempdir, 'etc', 'network'))
         if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces')
@@ -2441,6 +2457,9 @@ 
         self.assertIn(expected % {'if': 'wlan0'}, open(if_path).read())
 
     def test_update_interfaces_leaves_original(self):
+        self.useFixture(MockSomethingFixture(
+                rootfs, 'write_data_to_protected_file',
+                self.mock_write_data_to_protected_file))
         tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
         os.makedirs(os.path.join(tempdir, 'etc', 'network'))
         if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces')