mirielka's pull request #42: "Tests: Avoid skipping tests due to missing files" 
was synchronize

See the full pull-request at https://github.com/freeipa/freeipa/pull/42
... or pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/42/head:pr42
git checkout pr42
From afadf30be59933daab429231f51e87bf57559038 Mon Sep 17 00:00:00 2001
From: Lenka Doudova <ldoud...@redhat.com>
Date: Thu, 1 Sep 2016 09:46:17 +0200
Subject: [PATCH] Tests: Avoid skipping tests due to missing files

When running test_install/test_updates and test_pkcs10/test_pkcs10 as
outoftree, these are skipped with reason 'Unable to find test update files'.
For outoftree tests wrong paths are checked for these files.
Changing file localization to provide proper test setup.

https://fedorahosted.org/freeipa/ticket/6284
---
 ipatests/test_install/test_updates.py | 41 +++++++++++++++++++++--------------
 ipatests/test_pkcs10/test_pkcs10.py   | 11 +++++-----
 2 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/ipatests/test_install/test_updates.py b/ipatests/test_install/test_updates.py
index b41a7c5..3fa2cd7 100644
--- a/ipatests/test_install/test_updates.py
+++ b/ipatests/test_install/test_updates.py
@@ -65,11 +65,9 @@ def setUp(self):
         self.updater = LDAPUpdate(dm_password=self.dm_password, sub_dict={})
         self.ld = ipaldap.IPAdmin(fqdn)
         self.ld.do_simple_bind(bindpw=self.dm_password)
-        if ipautil.file_exists("0_reset.update"):
-            self.testdir="./"
-        elif ipautil.file_exists("ipatests/test_install/0_reset.update"):
-            self.testdir= "./ipatests/test_install/"
-        else:
+        self.testdir = os.path.abspath(os.path.dirname(__file__))
+        if not ipautil.file_exists(os.path.join(self.testdir,
+                                                "0_reset.update")):
             raise nose.SkipTest("Unable to find test update files")
 
         self.container_dn = DN(self.updater._template_str('cn=test, cn=accounts, $SUFFIX'))
@@ -84,7 +82,8 @@ def test_0_reset(self):
         Reset the updater test data to a known initial state (test_0_reset)
         """
         try:
-            modified = self.updater.update([self.testdir + "0_reset.update"])
+            modified = self.updater.update([os.path.join(self.testdir,
+                                                         "0_reset.update")])
         except errors.NotFound:
             # Just means the entry doesn't exist yet
             modified = True
@@ -103,7 +102,8 @@ def test_1_add(self):
         """
         Test the updater with an add directive (test_1_add)
         """
-        modified = self.updater.update([self.testdir + "1_add.update"])
+        modified = self.updater.update([os.path.join(self.testdir,
+                                                     "1_add.update")])
 
         self.assertTrue(modified)
 
@@ -137,7 +137,8 @@ def test_2_update(self):
         """
         Test the updater when adding an attribute to an existing entry (test_2_update)
         """
-        modified = self.updater.update([self.testdir + "2_update.update"])
+        modified = self.updater.update([os.path.join(self.testdir,
+                                                     "2_update.update")])
         self.assertTrue(modified)
 
         entries = self.ld.get_entries(
@@ -150,7 +151,8 @@ def test_3_update(self):
         """
         Test the updater forcing an attribute to a given value (test_3_update)
         """
-        modified = self.updater.update([self.testdir + "3_update.update"])
+        modified = self.updater.update([os.path.join(self.testdir,
+                                                     "3_update.update")])
         self.assertTrue(modified)
 
         entries = self.ld.get_entries(
@@ -163,7 +165,8 @@ def test_4_update(self):
         """
         Test the updater adding a new value to a single-valued attribute (test_4_update)
         """
-        modified = self.updater.update([self.testdir + "4_update.update"])
+        modified = self.updater.update([os.path.join(self.testdir,
+                                                     "4_update.update")])
         self.assertTrue(modified)
 
         entries = self.ld.get_entries(
@@ -176,7 +179,8 @@ def test_5_update(self):
         """
         Test the updater adding a new value to a multi-valued attribute (test_5_update)
         """
-        modified = self.updater.update([self.testdir + "5_update.update"])
+        modified = self.updater.update([os.path.join(self.testdir,
+                                                     "5_update.update")])
         self.assertTrue(modified)
 
         entries = self.ld.get_entries(
@@ -189,7 +193,8 @@ def test_6_update(self):
         """
         Test the updater removing a value from a multi-valued attribute (test_6_update)
         """
-        modified = self.updater.update([self.testdir + "6_update.update"])
+        modified = self.updater.update([os.path.join(self.testdir,
+                                                     "6_update.update")])
         self.assertTrue(modified)
 
         entries = self.ld.get_entries(
@@ -202,7 +207,8 @@ def test_6_update_1(self):
         """
         Test the updater removing a non-existent value from a multi-valued attribute (test_6_update_1)
         """
-        modified = self.updater.update([self.testdir + "6_update.update"])
+        modified = self.updater.update([os.path.join(self.testdir,
+                                                     "6_update.update")])
         self.assertFalse(modified)
 
         entries = self.ld.get_entries(
@@ -216,7 +222,8 @@ def test_7_cleanup(self):
         Reset the test data to a known initial state (test_7_cleanup)
         """
         try:
-            modified = self.updater.update([self.testdir + "0_reset.update"])
+            modified = self.updater.update([os.path.join(self.testdir,
+                                                         "0_reset.update")])
         except errors.NotFound:
             # Just means the entry doesn't exist yet
             modified = True
@@ -236,14 +243,16 @@ def test_8_badsyntax(self):
         Test the updater with an unknown keyword (test_8_badsyntax)
         """
         with self.assertRaises(BadSyntax):
-            modified = self.updater.update([self.testdir + "8_badsyntax.update"])
+            modified = self.updater.update(
+                [os.path.join(self.testdir, "8_badsyntax.update")])
 
     def test_9_badsyntax(self):
         """
         Test the updater with an incomplete line (test_9_badsyntax)
         """
         with self.assertRaises(BadSyntax):
-            modified = self.updater.update([self.testdir + "9_badsyntax.update"])
+            modified = self.updater.update(
+                [os.path.join(self.testdir, "9_badsyntax.update")])
 
     def test_from_dict(self):
         """
diff --git a/ipatests/test_pkcs10/test_pkcs10.py b/ipatests/test_pkcs10/test_pkcs10.py
index 86de3c6..4c5e09d 100644
--- a/ipatests/test_pkcs10/test_pkcs10.py
+++ b/ipatests/test_pkcs10/test_pkcs10.py
@@ -31,6 +31,7 @@
 import nss.nss as nss
 from nss.error import NSPRError
 import pytest
+import os
 
 
 @pytest.mark.tier0
@@ -41,15 +42,13 @@ class test_update(object):
 
     def setup(self):
         nss.nss_init_nodb()
-        if ipautil.file_exists("test0.csr"):
-            self.testdir="./"
-        elif ipautil.file_exists("ipatests/test_pkcs10/test0.csr"):
-            self.testdir= "./ipatests/test_pkcs10/"
-        else:
+        self.testdir = os.path.abspath(os.path.dirname(__file__))
+        if not ipautil.file_exists(os.path.join(self.testdir,
+                                                "test0.csr")):
             raise nose.SkipTest("Unable to find test update files")
 
     def read_file(self, filename):
-        fp = open(self.testdir + filename, "r")
+        fp = open(os.path.join(self.testdir, filename), "r")
         data = fp.read()
         fp.close()
         return data
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to