|
|
3f51ca |
From 8ffdc78b211c025c19636a5f5dcd12d12191aee4 Mon Sep 17 00:00:00 2001
|
|
|
3f51ca |
From: Fraser Tweedale <ftweedal@redhat.com>
|
|
|
3f51ca |
Date: Tue, 5 Dec 2017 15:00:18 +1100
|
|
|
3f51ca |
Subject: [PATCH] Add tests for installutils.set_directive
|
|
|
3f51ca |
|
|
|
3f51ca |
Part of: https://pagure.io/freeipa/issue/7288
|
|
|
3f51ca |
|
|
|
3f51ca |
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
|
|
|
3f51ca |
---
|
|
|
3f51ca |
.../test_install/test_installutils.py | 57 ++++++++++++++++++++++
|
|
|
3f51ca |
1 file changed, 57 insertions(+)
|
|
|
3f51ca |
create mode 100644 ipatests/test_ipaserver/test_install/test_installutils.py
|
|
|
3f51ca |
|
|
|
3f51ca |
diff --git a/ipatests/test_ipaserver/test_install/test_installutils.py b/ipatests/test_ipaserver/test_install/test_installutils.py
|
|
|
3f51ca |
new file mode 100644
|
|
|
3f51ca |
index 0000000000000000000000000000000000000000..cc8fd3cf3f82c2d9af48287f506a566ffbfc39f6
|
|
|
3f51ca |
--- /dev/null
|
|
|
3f51ca |
+++ b/ipatests/test_ipaserver/test_install/test_installutils.py
|
|
|
3f51ca |
@@ -0,0 +1,57 @@
|
|
|
3f51ca |
+#
|
|
|
3f51ca |
+# Copyright (C) 2017 FreeIPA Contributors. See COPYING for license
|
|
|
3f51ca |
+#
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+import os
|
|
|
3f51ca |
+import tempfile
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+from ipaserver.install import installutils
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+EXAMPLE_CONFIG = [
|
|
|
3f51ca |
+ 'foo=1\n',
|
|
|
3f51ca |
+ 'foobar=2\n',
|
|
|
3f51ca |
+]
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+class test_set_directive_lines(object):
|
|
|
3f51ca |
+ def test_remove_directive(self):
|
|
|
3f51ca |
+ lines = installutils.set_directive_lines(
|
|
|
3f51ca |
+ False, '=', 'foo', None, EXAMPLE_CONFIG)
|
|
|
3f51ca |
+ assert list(lines) == ['foobar=2\n']
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+ def test_add_directive(self):
|
|
|
3f51ca |
+ lines = installutils.set_directive_lines(
|
|
|
3f51ca |
+ False, '=', 'baz', '4', EXAMPLE_CONFIG)
|
|
|
3f51ca |
+ assert list(lines) == ['foo=1\n', 'foobar=2\n', 'baz=4\n']
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+ def test_set_directive_does_not_clobber_suffix_key(self):
|
|
|
3f51ca |
+ lines = installutils.set_directive_lines(
|
|
|
3f51ca |
+ False, '=', 'foo', '3', EXAMPLE_CONFIG)
|
|
|
3f51ca |
+ assert list(lines) == ['foo=3\n', 'foobar=2\n']
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+class test_set_directive(object):
|
|
|
3f51ca |
+ def test_set_directive(self):
|
|
|
3f51ca |
+ """Check that set_directive writes the new data and preserves mode."""
|
|
|
3f51ca |
+ fd, filename = tempfile.mkstemp()
|
|
|
3f51ca |
+ try:
|
|
|
3f51ca |
+ os.close(fd)
|
|
|
3f51ca |
+ stat_pre = os.stat(filename)
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+ with open(filename, 'w') as f:
|
|
|
3f51ca |
+ for line in EXAMPLE_CONFIG:
|
|
|
3f51ca |
+ f.write(line)
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+ installutils.set_directive(filename, 'foo', '3', False, '=')
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+ stat_post = os.stat(filename)
|
|
|
3f51ca |
+ with open(filename, 'r') as f:
|
|
|
3f51ca |
+ lines = list(f)
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+ assert lines == ['foo=3\n', 'foobar=2\n']
|
|
|
3f51ca |
+ assert stat_pre.st_mode == stat_post.st_mode
|
|
|
3f51ca |
+ assert stat_pre.st_uid == stat_post.st_uid
|
|
|
3f51ca |
+ assert stat_pre.st_gid == stat_post.st_gid
|
|
|
3f51ca |
+
|
|
|
3f51ca |
+ finally:
|
|
|
3f51ca |
+ os.remove(filename)
|
|
|
3f51ca |
--
|
|
|
3f51ca |
2.13.6
|
|
|
3f51ca |
|